xxxxxxxxxx
48
let coords = [];
let petals = 7;
function setup() {
createCanvas(400, 400);
slider = createSlider(0,12)
}
function draw() {
background(220);
petals = slider.value();
let pcoords = [];
let alph = 0.22*PI + 0.61*PI*((petals-1)/7);
let petalwidth = alph/petals;
//first do all the points in polar coordinates
for(let i=0;i<petals;i++){
let centerangle = (i+0.5) * petalwidth - alph*0.5;
pcoords.push([centerangle - petalwidth*0.5, 0.5])
pcoords.push([pcoords[pcoords.length-1][0]+0.025*PI, 0.75])
pcoords.push([pcoords[pcoords.length-1][0]+0.015*PI, 0.9])
pcoords.push([centerangle, 1.0])
pcoords.push([centerangle + petalwidth*0.5 - 0.040*PI, 0.9])
pcoords.push([pcoords[pcoords.length-1][0]+0.015*PI, 0.75])
pcoords.push([pcoords[pcoords.length-1][0]+0.025*PI, 0.5])
pcoords.push([0.0, 0.0])
}
//translate to cartesian (these are to be multiplied with the flowervector)
coords = [];
for(let i=0;i<pcoords.length;i++){
coords.push([cos(pcoords[i][0]) * pcoords[i][1],
sin(pcoords[i][0]) * pcoords[i][1]]);
}
beginShape();
for(let i=0; i<coords.length; i++){
// vertex(width/2 + coords[i][0] * mouseX - coords[i][1] * mouseY,
// height/2 + coords[i][0] * mouseY + coords[i][1] * mouseX);
vertex(width/2 + coords[i][0] * 0 - coords[i][1] * -100,
height/2 + coords[i][0] * -100 + coords[i][1] * 0);
}
endShape(CLOSE);
}