Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/******************************************************************
* File Name: Asteroids
* Author: Gabriel Duarte
* Student Number: 991433574
* Date: Sept 22, 2016
* Description: An asteroids inspired interactive drawing where the 
vertical mouse position controls the placement and alpha of the 
asteroids and the horizontal mouse position controls where the ship
is. Also, the stars are paralaxed towards the mouse and the screen 
flases when the mouse is clicked.
******************************************************************/


//Executed at begining:
void setup() {
  size(400, 400);
  
}

//Everyy frame:
void draw() {
  
  //Sets backgound to black:
  background(0);
  
  //Draws stars:
  fill(255);
 
  /*0*/ ellipse(mouseX/12+347, -mouseY/12+332, 2, 2);
  /*1*/ ellipse(mouseX/12+67, -mouseY/12+44, 2, 2);
  /*2*/ ellipse(mouseX/12+137, -mouseY/12+109, 2, 2);
  /*3*/ ellipse(mouseX/12+66, -mouseY/12+223, 2, 2);
  /*4*/ ellipse(mouseX/12+69, -mouseY/12+275, 2, 2);
  /*5*/ ellipse(mouseX/12+279, -mouseY/12+193, 2, 2);
  /*6*/ ellipse(mouseX/12+342, -mouseY/12+56, 2, 2);
  /*7*/ ellipse(mouseX/12+133, -mouseY/12+256, 2, 2);
  /*8*/ ellipse(mouseX/12+58, -mouseY/12+345, 2, 2);
  /*9*/ ellipse(mouseX/12+149, -mouseY/12+300, 2, 2);
  /*10*/ ellipse(mouseX/12+356, -mouseY/12+295, 2, 2);
  
  /*11*/ ellipse(mouseX/8+72, -mouseY/8+43, 2, 2);
  /*12*/ ellipse(mouseX/8+305, -mouseY/8+195, 2, 2);
  /*13*/ ellipse(mouseX/8+250, -mouseY/8+302, 2, 2);
  /*14*/ ellipse(mouseX/8+226, -mouseY/8+138, 2, 2);
  /*15*/ ellipse(mouseX/8+269, -mouseY/8+94, 2, 2);
  /*16*/ ellipse(mouseX/8+1, -mouseY/8+296, 2, 2);
  /*17*/ ellipse(mouseX/8+136, -mouseY/8+135, 2, 2);
  /*18*/ ellipse(mouseX/8+388, -mouseY/8+384, 2, 2);
  /*19*/ ellipse(mouseX/8+302, -mouseY/8+187, 2, 2);
  /*20*/ ellipse(mouseX/8+374, -mouseY/8+205, 2, 2);
  
  /*21*/ ellipse(mouseX/15+215, -mouseY/15+151, 2, 2);
  /*22*/ ellipse(mouseX/15+386, -mouseY/15+96, 2, 2);
  /*23*/ ellipse(mouseX/15+224, -mouseY/15+326, 2, 2);
  /*24*/ ellipse(mouseX/15+165, -mouseY/15+292, 2, 2);
  /*25*/ ellipse(mouseX/15+356, -mouseY/15+241, 2, 2);
  /*26*/ ellipse(mouseX/15+373, -mouseY/15+376, 2, 2);
  /*27*/ ellipse(mouseX/15+246, -mouseY/15+247, 2, 2);
  /*28*/ ellipse(mouseX/15+396, -mouseY/15+176, 2, 2);
  /*29*/ ellipse(mouseX/15+310, -mouseY/15+275, 2, 2);
  /*30*/ ellipse(mouseX/15+28, -mouseY/15+162, 2, 2);
  
  //DRAWS ALL ASTEROIDS:

  //Makes asteroids transparent:
  stroke(255, 255, 255, mouseY-30);
  fill(0, 0, 0, mouseY+80);
  
  //Asteroid_1
  quad(
    60, (mouseY-10)+50,
    140, (mouseY-50)+50,
    170, (mouseY+30)+50,
    100, (mouseY+30)+50
  );
  
  //Asteroid_2:
  quad(
    250, (mouseY-20),
    310, (mouseY-20),
    300, (mouseY+20),
    270, (mouseY+10)
  );
  
  //Asteroid_3:
  quad(
    140+30, (mouseY+10)-30,
    145+30, (mouseY-10)-30,
    160+30, (mouseY-5)-30,
    150+30, (mouseY+10)-30
  );
  
  //Asteroid_4:
  quad(
    90-30, (mouseY+50)-80,
    50-30, (mouseY+10)-80,
    70-30, (mouseY-20)-80,
    130-30, (mouseY-30)-80
  );
  
  //Asteroid_5:
  quad(
    230+60, (mouseY)-85,
    280+60, (mouseY-10)-85,
    310+60, (mouseY-40)-85,
    300+60, (mouseY+20)-85
  );
  
  //Asteroid_6:
  quad(
    220, (mouseY-10)-140,
    210, (mouseY-10)-140,
    220, (mouseY+20)-140,
    240, (mouseY)-140
  );
  
  //Asteroid_7:
  quad(
    220, mouseY-250,
    240, mouseY-200,
    300, mouseY-210,
    310, mouseY-255
  );
  
  //Asteroid_8:
  quad(
    50, mouseY-300,
    100, mouseY-200,
    150, mouseY-210,
    190, mouseY-255
  );
  
  //Draws ship:
  fill(0);
  stroke(255);
  quad(
    mouseX-10, 340,
    mouseX, 320,
    mouseX+10, 340,
    mouseX, 335
  );
  
  //Sets the cursor:
  fill(0);
  stroke(255);
  
  ellipse(mouseX, mouseY, 3, 3);
  
  line(mouseX, mouseY-4, mouseX, mouseY-8);
  line(mouseX, mouseY+4, mouseX, mouseY+8);
  
  line(mouseX-4, mouseY, mouseX-8, mouseY);
  line(mouseX+4, mouseY, mouseX+8, mouseY);
  
}

//Mouse click "flash":
void mousePressed() {
  fill(random(255), random(255), random(255), 255);
  rect(0, 0, width, height);
}