Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//Coordinate Variables
float pressedX;
float pressedY;
float releaseX;
float releaseY;
float GrowingX;
float GrowingY;

//Logic variables
boolean release = false;
boolean running = false;

//colour coordination Variables
float colX;
float colY;
float colZ;

//Random motion variables
float xmotion;
float ymotion;

//misc Variables
float stress = 0;
float counter = 0;
float drag = 0;

//Visor stats
float visorpoint1Y = 111;
float visorpoint2Y = 119;

void setup() {
  size(400, 400); 
  fill(50, 50, 50);

  //background color

  rect(0, 0, 400, 400);

  //Instructions
  print("Click and Drag to piss off Starman!");
}

void draw() {

  //establish and give value to rise/run variables
  float rise = getRise(pressedX, releaseX);
  float run = getRun(pressedY, releaseY);


  //release is set to true when the mouse is released and set to false when timetorock has has drawn a line off screen
  if (release) {
    timetorock(pressedX, pressedY, run, rise);
  }

  starmandraw();
  updatevisor();
  drawvisor();

  if (stress >= 20) {
    Starmanissickofyourgarbage();
  }
}

void starmandraw() {

  //makes Starman jitter more as he gets stressed
  xmotion = random(-1, 1)*(stress/2);
  ymotion = random(-1, 1)*(stress/2);
  //So the whole thing can go -10 or +10 up down left or right

  //Draw a bordered rectangle around him so that his infinite recursive instances are hidden
  strokeWeight(3);
  stroke(255, 255, 255);
  fill(0, 0, 0);
  rect(100, 59, 190, 280);

  //resets to zero after it changes in timetorock
  strokeWeight(0);

  //StarmanHead
  fill(198, 202, 246);
  stroke(150, 153, 186);
  triangle(200+xmotion, 80+ymotion, 180 +xmotion, 130+ymotion, 220+xmotion, 130+ymotion);
  noStroke();
  fill(0, 0, 0);
  rect(180 +xmotion, 70+ymotion, 50, 35);
  rect(190+xmotion, 110+ymotion, 20, 10);

  //StarmanBody
  fill(198, 202, 246);
  stroke(150, 153, 186);
  quad(160+xmotion, 130+ymotion, 240+xmotion, 130+ymotion, 230+xmotion, 210+ymotion, 170+xmotion, 210+ymotion);
  fill(0, 0, 0);
  triangle(210 +xmotion, 150+ymotion, 230 +xmotion, 150+ymotion, 220 +xmotion, 160+ymotion);
  rect(205 +xmotion, 163+ymotion, 20, 10);
  rect(205 +xmotion, 175+ymotion, 20, 7);
  rect(228 +xmotion, 163+ymotion, 5, 10);

  //Starman Arms
  fill(198, 202, 246);
  stroke(150, 153, 186);
  triangle(160 +xmotion, 131+ymotion, 150 +xmotion, 160+ymotion, 130 +xmotion, 160+ymotion);
  triangle(150 +xmotion, 160+ymotion, 130 +xmotion, 160+ymotion, 165 +xmotion, 200+ymotion);
  triangle(140 +xmotion, 220+ymotion, 155 +xmotion, 190+ymotion, 166 +xmotion, 202+ymotion);

  triangle(240 +xmotion, 131+ymotion, 250 +xmotion, 160+ymotion, 270 +xmotion, 160+ymotion);
  triangle(250 +xmotion, 160+ymotion, 270 +xmotion, 160+ymotion, 235 +xmotion, 200+ymotion);
  triangle(260 +xmotion, 220+ymotion, 245 +xmotion, 190+ymotion, 234 +xmotion, 202+ymotion);

  //Starman Legs
  triangle(170 +xmotion, 210+ymotion, 190 +xmotion, 210+ymotion, 175 +xmotion, 300+ymotion);
  triangle(230 +xmotion, 210+ymotion, 210 +xmotion, 210+ymotion, 225 +xmotion, 300+ymotion);

  //Starman Feet
  ellipse(175 +xmotion, 293+ymotion, 30, 20);
  ellipse(225 +xmotion, 293+ymotion, 30, 20);
}

void updatevisor() {
  /*
  add stress to the point so the lines will be moving faster at higher stress
   decrement the values until they are for sure on the visor
   */
  visorpoint1Y = visorpoint1Y + (stress/7.5);

  visorpoint2Y = visorpoint2Y + (stress/7.5);

  while (visorpoint1Y > 119) {
    visorpoint1Y = visorpoint1Y-5;
  }
  while (visorpoint2Y > 119) {
    visorpoint2Y = visorpoint2Y-5;
  }
}

void drawvisor() {
  //1st and 4th lines contain fixed X points at the end of the visor
  stroke(200, 0, 0);
  strokeWeight(1);
  line(190+xmotion, 115+ymotion, 195+xmotion, visorpoint1Y+ymotion);
  line(195+xmotion, visorpoint1Y+ymotion, 200+xmotion, visorpoint2Y+ymotion);
  line(200+xmotion, visorpoint2Y+ymotion, 205+xmotion, visorpoint1Y+ymotion);
  line(205+xmotion, visorpoint1Y+ymotion, 210+xmotion, 115+ymotion);
}

//establish point where drag begins
void mousePressed() {
  pressedX = mouseX;
  pressedY = mouseY;
}

//establish point where drag ends
void mouseReleased() {
  releaseX = mouseX;
  releaseY = mouseY;

  //checks the two points are not identical
  if (releaseX!=pressedX || releaseY!=pressedY) {
    release = true;
  }
}

//establishes rise variables
float getRise(float Y1, float Y2) {
  float rise = Y1-Y2;
  return rise;
}

//established run values
float getRun(float X1, float X2) {
  float run = X1-X2; 
  return run;
}

void timetorock(float X1, float Y1, float rise, float run) {
  //Establishing the incrementing variables
  if (!running) {
    GrowingX = X1;
    GrowingY = Y1;
  }

  //moving the first point of the line off-screen
  while ((GrowingX > 0 && GrowingX < 400) && (GrowingY > 0 && GrowingY < 400)&& !running) {
    GrowingX = GrowingX+run;
    GrowingY = GrowingY+rise;
  }

  //sets Running to true so the line will not continue resetting until the pattern is complete
  running = true;

  //handling colors
  if (counter == 3) {
    counter = 0;
  }
  if (counter == 0) {
    colX = 255;
    colY = 0;
    colZ = 0;
  }
  if (counter == 1) {
    colX = 0;
    colY = 0;
    colZ = 255;
  }
  if (counter == 2) {
    colX = 255;
    colY = 255;
    colZ = 0;
  }

  //Draws lines behind each other in different transparencies
  stroke(colX, colY, colZ, 255);
  strokeWeight(6);
  line(GrowingX, GrowingY, GrowingX-run, GrowingY-rise);
  stroke(colX, colY, colZ, 150);
  strokeWeight(20);
  line(GrowingX, GrowingY, GrowingX-run, GrowingY-rise);
  stroke(colX, colY, colZ, 50);
  strokeWeight(50);
  line(GrowingX, GrowingY, GrowingX-run, GrowingY-rise);

  //increments the starting values of the lines to continue the pattern
  GrowingX = GrowingX-run;
  GrowingY = GrowingY-rise;

  // If the method is running and the values are offscreen, the method will stop being called every frame
  if (running) {
    if (GrowingX > 400 || GrowingX < 0 || GrowingY > 400 || GrowingY < 0) {
      running = false;
      release = false;
      counter++;
      stress++;
    }
  }
}

void Starmanissickofyourgarbage() {
  //Draw Rectangle over patterns and old background
  fill(50, 50, 50);
  stroke(0, 0, 0);
  rect(0, 0, drag, 400);

  starmandraw();

  //Draw Beam
  fill(255, 255, 0);
  stroke(255, 225, 0);
  strokeWeight(3);
  triangle(200+xmotion, 90+ymotion, drag, 0, drag, 400);

  if (drag > 400) {
    stress = 0;
    //draw another rectangle to delete the remnants of the beam
    fill(50, 50, 50);
    stroke(50,50,50);
    rect(0, 0, 400, 400);
    drag = -5;
  }
  //increase drag so the beam moves across the screen
  drag = drag+5;
  

}