Planetscape?
sketch
//tjchen
// project landscape
var stars=[]; // array for circles
var streaks=[]; // array for streaks
var speed = 3; // change for how zoom
// color initialization
var r;
var g;
var b;
// rate of change fo color
var dr;
var dg;
var db;
function setup() {
createCanvas(480, 480);
//initalize objects
for(i=0; i<=500; i++ ){
var s =makeStar();
var st=makeStreak();
stars.push(s);
streaks.push(st);
}
//background color setup
r = (random(255));
g = (random(255));
b = (random(255));
dr = (random(-5,5));
db = (random(-5,5));
dg = (random(-5,5));
}
function draw() {
background(r,g,b);
//set it up from the middle
translate(width/2,height/2);
//draw the stars and streaks
for(i=0; i<500; i++){
var s = stars[i];
s.drawstar();
s.updatestar()
var st = streaks[i];
st.drawstreak();
st.updatestreak();
}
// color update
if (r>255 || r<0){
dr= -dr;
}
if (g>255 || g<0){
dg= -dg;
}
if (b>255 || b<0){
db= -db;
}
r+=dr;
g+=dg;
b+=db;
}
//star construction
function makeStar(){
var star={
x:random(-width,width),
y:random(-height,height),
z:random(width), // constant ratio for zoom
c:color(random(255),random(255),random(255)),
drawstar: stardraw,
updatestar: starupdate,
}
return star;
}
function stardraw(){
noStroke();
fill(this.c);
// draw stars but mapped to z
var dx = map(this.x/this.z,0,1,0,width);
var dy = map(this.y/this.z,0,1,0,width);
// map it for sizze increase
var r = map(this.z,0,width,20,0);
ellipse(dx,dy,r);
}
function starupdate(){
this.z-=speed;
// reset
if (this.z<1){
this.z = width;
this.x = (random(-width,width));
this.y = (random(-height,height));
}
}
// streak construction
function makeStreak(){
var streak={
x:random(-width,width),
y:random(-height,height),
z:random(width),
c:color(random(255),random(255),random(255),50),
pz: this.z, // previous location of z
drawstreak: streakdraw,
updatestreak: streakupdate,
}
return streak;
}
function streakdraw(){
strokeWeight(5);
stroke(this.c);
var dx = map(this.x/this.z,0,1,0,width);
var dy = map(this.y/this.z,0,1,0,width);
var px = map(this.x/this.pz,0,1,0,width);
var py = map(this.y/this.pz,0,1,0,width);
//draw line
line(dx,dy,px,py);
}
function streakupdate(){
this.z-=speed;
// reset
if (this.z<1){
this.z = width;
this.x = (random(-width,width));
this.y = (random(-height,height));
this.pz = this.z;
}
}