xxxxxxxxxx
43
//generative art of a sunset using my 5 colors
//using reusable functions
let colorRange_sea = ['#6EB9E7', '#46A4DE', '#208DD1', '#00619E'];
let color_sun = '#EAC53F';
function setup() {
createCanvas(400, 400);
background(220);
noFill();
}
function draw() {
clearCanvas();
drawSun();
drawHorizon();
}
//refresh canvas every 1000 frames
function clearCanvas() {
if(frameCount%1000==0){
background(220);
}
}
//draw sun: half circle with the color of sun. radius and thickness varies.
function drawSun() {
// draw sun. center and color is fixed, size varies
r = random(0, 300);
strokeWeight(0.3);
stroke(color_sun);
arc(width/2, height/2, r, r, PI, TWO_PI);
}
//draw horizon: horizontal lines of the sea. x, y position in which line starts varies. width also varies and can be a negative or positive number. colors range within color range of sea
function drawHorizon() {
x = random(0, width);
y = random(height/2, height);
w = random(width/5, width*0.8)*random([-1, 1]);
strokeWeight(5);
stroke(random(colorRange_sea));
line(x, y, x+w, y);
}