expo-processing/Star.pde

94 lines
2.3 KiB
Plaintext
Executable File

class Star {
float x;
float y;
float z;
float pz;
int c;
Star()
{
x = random(-width, width);
y = random(-height, height * 2);
z = random(width);
pz = z;
c = int(random(20));
}
void update()
{
z -= tg_starfield_speed;
if (z < 1)
{
z = width;
x = random(-width / 2, width / 2);
y = random(-height / 2, height / 2);
pz = z;
}
}
void render()
{
if (c == 0)
fill(255,210,125);
if (c == 1)
fill(255,163,113);
if (c == 2)
fill(166,168,255);
if (c == 3)
fill(255,250,134);
if (c == 4)
fill(168,123,255);
if (c > 4)
fill(255, 255, 255);
noStroke();
pushMatrix();
translate(width / 2, height / 2, -1000);
float sx = map(x / z, 0, 1, 0, width);
float sy = map(y / z, 0, 1, 0, height);
float r = map(z, 0, width, 16, 0);
float px = map(x / pz, 0, 1, 0, width);
float py = map(y / pz, 0, 1, 0, height);
ellipse(sx, sy, r, r);
if (c == 0)
stroke(255,210,125);
if (c == 1)
stroke(255,163,113);
if (c == 2)
stroke(166,168,255);
if (c == 3)
stroke(255,250,134);
if (c == 4)
stroke(168,123,255);
if (c > 4)
stroke(255, 255, 255);
strokeWeight(1);
beginShape();
vertex(sx, sy - r / 4);
vertex(sx + r * 1.5, sy);
vertex(sx, sy + r / 4);
endShape();
beginShape();
vertex(sx, sy - r / 4);
vertex(sx - r * 1.5, sy);
vertex(sx, sy + r / 4);
endShape();
beginShape();
vertex(sx - r / 4, sy);
vertex(sx, sy + r * 1.5);
vertex(sx + r / 4, sy);
endShape();
beginShape();
vertex(sx - r / 4, sy);
vertex(sx, sy - r * 1.5);
vertex(sx + r / 4, sy);
endShape();
strokeWeight(r / 2);
line(px, py, sx, sy);
popMatrix();
pz = z;
}
}