xxxxxxxxxx
112
let yellow, brightred;
function setup() {
pixelDensity(1);
createCanvas(400, 400, SVG);
frameRate(1);
yellow = new Riso('yellow');
brightred = new Riso('brightred');
//risoNoStroke();
}
function draw() {
background("white");
Sun1 = new sun(width / 2, height / 2);
Sun1.show();
drawRiso();
noLoop();
}
function mouseClicked() {
clearRiso();
redraw();
preload();
}
function keyPressed() {
if (keyCode === 32) {
exportRiso();
} else if (keyCode === DOWN_ARROW) {
clearRiso();
redraw();
}
return false; // prevent default
}
class sun {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = floor(random(120, 250));
this.rayWidth = floor(random(10, 15));
this.raySize = floor(random(30, 80));
this.rayQty = floor(random(5, 24));
this.colour1 = (255);
this.colour2 = (255);
this.strokeWeight = random(5,10);
}
show() {
brightred.fill(this.colour1);
brightred.noStroke();
yellow.fill(this.colour2);
yellow.noStroke();
// circle
ellipseMode(CENTER);
yellow.ellipse(this.x,this.y,this.size);
fill(241, 80, 96);
noStroke();
for(let i = 0; i < this.rayQty; i++){
push();
translate(this.x,this.y);
rotate(i * TWO_PI / this.rayQty);
beginShape();
vertex(-this.rayWidth, -this.size/2-this.strokeWeight);
vertex(0, -this.size/2-this.raySize);
vertex(+this.rayWidth, -this.size/2-this.strokeWeight);
endShape(CLOSE);
pop();
}
// //petals
// for (let i = 0; i < this.petals; i++) {
// // I used Chat GPT to figure this out
// push();
// translate(this.x, this.y);
// rotate(i * TWO_PI / this.petals);
// fill('yellow');
// beginShape();
// vertex(0, 0);
// bezierVertex(this.size * 0.1, -this.size * 0.2, this.size * 0.2, -this.size * 0.6, 0, -this.size * 0.5);
// bezierVertex(-this.size * 0.2, -this.size * 0.6, -this.size * 0.1, -this.size * 0.2, 0, 0);
// endShape(CLOSE);
// pop();
// }
}
}