> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.fVCrJ4JwmSL/rev.4
 * 
 * authors: 
 *   GoToLoop

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/**
 * Starfield (v2.0)
 * by  TfGuy44 (2014/Jun)
 * mod GoToLoop
 *
 * forum.processing.org/two/discussion/5758/
 * making-points-move-out-of-the-screen
 * from-the-center-to-the-edges-warp-speed
 *
 * studio.processingtogether.com/sp/pad/export/ro.9ZbTlw0Ak8yUR/latest
 */

static final int NUM = 02000;
final Star[] stars = new Star[NUM];

void setup() {
  size(600, 400, JAVA2D);
  frameRate(60);
  noSmooth();

  stroke(Star.OUTLINE);
  background(0);

  for (int i = 0; i != NUM; stars[i++] = new Star());
}

void draw() {
  if (!(mousePressed | keyPressed))  background(0);
  for (Star s: stars)  s.display();
}

class Star {
  static final int MAX_SPD = 3;
  static final color OUTLINE = -1;

  float px, py, vx, vy;

  Star() {
    reset();
  }

  void reset() {
    float r = random(width+height);

    vx = random(-MAX_SPD, MAX_SPD);
    vy = random(-MAX_SPD, MAX_SPD);

    px = (width>>1)  + vx*r;
    py = (height>>1) + vy*r;
  }

  void display() {
    if ((px += vx)<0 | px>width | (py += vy)<0 | py>height)  reset();

    if (mousePressed | keyPressed)  line(px, py, px-vx, py-vy);
    else                            set((int) px, (int) py, OUTLINE);
  }
}