My Project
var col = 0;
var col2 = 0;var angl = 0;var shiftingVal = 100;var shiftingValChange = 1;
function setup() {
createCanvas(480, 480);
background(220);
text("p5.js vers 0.9.0 test.", 10, 15);
}
function draw() {
background(220);
stroke(0);
line(0, 0, 120, 120);
line(0, 480, 120, 360);
line(480, 0, 360, 120);
line(480, 480, 360, 360);
line(0, 0, 480, 0);
line(0, 0, 0, 480);
line(480, 0, 480, 480);
line(0, 480, 480, 480);
line(120, 120, 120, 360);
line(120, 360, 360, 360);
line(360, 360, 360, 120);
line(360, 120, 120, 120);
strokeWeight(2);
fill(shiftingVal);
stroke(col2);
push();
translate(240, 240);
conicalSpiralTopViewRough();
pop();
noFill();
stroke(col);
for (var i = 120; i <= 360; i += 240){
for (var j = 120; j <= 360; j += 240){
push();
translate(j, i);
rotate(radians(angl));
scale(0.5);
conicalSpiralTopViewSmooth();
pop();
}
}
if (shiftingVal >= 255){
shiftingValChange = shiftingValChange * -1;
}
else if (shiftingVal < 100){
shiftingValChange = shiftingValChange * -1;
}
shiftingVal += 1*shiftingValChange;
angl += 0.1;
}
function conicalSpiralTopViewSmooth() {
var h = 1;
var a;
var r = 30;
var indepChangeX = map(mouseX, 0, 480, 500, 1000);
var indepChangeY = map(mouseY, 0, 480, 800, 1000);
a = indepChangeY;
beginShape();
for (var i = 0; i < indepChangeX; i++){
var z = map(i, 0, 400, 0, PI);
x = ((h - z) / h)*r*cos(radians(a*z));
y = ((h - z) / h)*r*sin(radians(a*z));
vertex(x, y);
}
endShape(CLOSE);
}
function conicalSpiralTopViewRough() {
var h = 0.5;
var a = 1000;
var r;
r = map(mouseY, 0, 480, 20, 10);
var edgeNum = map(mouseX, 0, 480, 60, 30);
beginShape();
for (var i = 0; i < edgeNum; i++){
var z = map(i, 0, 50, 0, TWO_PI);
x = ((h - z) / h)*r*cos(radians(a*z));
y = ((h - z) / h)*r*sin(radians(a*z));
vertex(x, y);
}
endShape();
}
function mousePressed() {
var randR = random(150);
var randG = random(150);
var randB = random(150);
col = color(randR, randG, randB);
col2 = color(randR + random(-50, 50), randG + random(-50, 50), randB + random(-50, 50));
}
I initially had no idea what to make in terms of curves. That was until I happened upon the Conical Spiral. It was supposed to be 3-D, but it ended up as a top down view of a spiral which I liked. Overall, I liked what I did with this Project.
As for how it works, clicking the mouse will change the colors of the middle “rough” Conical Spiral and the 4 “smooth” Conical Spirals. The colors of both types are similar but not the same, as seen with the use of random() in the code.
Along with that, moving the mouse right will increase the size of the “smooth” Spirals and reduce the size and complexity of the “rough” Spiral. Moving left does the opposite. Moving down increases the complexity of the “smooth” Spirals while also reducing the size of them and the “rough” Spiral.