xxxxxxxxxx
var thesize = 1; // GLOBAL VARIABLE
var mouseangle = 0; // global variable
var distance = 50; // distance of the circles
var angle = 0; // angle of the circles
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
}
function draw() {
colorMode(RGB);
//background(255, 10);
rect(0, 0, width, height); // psychedelic background
var speed = dist(mouseX, mouseY, pmouseX, pmouseY); // hypotenuse
if(speed>0) mouseangle = atan2((pmouseY-mouseY),(pmouseX-mouseX));
// console.log(speed);
// pmouseX and pmouseY are the previous mouseX and mouseY
strokeWeight(speed);
noFill();
stroke(0, 20);
line(pmouseX, pmouseY, mouseX, mouseY);
colorMode(HSB);
noStroke();
var h = map(mouseangle, -PI, PI, 0, 360); // map(input, minin, maxin, minout, maxout)
var s = 100;
var b = 100;
var d = speed+15;
var cx = distance * cos(angle);
var cy = distance * sin(angle);
fill(h, s, b, 0.3); // HSB is 0-360 for the H, 0-100 for the S & B, 0-1 for the alpha
ellipse(mouseX+cx, mouseY+cy, d, d);
fill((h+120)%360, s, b, 0.3); // HSB is 0-360 for the H, 0-100 for the S & B, 0-1 for the alpha
ellipse(mouseX, mouseY, d, d);
fill((h+240)%360, s, b, 0.3); // HSB is 0-360 for the H, 0-100 for the S & B, 0-1 for the alpha
ellipse(mouseX-cx, mouseY-cy, d, d);
angle = (angle+speed/10)%TWO_PI; // % is the remainder of a division (modulo operator)
}
function keyTyped() {
if(key=='c') {
background(255);
thesize = 1;
}
}