xxxxxxxxxx
38
let sunRadius = 50;
let sunColor;
let angle = 0;
function setup() {
createCanvas(400, 400);
sunColor = color(255, 255, 0);
}
function draw() {
background(220,0);
// Draw the sun
fill(sunColor);
stroke(255, 144, 193);
strokeWeight(3);
ellipse(width / 2, height / 2, sunRadius * 2);
// Draw sun rays
drawSunRays(width / 2, height / 2, sunRadius + 10, 12);
// Make the sun spin
angle += 0.01;
sunRadius = 50 + 10 * sin(angle);
}
function drawSunRays(x, y, radius, numRays) {
let angleIncrement = 360 / numRays;
for (let i = 0; i < numRays; i++) {
let startX = x + cos(radians(i * angleIncrement)) * radius;
let startY = y + sin(radians(i * angleIncrement)) * radius;
let endX = x + cos(radians(i * angleIncrement)) * (radius + 20);
let endY = y + sin(radians(i * angleIncrement)) * (radius + 20);
line(startX, startY, endX, endY);
}
}