class Ball {
// attributes
color c;
float xpos;
float ypos;
float xspeed;
float yspeed;
float mysize;
// constructor
Ball() {
c = (255);
xpos = (mouseX);
ypos = (mouseY);
xspeed =random(-4,4);
yspeed = random(-4,4);
mysize = random(10,30);
}
// methods (behavior)
void move() {
if (xpos+(mysize/2) > 500 ){
xspeed = xspeed * (-1);
chime1.loop(0);
}
if (xpos-(mysize/2) < 0 ) {
xspeed = xspeed * (-1);
chime2.loop(0);
}
if (ypos+(mysize/2) > 500){
yspeed = yspeed * (-1);
chime3.loop(0);
}
if (ypos-(mysize/2) < 0) {
yspeed = yspeed * (-1);
chime4.loop(0);
}
xpos += xspeed;
ypos += yspeed;
}
void display() {
fill(c);
ellipse(xpos, ypos, mysize, mysize);
}
}
class Rectangle {
float x, y, w = 20, h = 200;
float rotation = 0;
Rectangle(float x, float y) {
moveTo(x, y);
}
void moveTo(float x, float y) {
this.x = x;
this.y = y;
}
void rotateTo(float rotation) {
this.rotation = rotation;
}
void draw() {
pushMatrix();
translate(x + w / 2, y + h / 2);
rotate(rotation);
fill(100);
rect(-w / 2, -h / 2, w, h); //(0,0)
popMatrix();
}
}
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
// bouncing balls
ArrayList<Ball> ball= new ArrayList<Ball>();
Rectangle rectangle;
ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>();
Minim m;
AudioPlayer chime1;
AudioPlayer chime2;
AudioPlayer chime3;
AudioPlayer chime4;
void setup() {
size(500,500);
noStroke();
smooth();
m= new Minim (this);
chime1 = m.loadFile ("C.mp3");
chime2 = m.loadFile ("E.mp3");
chime3 = m.loadFile ("G.mp3");
chime4 = m.loadFile ("B.mp3");
float angle = atan2 (mouseY+1, mouseX+1);
// if (mousePressed==true){
// if(mouseButton == RIGHT){
//
// }else{
// fill(100);
// rect(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
// }
//
// }else{
// fill(100);
// rect(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
// }
}
void draw() {
background(0);
fill(100);
// rect(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
for (Rectangle rectangle : rectangles) {
rectangle.draw();
}
for (int i = 0; i < ball.size(); i++) {
ball.get(i).move();
ball.get(i).display();
}
// float angle = atan2 (mouseY+1, mouseX+1);
// if (mousePressed==true){
// if(mouseButton == RIGHT){
//
//
// pushMatrix();
// translate(rectangleX+rectangleWidth/2, rectangleY+rectangleHeight/2);
// rotate(angle);
// fill(100);
// rect(-rectangleWidth/2, -rectangleHeight/2, rectangleWidth, rectangleHeight); //(0,0)
// popMatrix();
//
// }else{
// fill(100);
// rect(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
// }
//
// }else{
// fill(100);
// rect(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
// }
}
void mouseClicked() {
if (mouseButton == LEFT) {
ball.add(new Ball());
} else if (mouseButton == RIGHT) {
rectangles.add(rectangle = new Rectangle(mouseX, mouseY));
}
}
//trying to get the chime to move around
void mouseDragged() {
if (rectangle != null) {
if (mouseButton == LEFT) {
rectangle.moveTo(mouseX, mouseY);
} else if (mouseButton == RIGHT) {
rectangle.rotateTo(atan2(mouseY + 1, mouseX + 1));
}
}
}
Left click= creates a chime
Left drag= rotates chime
Right drag = moves chime
Right click= creates balls