> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://google-kir-2013.sketchpad.cc/sp/pad/view/ro.-sSW8o$GbRL/rev.11
 * 
 * authors: 
 *   Alina Uberti
 *   Filip Icev
 *   Dathan Ault-McCoy
 *   Buka Berk
 *   Mark Belianski
 *   Dennis Belianski
 *   Brooklyn Gibbs
 *   Alex Rutherford
 *   Karen X
 *   Rami Rifaat
 *   Yifan Wen
 *   Rasekh Rifaat
 *   Nick Kline
 *   Matthew Howard
 *   
 *   Beckom Gutierrez
 *   Corbin Gutierrez
 *   Raz Mathias
 *   Corwin O'Madadhain

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



// Pressing Control-R will render this sketch.
 
void setup() {  // this is run once.   
    
    // set the background color
    background(0);
    
    // canvas size (Variable aren't evaluated. Integers only, please.)
    size(300, 300); 
      
    // smooth edges
    smooth();
    
    // limit the number of frames per second
    frameRate(30);
    
    colorMode(RGB, 100);
    
    // set the width of the line. 
    strokeWeight(2);
    
    PFont fontA = loadFont("Courier New");
 
    textFont(fontA, 36);
 
    textAlign(RIGHT);
} 
 
int speedScale = 2.0;
int score = 0;
 
void draw() {
    background(0);
    drawStars();
    drawShip();
    drawGems();
    drawScore();
}
 
void drawScore() {
    text("" + score, 250, 40);
}
 
int topOfShipY = 250;
int topOfShipX = 150;
int shipHeight = 20;
int shipWidth = 20;
 
int maxSpeed = 30 * speedScale;
int vel;
 
void keyPressed() {
    if (keyCode == LEFT) {
        vel = -maxSpeed;
    } else if (keyCode == RIGHT) {
        vel = maxSpeed;
    }
}
 
void keyReleased() {
    vel = 0;
}
 
int greenness = 0;
 
void drawShip() {
    greenness ++;
    if (greenness > 100) {
        greenness = 0;
    }
    topOfShipX += (vel / 30)
    stroke(100, 0, 0);
    fill(0, greenness, 0);
    triangle(topOfShipX, 
             topOfShipY, 
             topOfShipX + (shipWidth / 2),
             topOfShipY + shipHeight,
             topOfShipX - (shipWidth / 2),
             topOfShipY + shipHeight);
}
 
int numStars = 20;
int[] starX = new int[numStars];
int[] starY = new int[numStars];
int[] starBright = new int[numStars];
int starSpeed = 60 * speedScale;
 
for (int i = 0; i < numStars; i++) {
    starX[i] = random(300);
    starY[i] = random(300);
    starBright[i] = random(100);
}
 
void drawStars() {
    for (int i = 0; i < numStars; i++) {
        starY[i] = starY[i] + (starSpeed / 30);
        if (starY[i] > 300) {
            starY[i] = 0;
            starX[i] = random(300);
        }
        starBright[i] -= 2;
        if (starBright[i] < 0) {
            starBright[i] = 100;
        }
        stroke(starBright[i]);
        point(starX[i], starY[i]);
    } 
}
 
 
int numGems = 3;
int[] gemX = new int[numGems];
int[] gemY = new int[numGems];
int[] gemColor = new int[numGems];
int[] gemSpin = new int[numGems];
int gemSpeed = 30 * speedScale;
int gemSize = 15;
int gemSpinSpeed = 2;
 
for (int i = 0; i < numGems; i++) {
    gemX[i] = random(300);
    gemY[i] = random(300);
    gemColor[i] = random(100);
    gemSpin[i] = random(100);
}
 
void drawGems() {
    for (int i = 0; i < numGems; i++) {
        gemY[i] = gemY[i] + (gemSpeed / 30);
        if (abs(gemX[i] - topOfShipX) < gemSize / 2
            && abs(gemY[i] - topOfShipY) < gemSize / 2) {
            gemY[i] = 301;
            score++;
        }
        if (gemY[i] > 300) {
            gemY[i] = 0;
            gemX[i] = random(300);
        }
        gemColor[i] -= 1;
        if (gemColor[i] < 0) {
            gemColor[i] = 100;
        }
        gemSpin[i] += gemSpinSpeed;
        if (gemSpin[i] > 100) {
            gemSpin[i] = 0;
        }
        
        colorMode(HSB, 100);
        stroke(0, 0, 100);
        fill(gemColor[i], 50, 100);
        translate(gemX[i], gemY[i]);
        rotate(PI * gemSpin[i] / 50);
        
        rect(-gemSize/2, 
             -gemSize/2,
             gemSize,
             gemSize)
        resetMatrix();
        colorMode(RGB, 100);
    } 
}