-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomBrush.js
29 lines (25 loc) · 1.47 KB
/
customBrush.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function CustomBrush() {
//Seting name and icon for custom brush tool.
this.name = "Custom Brush";
this.icon = "assets/brush.jpg";
//Draw function which work all the time when mouse is pressed.
this.draw = function() {
if (mouseIsPressed) {
let brushDensity = 10; // Number of points in the brush.
let brushSpread = brushSize / 2; // Spread of the brush strokes.
//loop for multiple brush strokes.
for (let i = 0; i < brushDensity; i++) {
let offsetX = random(-brushSpread, brushSpread); //offsetX for random stroke displacement.
let offsetY = random(-brushSpread, brushSpread); //offsetY for random stroke displacement.
let alphaValue = random(50, 255); // Random opacity for each stroke.
//use of stroke color from colour pallette and applying random alpha value for transparency.
stroke(colourP.selectedColour);
strokeWeight(random(1, brushSize / 2)); // Varying stroke weight.
stroke(color(red(colourP.selectedColour),
green(colourP.selectedColour),
blue(colourP.selectedColour), alphaValue));
line(pmouseX + offsetX, pmouseY + offsetY, mouseX + offsetX, mouseY + offsetY); //Draw line from previous mouse posittion and offset it by random value.
}
}
};
}