xxxxxxxxxx
90
let y=0; //y-position of ellipse
let w=0; //width of ellipse
let h=0; //mouse y-distance from position of initial click
let x1=0; //x-position of mouse
let y1=0; //y-position of mouse
let hmx=0; //x-position of initial click
let hmy=0; //y-position of initial click
let toggle = 0; //click-hold toggle
function setup() {
//creating setup
createCanvas(600, 600);
noFill();
strokeWeight(3);
background(0);
}
function draw(){
//creating drawings
x1=mouseX; //defining x-position of initial click
y1=mouseY; //defining y-position of initial click
let r = map(mouseX, 0, width, 0, 450); //red value
let g = map(mouseY, 0, height, 450,0); //green value
let b = map(mouseX+mouseY, 0, width+height, 0, 450); //blue value
col= color(r,g,b); //colour of stroke
stroke(col); //defining stroke colour
if(mouseIsPressed){
//click-hold to draw
if(toggle==0){
//left-click
hmx=x1; //snapshot x-position of mouse
hmy=y1; //snapshot y-position of mouse
toggle = 1; //hold
}
h=y1-hmy; //defining mouse y-distance from position of initial click
if(h>0){
//down stoke weight
if(h>15){
//draw down range
h=15;
}
myBrush1(hmx,hmy,h); //drawing down stoke weight
}
if(h<0){
//up stroke weight
if(h<-15){
//draw up range
h=-15;
}
myBrush2(hmx,hmy,h); //drawing up stroke weight
}
}
else{
toggle=0; //let go of left-click
}
}
function myBrush1(homeX,homeY,tempH){
y=tempH/2;
w=tempH/2;
arc(homeX,homeY+y,150+w,150+tempH,0+tempH*0.1/2,PI/2);
//bottom right curve
arc(homeX,homeY+y,150+w,150+tempH,PI/2,PI-0.1-tempH*0.15/2);
//bottom left curve
arc(homeX,homeY,150,150,PI,0);
//top curve
}
function myBrush2(homeX,homeY,tempH){
y=tempH/2;
w=tempH/2;
arc(homeX,homeY+y,150-w,150-tempH,PI-tempH*0.1/2,0);
//top curve
arc(homeX,homeY,150,150,0,PI/2);
//bottom curve
}