xxxxxxxxxx
54
/*
try to reproduce the 'twinkling stars' effect in the gif. You should use the Star class in order to do this. Think of the starry sky as a group of star objects that change color over time.If you can't reproduce it exactly, come as close as you can.
*/
let stars = [];
function setup() {
createCanvas(600, 600);
for (let i = 0; i < 1000; i ++)
{
stars[i]= new Star();
}
}
function draw() {
background(0);
for (let i = 0; i < stars.length -1; i ++)
{
stars[i].show();
stars[i].shiny();
}
}
class Star {
constructor ()
{
this.x = random(width);
this.y = random (height);
this.trans = random (0,255);
this.changeTrans = random(-2,4);
}
show ()
{
stroke (this.trans);
strokeWeight (2);
point (this.x, this.y)
}
shiny ()
{
this.trans += this.changeTrans;
if (this.trans >=255 || this.trans <=25)
{
this.changeTrans= - this.changeTrans;
}
}
}