xxxxxxxxxx
71
// Vivianna Mo
// Intro to IM - Shiloh
// Sept. 20 2022
// Assignment 3: Object Oriented Programming
//Description: this version I was trying to make twinkling starts in the sky.
galaxyColors = ["#FDFCFD","#EE7AE9","#8D3694","#6A327C","#8343B2","#4D3CD7","#44389E","#3C2E79","#28184D"]
let oneStar = [];
function setup() {
createCanvas(550, 550);
// so I was experimenting with my code and it crashed before I could save it, which meant I lost the link to the reference that helped me figure out that floor is needed in order to randomly generate a number for colors, which is an array.
// this is a similar code but not the one I used: https://editor.p5js.org/LizPina/sketches/9LF5GRL7
pickAColor = floor(random(galaxyColors.length));
for(let i = 0; i < 100; i++) {
oneStar[i] = new Stars(random(10, 540), random(10, 540), random(5, 15));
}
background(galaxyColors[8]);
}
function draw() {
noStroke();
// for(myCurve of BezierCurves) {
// myCurve.show();
// }
for(let i = 0; i < oneStar.length; i++) {
oneStar[i].show();
oneStar[i].growAndShrink();
}
}
class Stars {
constructor(x, y, size) {
this.pointX = x;
this.pointY = y;
this.size = size;
this.changeSize = 0.25;
this.color = color(galaxyColors[pickAColor])
this.alpha = this.color.setAlpha(128 + 128 * sin(millis() / 1000));
}
jitter() {
this.pointX += random(-0.05, 0.05);
this.pointY += random(-0.05, 0.05);
}
growAndShrink() {
this.size += this.changeSize;
if(this.size > 100) {
this.size = -this.size;
}
}
twinkle() {
}
show() {
fill(this.color);
ellipse(this.pointX, this.pointY, this.size);
}
}