//---- normal P5 code -------------------------------------------------------
//Pizza slices that follows the mouse pointer
var rows = 0,
cols = 0,
distance= 30;//Each pizza is spaced 30
var theta=0;
function setup() {
createCanvas(windowWidth/2, windowHeight /2);
rows =width/ distance;
cols = height/ distance;
noStroke();//no stroke
}
function draw() {
background(0);
beginShape();//Start drawing free-form shapes
for (var i = 0; i <= rows; i++) {
for (var j = 0; j <=cols; j++) {
var x = i * distance;//The horizontal coordinates of each pizza
var y = j * distance;//Vertical coordinates of each pizza
var dx = mouseX - x;
var dy = mouseY - y;
var r = atan2(dy, dx);//Calculate the slope, tangent
push();
translate(x , y );//Generate multiple semi-circular arcs (the shape of a pizza)
rotate(r+theta);//angle of rotation
push();
fill(255,200,100);
arc(0, 0, 35, 35, 0, 0.8);
pop();
push();
fill(250,100,0);
arc(0,0,25,25,0,0.8);
pop();
push();
fill(255);
arc(0,0,12,12,0,0.8);
pop();
pop();
}
}
theta+=0.02;
endShape(CLOSE);
}