xxxxxxxxxx
//generative art class 2: sine functions with p5.js
//the formula for circular moviment is
//position + radius*sin(angle)
//sine functions returns 1 to -1 when you input an angle
//use angle in radians: TWO_PI/360 for example
let circleR;//circle Radius
function setup() {
createCanvas(windowWidth,windowHeight);//size of the canvas two numbers, width and height
}
function draw() {
//color of the background fading fx with opacity
fill(255,7);// 2 numbers 255 is white and opacity 7 (very low)
rect(0,0,width,height);
//colored pulse circle with sine(color and diameter)
colorMode(HSB);
noFill();//no fill just stroke
stroke(125+sin(millis()*0.008)*125,255,255);
circle(width/2, height/2,
250 + sin(millis()*0.008)*250);
//use millis() to increment the angle
//millis() function returns the time passed since the sketch is runing in milliseconds
//0 to 1000 in one second!
//so we multiply for a litle number like 0.008 to slow it down
//bigger circle just the black stroke, no fill
stroke(0);//stroke 0 is black
circle(width/2, height/2, 300);
//blue circle just sine and cosine
circleR2 = 150;//this is to use the circular movement formula
noStroke();
colorMode(RGB);
fill(0,0,255,125); //put fill again to the circles
//this is the way to aply the formula
//the formula is
//position+radius*sin(angle); just increment the angle with millis()
circle(width/2 + circleR2*cos(TWO_PI/360+millis()*0.008),
height/2 + circleR2*sin(TWO_PI/360+millis()*0.008),
40);
//green circle with noise aplied to the radius size position (circular movement formula)
circleR = 15+noise(millis()*0.00008) *295;
fill(0,255,0,95);
circle(width/2+circleR*cos(TWO_PI/360+millis()*0.008),height/2+circleR*sin(TWO_PI/360+millis()*0.008),40);
//red circle with random angle
let randAngle=random(TWO_PI);//random number from 0 to TWO_PI
fill(255,0,0,155);
let angle=PI;
circle(width/2+150*cos(randAngle),
height/2+150*sin(randAngle),40);
}