Steven Fei dynamic Drawing
function setup() {
createCanvas(600, 480);
}
var size = 8; //hexagon size that can change according to the mouse movement
let color = 0; //hexagon color that can change according to the mouse movement
var colorDir = 2; //the degree of change for the color change
let angle = 0; //the initial rotation angle for the hexagon
var dir = 1; // the growing direction of the hexagon, either positive or negative
var speed = 2; //the growing speed of the hexagon
function mouseMoved(){
color = color +colorDir;
if (color<0){
colorDir = 2;
} else if (color>255){
colorDir = -2;
}
angle +=0.6;
size += dir * speed;
if(size<0){
dir = 1;
size = 0;
}else if (size>60){
dir = -1;
size = 60;
}
}
var diffx = 0;
var diffy = 0;
var circlex = 300;
var circley = 300;
function draw() {
background(0);
// locate the mouse position
diffx = mouseX - circlex;
diffy = mouseY - circley;
circlex = circlex + 0.1*diffx;
circley = circley + 0.1*diffy;
fill("white");
circle(circlex,circley,20);
fill(color,37,213);
var x = max(min(mouseX,300),5); // decide the starting point of the hexagon, when the mouse is far on the left the canvas, the hexagons may shrink together and when the mouse is far on the right of the canvas, the hexagons may move away from each other
translate(300,240); //move to the center of the canvas
// draw the basic shape for 1st Hexagon
beginShape();
rotate(radians(angle));
vertex(x/2,0);
vertex(x/2+size*cos(radians(60)),0-size*sin(radians(60)));
vertex(x/2+size+size*cos(radians(60)),0-size*sin(radians(60)));
vertex(x/2+size+2*size*cos(radians(60)),0);
vertex(x/2+size+size*cos(radians(60)),size*sin(radians(60)));
vertex(x/2+size*cos(radians(60)),size*sin(radians(60)));
endShape();
// draw the basic shape for 2nd Hexagon
rotate(radians(60));
beginShape();
vertex(x/2+1.3,0);
vertex(x/2+1.3+1.3*size*cos(radians(60)),0-1.3*size*sin(radians(60)));
vertex(x/2+1.3+1.3*size+1.3*size*cos(radians(60)),0-1.3*size*sin(radians(60)));
vertex(x/2+1.3+1.3*size+2*1.3*size*cos(radians(60)),0);
vertex(x/2+1.3+1.3*size+1.3*size*cos(radians(60)),1.3*size*sin(radians(60)));
vertex(x/2+1.3+1.3*size*cos(radians(60)),1.3*size*sin(radians(60)));
endShape();
// draw the basic shape for 3rd Hexagon
rotate(radians(60));
beginShape();
vertex(x/2+1.5,0);
vertex(x/2+1.5+1.5*size*cos(radians(60)),0-1.5*size*sin(radians(60)));
vertex(x/2+1.5+1.5*size+1.5*size*cos(radians(60)),0-1.5*size*sin(radians(60)));
vertex(x/2+1.5+1.5*size+2*1.5*size*cos(radians(60)),0);
vertex(x/2+1.5+1.5*size+1.5*size*cos(radians(60)),1.5*size*sin(radians(60)));
vertex(x/2+1.5+1.5*size*cos(radians(60)),1.5*size*sin(radians(60)));
endShape();
// draw the basic shape for 4th Hexagon
rotate(radians(60));
beginShape();
vertex(x/2+1.7,0);
vertex(x/2+1.7+1.7*size*cos(radians(60)),0-1.7*size*sin(radians(60)));
vertex(x/2+1.7+1.7*size+1.7*size*cos(radians(60)),0-1.7*size*sin(radians(60)));
vertex(x/2+1.7+1.7*size+2*1.7*size*cos(radians(60)),0);
vertex(x/2+1.7+1.7*size+1.7*size*cos(radians(60)),1.7*size*sin(radians(60)));
vertex(x/2+1.7+1.7*size*cos(radians(60)),1.7*size*sin(radians(60)));
endShape();
// draw the basic shape for 5th Hexagon
rotate(radians(60));
beginShape();
vertex(x/2+1.9,0);
vertex(x/2+1.9+1.9*size*cos(radians(60)),0-1.9*size*sin(radians(60)));
vertex(x/2+1.9+1.9*size+1.9*size*cos(radians(60)),0-1.9*size*sin(radians(60)));
vertex(x/2+1.9+1.9*size+2*1.9*size*cos(radians(60)),0);
vertex(x/2+1.9+1.9*size+1.9*size*cos(radians(60)),1.9*size*sin(radians(60)));
vertex(x/2+1.9+1.9*size*cos(radians(60)),1.9*size*sin(radians(60)));
endShape();
// draw the basic shape for 6th Hexagon
rotate(radians(60));
beginShape();
vertex(x/2+2.1,0);
vertex(x/2+2.1+2.1*size*cos(radians(60)),0-2.1*size*sin(radians(60)));
vertex(x/2+2.1+2.1*size+1.9*size*cos(radians(60)),0-2.1*size*sin(radians(60)));
vertex(x/2+2.1+2.1*size+2*2.1*size*cos(radians(60)),0);
vertex(x/2+2.1+2.1*size+1.9*size*cos(radians(60)),2.1*size*sin(radians(60)));
vertex(x/2+2.1+2.1*size*cos(radians(60)),2.1*size*sin(radians(60)));
endShape();
}