Kinetic Interfaces: Week3 Buttons (Muru)

This game is clicking the square of different color. The duration time of  each round will be less than the previous one. I actually planned to have more and more squares each round, but there were some bugs and I did not achieve that.

import processing.sound.*;
SoundFile sound;

ArrayList<Button> g_RenderBtns = new ArrayList<Button>();

float g_Fps = 60;
float g_LogicFrameInterval = 1000 / g_Fps;
int   g_OnlyBtnIndex = 0;
int   g_RoundTime = 8000;
float g_ReduceFactor = 0.8;
int   g_DefaultFrameInterval = (int)(g_RoundTime / g_LogicFrameInterval);
int   g_NextRoundFrame = frameCount + g_DefaultFrameInterval;
int   g_RoundNum = 0; 
int   g_rightRoundNum = 0;

void setup() {
  size(1000, 1000);
  background(0);
  //noStroke();
  frameRate(g_Fps);

  sound = new SoundFile(this, "sound.wav");
  // Create full-screen buttons.
  float btn_width = 200;
  float btn_height = 200;
  int btnsNum_x = (int)(width / btn_width);
  int btnsNum_y =  (int)(height / btn_height);
  int btnsNum = btnsNum_x * btnsNum_y;


  g_OnlyBtnIndex = (int)random(0, btnsNum);
  int r = (int)random(256);
  int g = (int)random(256);
  int b = (int)random(256);
  int a = (int)random(100, 256);
  color commonClr = color(r, g, b, a);

  for (int i = 0; i < btnsNum; ++i)
  {
    float btn_x = (i % btnsNum_x) * btn_width;
    float btn_y = (int)(i / btnsNum_y) * btn_height;

    color clr = commonClr;
    if (i == g_OnlyBtnIndex)
    {
      int diff = 20;
      clr = color(max(r - diff, 0), max(g - diff, 0), max(b - diff, 0), a);
    }

    Button btn = new Button();
    btn.Init(btn_x, btn_y, btn_width, btn_height, clr);

    g_RenderBtns.add(btn);
  }
}

boolean IsRoundOver()
{
  if (frameCount >= g_NextRoundFrame)
  {
    ++g_RoundNum;
    g_NextRoundFrame = frameCount + (int)(g_DefaultFrameInterval * pow(g_ReduceFactor, g_RoundNum));
    g_NextRoundFrame = (int)(max(g_NextRoundFrame, frameCount + 30));

    return true;
  }

  return false;
}

void draw() {
  background(0);

  boolean bRoundOver = IsRoundOver();
  int btnsNum = g_RenderBtns.size();

  int r = 0;
  int g = 0;
  int b = 0;
  int a = 0;
  color newClr = color(r, g, b, a);
  color commonClr = color(r, g, b, a);
  if (bRoundOver)
  {
    g_OnlyBtnIndex = (int)random(0, btnsNum);
    r = (int)random(256);
    g = (int)random(256);
    b = (int)random(256);
    a = (int)random(100, 256);
    commonClr = color(r, g, b, a);
  }

  for (int i = 0; i < btnsNum; ++i)
  {
    Button btn = g_RenderBtns.get(i);  
    if (bRoundOver)
    {
      if (i == g_OnlyBtnIndex)
      {
        int diff = 20;
        newClr = color(max(r - diff, 0), max(g - diff, 0), max(b - diff, 0), a);
      } else
      {
        newClr = commonClr;
      }
      btn.SetColor(newClr);
    }
    btn.Update();
    btn.Render();
  }

  //
  fill(color(255, 255, 255, 255));
  textSize(36);
  text(g_rightRoundNum, 20, 40);
}

void mousePressed() {
  for (int i = 0; i < g_RenderBtns.size(); ++i)
  {
    Button btn = g_RenderBtns.get(i);
    if (btn.IsInclude(mouseX, mouseY) && i == g_OnlyBtnIndex)
    {
      g_NextRoundFrame = frameCount + 1;
      ++g_rightRoundNum;
      sound.play();
    }
  }
}
class Button {
  float x, y;
  float w, h;
  color clr;
  
  void Init(float _x, float _y, float _w, float _h, color _clr) {
    //
    x = _x;
    y = _y;
    w = _w;
    h = _h;

    //
    clr = _clr;
  }

  void SetColor(color _clr)
  {
    clr = _clr;
  }

  void Update()
  {
    
  }

  void Render()
  {
    //
    fill(clr);
    rect(x, y, w, h);
  }
  
  boolean IsInclude(float _x, float _y)
  {
    float deltaX = _x - x;
    float deltaY = _y - y;
    if(deltaX > 0 && deltaX < w &&
        deltaY > 0 && deltaY < h)
    {
      return true;
    }
    
    return false;
  }
}

Kinetic Interfaces: Week 3 Buttons(Harrison)

This week, I attempted to make a musical staff generation system with buttons. And down below in the red rect users can interact with the system by swiping the mouse to playblast the short phrase created by himself. Video: 2nd Instruction: -Press the key and click mouse to add notes. -Click the note to shift […]

// IMA NYU Shanghai
// Kinetic Interfaces Week 3
// Harrison
// Feb 11 2016

import processing.sound.*;
SoundFile sound;

ArrayList<Note> notes = new ArrayList<Note>();
int i;
void setup() {
  size(1300, 350);
  sound = new SoundFile(this, "sound.wav");
  sound.play();
}


void draw() {
  background(255);
  stroke(0);
  strokeWeight(1);
  line(0, 50, 1300, 50);
  line(0, 70, 1300, 70);
  line(0, 90, 1300, 90);
  line(0, 110, 1300, 110);
  line(0, 130, 1300, 130);
  fill(255, 0, 0, 200);
  rect(0, 180, width, 170, 10);
  float speed = dist(pmouseX, pmouseY, mouseX, mouseY);
  int count = 0;
  if (!keyPressed) {
    for (int i=0; i<notes.size(); i++) {
      Note b = notes.get(i);
      b.update();
      b.display();
      b.play();
    }
  }else{
    for (int i=0; i<notes.size(); i++) {
      Note b = notes.get(i);
      b.displaynew();
    }
  }
}
void keyPressed() {
  if (mousePressed) {
    if (mouseY>50 && mouseY<151) {
      int up = mouseY-mouseY%10 + 10;
      notes.add( new Note(mouseX, up, sound ));
    }
  }
}

class Note {
  float posX, posY, size;
  color clr;
  float   r, g, b; // color
  int state = 0;
  boolean prevPress = false;
  SoundFile sound;


  Note(float tempX, float tempY, SoundFile snd) {
    posX = tempX;
    posY = tempY;
    size = 20;
    sound = snd;
  }

  void update() {
    checkState();
  }
  void checkState() {
    float distance = dist(posX, posY, mouseX, mouseY);
    boolean currPress = false;
    if (distance < size/2) {
      //hovers
      state = 1;
      if (mousePressed) {
        currPress = true;
        if (!prevPress) {
          //triggered
          state = 2;
        } else {
          //onPress
          state = 3;
        }
      } else if (prevPress) {
        //released
        state = 4;
      }
    } else {
      state = 0;
    }

    println(prevPress, currPress);
    prevPress = currPress;
  }

  void displaynew() {
    fill(10, 10, 10);
    ellipse(posX, posY, size, size);
  }

  void display() {

    pushStyle();
    
    switch (state) {
    case 0:
      stroke(r, g, b);
      fill(r, g, b, 150);
      ellipse(posX, posY, size, size);
      break;
    case 1: // hover
      stroke(r, g, b);
      fill(200, 50, 100);
      ellipse(posX, posY, size, size);
      break;
    case 2: // triggered
      stroke(r, g, b);
      fill(r, g, b, 150);
      ellipse(posX, posY, size*1.5, size*1.5);
      //sound.play();
      break;
    case 3: // on press
      stroke(r, g, b);
      fill(r, g, b);
      ellipse(posX, posY, size*0.9, size*0.9);
      break;
    case 4: // released
      stroke(r, g, b);
      fill(30, 250, 20, 150);
      ellipse(posX, posY, size, size);
      posY = 10*int(random(6,15));
      break;
    }

    popStyle();
  }

  void play(){
    if(mouseY>180 && mouseY<height){
      if(mouseX>posX && pmouseX<posX){
        sound.play();
      }
    }
  }
  
}

Kinetic Interfaces : Week 3 Buttons (Oli)

This week I worked on developing a simple game that simulated a lantern blowing in the wind. By using two buttons the player can alter the course of the lantern. Points are one by preventing the lantern from hitting the walls. vid  

PImage img;
float posX;
float posY;
float velX;
float velY;
float btnPosX, btnPosY, btnSize, btnPosLeftX, btnPosLeftY;
boolean leftJustPressed;
boolean justPressed;
int score;



void setup(){
  size(500,600);
  
  reset();
  
  img = loadImage("lanternImg.jpg");
  
  btnPosX = width*0.85;
  btnPosY = height*0.92;
  
  btnPosLeftX = width*0.15;
  btnPosLeftY = height*0.92;

  justPressed = false;
  leftJustPressed = false;

  score = 0;
}



void draw(){
  background(0);
  
  if(posY < -height*0.35){
    score = score + 1;
    reset();
  }
  

  image(img, posX, posY, width*0.3, height*0.4);
  updateImg();
  
  if(posX < width*0.15 || posX > width * 0.8 - width*0.29){
    reset();
  }
  
  displayText();
  
  
  rectDraw();

  buttons();

}

void updateImg () {
    posX = posX + velX;
    posY = posY + velY;

}

void reset() {
    posY = height * 0.9;
    posX = width/2;
    
    velX = random(-2.5,2.5);
    velY = random(-1.5,-5);

}


void rectDraw() {

  fill(255,0,0);
  stroke(255,255,255);
  rect(width*0.15, 0, 10, height);
  rect(width*0.8, 0, 10, height);



}

void mousePressed() {


}

void buttons(){
  btnSize = 80;
    
    strokeWeight(4);
    pushStyle();
  
    float distance = dist(btnPosX, btnPosY, mouseX, mouseY);
    
    if ( distance < btnSize/2) { // radious
      if (mousePressed) {
        fill(random(255), random(255), random(255));
        stroke(random(255), random(255), random(255));
        ellipse(btnPosX, btnPosY, btnSize, btnSize);
        if(justPressed == false){
          velX = -velX;
        }
        justPressed = true;
         println(velX);
      } else {
        fill(255, 0, 255);
        ellipse(btnPosX, btnPosY, btnSize, btnSize);
      }
    } else {
      fill(255, 0, 0);
      ellipse(btnPosX, btnPosY, btnSize, btnSize);
      justPressed = false;
    }
    
    popStyle();
    
    float distanceLeft = dist(btnPosLeftX, btnPosLeftY, mouseX, mouseY);
    
    if ( distanceLeft < btnSize/2) { // radious
      if (mousePressed) {
        fill(random(255), random(255), random(255));
        stroke(random(255), random(255), random(255));
        ellipse(btnPosLeftX, btnPosLeftY, btnSize, btnSize);
        if(!leftJustPressed){
          velX = -velX;
        }
        leftJustPressed = true;
      } else {
        fill(255, 0, 255);
        ellipse(btnPosLeftX, btnPosLeftY, btnSize, btnSize);

      }
    } else {
      fill(255, 0, 0);
      ellipse(btnPosLeftX, btnPosLeftY, btnSize, btnSize);
      leftJustPressed = false;

    }
    
    
  }

void displayText(){
  textSize(32);
  fill(255, 255, 0);
  text(score , width*0.05, height*0.05);
}

Kinetic Interface: Week3- interactiveGame(Cyndi)

In this assignment I tried to make use of mouse acceleration to control the movement of the balls, also added some button and sound effect to the balls. 

ArrayList <Ball>balls = new ArrayList<Ball>();
int state = 0;
float accX, accY;
import processing.sound.*;
SoundFile press;
SoundFile hover;
/** 
 state
 0: not pressed
 1: on press
 2: swipe left
 3: swipe right
 4: hover
 **/
void setup() {
  size(800, 600);
  //frameRate(5);
  press = new SoundFile(this, "press.wav");
  //press.play();
  hover = new SoundFile(this, "hover.wav");
  //hover.play();
  for (int i=0; i<50; i++) {
    balls.add(new Ball(random(100, 400), random(200, 500), 40, random(10, 20)));
  }
}

void draw() {
  background(0);
  for (int i = 0; i < balls.size(); i++) {
    Ball ba = balls.get(i);
    ba.update();
    ba.checkStates();
    //ba.leftwind();
    switch(state) {
    case 1:
      for (int j=10; j>=0; j--) {
        //balls.add( new Ball(random(ba.pos.x-5,ba.pos.x+5), random(ba.pos.y-5,ba.pos.y+5), 10,random(10,20)));
        balls.add( new Ball(random(width), random(height), 10, random(10, 20)));
        press.play();
        if (ba.isDead) {
          balls.remove(j);
        }
      }
      break;
    case 2:
      ba.leftwind();
      break;
    case 3:
      ba.rightwind();
      break;
    case 4:
      //sound
      hover.play();
      break;
    }

    for (int j =0; j<balls.size(); j++) {
      if (i!=j) {
        Ball na = balls.get(j);
        ba.applyCollision(na);
      }
    }
    ba.checkEdges();   

    ba.display();
  }

  for (int i = balls.size()-1; i >= 0; i--) {
    Ball b = balls.get(i);
    if (b.isDead) {
      balls.remove(i);
    }
  }
  fill(255);
  text(balls.size(), 40, 130);

  //distance == pixel per frame 

  accX = mouseX-pmouseX;
  accY = mouseY-pmouseY;
  textSize(25);
  text(accX, 30, 50);
  text(accY, 30, 50+40);
}

class Ball {
  PVector pos;
  PVector vel;
  PVector acc;
  PVector posc;
  float mass;
  float size;
  boolean isDead;
  boolean lala;
  Ball( float x, float y, float siz,float m) {
    pos = new PVector(x, y);
    vel = new PVector(random(-3, 3), random(-3, 3));
    acc = new PVector();
    mass = m;
    size = siz;
    isDead = false;
  }

  void update() {
    vel.add(acc);
    pos.add(vel);
    acc.mult(0);
  }

  void applyForce(PVector f) {
    PVector force = PVector.div(f, mass);
    acc.add(force);
  }

  void applyCollision(Ball other) {
    float distance = pos.dist(other.pos);
    if (distance<size/2+other.size/2) {
      PVector force = PVector.sub(other.pos, pos);
      force.mult(-1);
      force.mult(0.1);
      applyForce(force);

      PVector force1 = PVector.sub(other.pos, pos);
      force1.mult(-1);
      force1.mult(0.1);
      applyForce(force);
    }
  }

  void checkEdges() {
    if (pos.x<0 || pos.x >width) {
      isDead = true;
    }
    if (pos.y < size/2) {
      vel.y = -vel.y;
    } else if (pos.y > height-size/2) {
      vel.y = -vel.y;
    }
  }

  void rightwind() {
    PVector wind = new PVector(10, 0);
    applyForce(wind);

    PVector gravity = new PVector(0, 0.1*mass);
    applyForce(gravity);
  }

  void leftwind() {
    //println("wind");
    PVector wind = new PVector(-10, 0);
    applyForce(wind);

    PVector gravity = new PVector(0, 0.1*mass);
    applyForce(gravity);
  }


  void checkStates() {
    float dis = dist(pos.x, pos.y, mouseX, mouseY);
    accX = mouseX-pmouseX;
    accY = mouseY-pmouseY;
    if (dis<size/2) {
      state = 4;
      if (mousePressed) {
        state = 1;
      }
    } else if (accX<-20) {
      //swipeleft
      state = 2;
    } else if (accX>20) {
      //swiperight
      state = 3;
    } else {
      state = 0;
    }
  }

  void display() {
    pushStyle();
    pushMatrix();
    noStroke();
    fill(255, 0, 0);
    ellipse(pos.x, pos.y, size, size);
    switch(state) {
    case 4:
      noStroke();
      fill(255, 0, 0);
      ellipse(pos.x, pos.y, size*1.3, size*1.3);

      break;
    }
    popMatrix();
    popStyle();
  }
}

Kinetic Interfaces : Week 3 Buttons (Amy)

I wanted to replicate one of my childhood games called Simon, which is a memory game where you have to press a certain button. The game works as is: The game will light up one random number out of the four possible buttons. If the user pushes the correct number, they will go to the […]

import processing.sound.*;
SoundFile sound;

ArrayList<Button> buttons = new ArrayList<Button>();

Button[] patterns = new Button[10];
int currPosInPattern = 0;
int currLength = 0;

int button_h;
int button_w;
int clr;
int x, y;

boolean simonTurn = true;
boolean correct = true;

void setup(){
  size(600, 600);
  frameRate(10);
  button_h = height / 2 - 10;
  button_w = width / 2 - 10;
  
  x = 10;
  y = 10;
  
  //button locations
  for (int i = 1; i <= 4; i++){
    clr = color(random(150,255), random(150, 255), random(150, 255));
    sound  = new SoundFile(this, "a" + str(i) + ".wav");
    buttons.add(new Button(x, y, button_w, button_h, clr, sound));
    if (x >= width - (button_w) - 10){
      y += button_h;
      x = 10;
    } else x += button_w;
  }
  
  this.createPattern();
}

void draw(){
  background(100);
  for (Button b : buttons){
    b.checkState();
    b.display();
  }
  
  if (simonTurn) this.performPattern();
}

void performPattern(){
  patterns[currPosInPattern].state = "PRESSED";
  patterns[currPosInPattern].display();
  /*patterns[currPosInPattern].state = "NOT_PRESSED";
  print(patterns[currPosInPattern].state);*/

  if (currPosInPattern < currLength){
    currPosInPattern++;
  } else{
    simonTurn = false;
    currPosInPattern = 0;
  }
}

void mousePressed(){
  if (!simonTurn){
    for (Button b: buttons){
      b.checkState();
      if (b.state == "PRESSED"){
        b.display();
        if (patterns[currPosInPattern] != b)
          correct = false;
      }
    }
  }
}

void mouseReleased(){
  if (!simonTurn){
    for (Button b : buttons){
      b.checkState();
      if (b.state == "RELEASED")
        b.display();
    }
  
    if (!correct){
      this.createPattern();
      currPosInPattern = 0;
      simonTurn = true;
      correct = true;
    } 
    else {
      if (currPosInPattern < currLength){
        currPosInPattern++;
      } else{
        if (currLength == patterns.length - 1){
          this.createPattern();
        }
        else {
          currLength += 1;
          currPosInPattern = 0;
        }
        simonTurn = true;
      }
      /*if (currLength == patterns.length - 1){
        this.createPattern();
      } else {
        currLength++;
        currPosInPattern = 0;
      }
      simonTurn = true;*/
    } 
  }
}

void createPattern(){
  int random_n;
  for (int i = 0; i < patterns.length; i++){
    random_n = int(random(0, 4));
    patterns[i] = buttons.get(random_n);
  }
  currPosInPattern = 0;
  currLength = 0;
}



//Button Class
class Button{
  float w_l, h_l;
  float xPos, yPos;
  color clr;
  String state = "NOT_PRESSED"; 
  SoundFile sound;
  boolean prevPress = false;
  
  Button(float x, float y, float w, float h, int c, SoundFile s){
    xPos = x;
    yPos = y;
    w_l = w;
    h_l = h;
    clr = c;
    
    state = "NOT_PRESSED";
    
    sound = s;
  }
  
  void checkState(){
    boolean currPress = false;
    if (mouseX > xPos && mouseX < xPos + w_l && mouseY > yPos && mouseY < yPos + h_l){
      state = "HOVER";
      if (mousePressed){
        currPress = true;
        state = "PRESSED";
      } else if (prevPress){
        state = "RELEASED";
      }
    } else{
      state = "NOT_PRESSED";
    }
    prevPress = currPress;
  }

  void display(){
    pushStyle();
    noStroke();
    switch(state){
      case "NOT_PRESSED": 
        fill(clr);
        break;
      case "PRESSED":
        sound.play();
        fill(255);
        break;
      case "HOVER":
        fill(clr, 200);
        break;
      case "RELEASED":
        fill(clr);
        break;
    }
    rect(xPos, yPos, w_l, h_l);
    popStyle();
  }
}

Kinetic Interfaces | Week 03 Button States HW (Kate)

I started by making buttons that made the shapes of the buttons appear. I decided to make the shapes fall and make a noise when they hit a specific spot on the screen and draw a line to show where it hit. I decided not to make it the bottom so you can see where […]

import processing.sound.*;

SoundFile C1,D,Eb,F,G,Ab,Bb,C2;
SoundFile D2,E,F2,G2,A,B,C3;
SoundFile CS1,DS,E3,FS,GS,A3,C4,CS2;
FloatList trail;
ArrayList<Shapes> shapePt = new ArrayList<Shapes>();
float mX,mY,a,b,c,pX,pY;
int s,d,d2;
color clr1,clr2,clr3;
boolean randomizer;
void setup(){
  noCursor();
  size(800,800);
  ellipseMode(CENTER);  
  rectMode(CENTER);
  C1 = new SoundFile(this,"square/c.wav");
  D = new SoundFile(this,"square/d.wav");
  Eb = new SoundFile(this,"square/ds.wav");
  F = new SoundFile(this,"square/f.wav");
  G = new SoundFile(this,"square/g.wav");
  Ab = new SoundFile(this,"square/ab.wav");
  Bb = new SoundFile(this,"square/bb.wav");
  C2 = new SoundFile(this,"square/c2.wav");
  D2 = new SoundFile(this,"circle/c.wav");
  E = new SoundFile(this,"circle/e.wav");
  F2 = new SoundFile(this,"circle/f.wav");
  G2 = new SoundFile(this,"circle/g.wav");
  A = new SoundFile(this,"circle/a.wav");
  B = new SoundFile(this,"circle/b.wav");
  C3 = new SoundFile(this,"circle/c5.wav");
  CS1 = new SoundFile(this,"triangle/cs.wav");
  DS = new SoundFile(this,"triangle/ds.wav");
  E3 = new SoundFile(this,"triangle/e.wav");
  FS = new SoundFile(this,"triangle/fs.wav");
  GS = new SoundFile(this,"triangle/ab.wav");
  A3 = new SoundFile(this,"triangle/a.wav");
  C4 = new SoundFile(this,"triangle/c6.wav");
  CS2 = new SoundFile(this,"triangle/cs2.wav");
  a = 50;
  b = 50;
  c = 50;
  s = 2;
  d = 20;
  d2 = 10;
  trail = new FloatList();
  randomizer = false;
}
void draw(){
  mX = mouseX;
  mY = mouseY;
  pX = pmouseX;
  pY = pmouseY;
  background(0);
  fill(208,237,240,a);
  ellipse(width/2,100,50,50);
  fill(250,236,148,b);
  rect(width/4,100,50,50);
  fill(252,166,151,c);
  triangle(3*width/4,75,3*width/4-25,125,3*width/4+25,125);
  fill(202,17,17);
  rect(width/2,20,width,40);
  switch(s){
    case 1:
      fill(250,236,148);
      rect(mX,mY,20,20);
      b = 255;
      a = 50;
      c = 50;
      
      break;
    case 2:
      fill(208,237,240);
      ellipse(mX,mY,20,20);
      a = 255;
      b = 50;
      c = 50;
      break;
    case 3:
      fill(252,166,151);
      triangle(mX,mY,mX-10,mY+20,mX+10,mY+20);
      c = 255;
      a = 50;
      b = 50;
      break;
  }
  for(int i = 0;i<shapePt.size();i++){
    shapePt.get(i).selector();
    shapePt.get(i).fall();
    if(shapePt.get(i).check()==true){
      switch(s){
        case 1:
          //C,D,Eb,F,G,Ab,Bb,C
          stroke(250,236,148,b);
          break;
        case 2:
          stroke(208,237,240,a);          
          break;
        case 3:
          //C#,D#,E,F#,G#,A,C,C#
          stroke(252,166,151,c);    
          break;
      }
      line(0,700,width,700);
      noStroke();
    }
  }
  
  if(trail.size()>2){
    for(int i=2;i<trail.size();i+=2){
      switch(s){
        case 1:
          fill(250,236,148);
          rect(trail.get(i),trail.get(i+1),d,d);
          b = 255;
          a = 50;
          c = 50;
        break;
        case 2:
          fill(208,237,240);
          ellipse(trail.get(i),trail.get(i+1),d,d);
          a = 255;
          b = 50;
          c = 50;
        break;
        case 3:
          fill(252,166,151);
          triangle(trail.get(i),trail.get(i+1),trail.get(i)-d2,trail.get(i+1)+d,trail.get(i)+d2,trail.get(i+1)+d);
          c = 255;
          a = 50;
          b = 50;
        break;
        }
      }
      trail.remove(0);
      trail.remove(0);
  }
  if(randomizer == true){
    shapePt.add(new Shapes(int(random(1,4)),random(width),random(height)));
  }
  println(randomizer);
}
void mousePressed(){
  if(abs(dist(mX,mY,width/2,100))<50){
    a = 255;
    b = 50;
    c = 50;
    s = 2;
  }else if(abs(mX-(width/4))<25 && abs(mY-100)<25){
    b = 255;
    a = 50;
    c = 50;
    s = 1;
  }else if(abs(dist(mX,mY,3*width/4,100))<20){
    c = 255;
    a = 50;
    b = 50;
    s = 3;
  }else if(mX>0 && mX<width && mY<40){
    randomizer = !randomizer;
  }
}
void keyPressed(){
  if(keyCode == LEFT){
    s--;
    if(s<=0){
      s = 3;
    }
  }else if(keyCode == RIGHT){
    s++;
    if(s>3){
      s = 1;
    }
  }
  else if(s != 0 && key == ' '){
    shapePt.add(new Shapes(s,mX,mY));
  }
}
void mouseMoved(){
  if(d<0){
    d = 20;
  }
  d--;
  if(d2<0){
    d2 = 10;
  }
  d2--;
  trail.append(pX);
  trail.append(pY);
  if(trail.size()>10){
    trail.remove(0);
    trail.remove(0);
  }
}
class Shapes{
  float xP,yP,r,o;
  int s;
  color clr;
  float offset;
  boolean done;
  IntList cir,squ,tri;
  Shapes(int c,float x, float y){
    done = false;
    s = c;
    //xP = random(100,width-100);
    //yP = random(200,height-100);
    xP = x;
    yP = y;
    r = random(2*PI);
    o = 255;
  }
  void selector(){
    o = map(yP,0,width,255,0);
    switch(s){
      case 2:
        fill(208,237,240,o);
        ellipse(xP,yP,20,20);
        if(done == true){
          if(xP<100){
            C1.play();
          }else if(xP<200){
            D.play();
          }else if(xP<300){
            Eb.play();
          }else if(xP<400){
            F.play();
          }else if(xP<500){
            G.play();
          }else if(xP<600){
            Ab.play();
          }else if(xP<700){
            Bb.play();
          }else{
            C2.play();
          }
    }
        break;
      case 1:
       pushMatrix();
        translate(xP,yP);
        rotate(r);
        translate(-xP,-yP);
        fill(250,236,148,o);
        rect(xP,yP,20,20);
        popMatrix();
        if(done == true){
        if(xP<100){
            C2.play();
          }else if(xP<200){
            D2.play();
          }else if(xP<300){
            E.play();
          }else if(xP<400){
            F2.play();
          }else if(xP<500){
            G2.play();
          }else if(xP<600){
            A.play();
          }else if(xP<700){
            B.play();
          }else{
            C3.play();
          }
        }
        break;
        
      case 3:
        pushMatrix();
        translate(xP,yP);
        rotate(r);
        translate(-xP,-yP);
        fill(252,166,151,o);
        triangle(xP,yP,xP-10,yP+20,xP+10,yP+20);
        popMatrix();
        if(done == true){
        if(xP<100){
            CS1.play();
          }else if(xP<200){
            DS.play();
          }else if(xP<300){
            E3.play();
          }else if(xP<400){
            FS.play();
          }else if(xP<500){
            GS.play();
          }else if(xP<600){
            A3.play();
          }else if(xP<700){
            C4.play();
          }else{
            CS2.play();
          }
        }
        break;
    }
  }
  void fall(){
    yP += 5;
    r += 0.02;
    pushMatrix();
    translate(xP,yP);
    rotate(r);
    translate(-xP,-yP);
    popMatrix();
  }
  boolean check(){
    if(yP > 700 && yP<706){
      done = true;
    }else{
      done = false;
    }
    return done;
  }
}