class Bead {
//variables of beads
float x,y;
float theta;
float speed;
float fi;
PImage myImage;
//constructor connected to new bead pole()
Bead (float tempX, float tempY, String iName, float tempSpeed) {
x= tempX;
y= tempY;
myImage = loadImage(iName);
theta= PI*mouseX/ width;
speed= tempSpeed;
}
void spin() {
theta= theta+0.1;
}
void display() {
image(myImage,x,y);
if (mousePressed) {
pushMatrix();
theta= theta+ 0.1;
fi= (theta);
translate(x,y);
rotate(theta);
//imageMode (CENTER);
image(myImage,0,0);
popMatrix();
}
}
//set my location to the mouse
void setLocation (int tempX, int tempY) {
//x = tempX;
y = tempY;
y = constrain(mouseY,30,height-30);
}
//if the mouse is not over return false
//if the mouse is over return true
boolean drag () {
boolean dragging = false;
float d = dist(mouseX,mouseY,x,y);
if (d < 30) {
dragging = true;
}
return dragging;
}
void checkMouse () {
//print("checking mouse");
//check to see if mouse is in the circle;
float d = dist(mouseX,mouseY,x,y);
println(d);
if (d < 30) {
println("hey");
y = constrain(mouseY,30,height-30);
}
}
}
//Assignment 1
// Ashley Shepherd (z3269417)
PImage bead;
float r;
float g;
float b;
Bead [] string = new Bead [24];
boolean dragging = false;
Bead dragBead;
void setup() {
size(350,520);
smooth();
string[0]= new Bead (50,43, "beadaqua.png",0.1);
string[1]= new Bead (50,130, "beadwhite.png",0.1);
string[2]= new Bead (50,190, "beadorange.png",0.1);
string[3]= new Bead (50,340, "beadgreen.png",0.1);
string[4]= new Bead (50,400, "beadspot.png",0.1);
string[5]= new Bead (50,460, "beadindigo.png",0.1); //end of pole one
string[6]= new Bead (130,43, "beadgreen.png",0.2);
string[7]= new Bead (130,220, "beadspot.png",0.2);
string[8]= new Bead (130,280, "beadorange.png",0.2);
string[9]= new Bead (130, 340, "beadindigo.png", 0.2);
string[10]= new Bead (130, 400,"beadwhite.png",0.2);
string[11]= new Bead (130,460,"beadaqua.png",0.2); // end of pole tw
string[12]= new Bead (210,43, "beadorange.png",0.2);
string[13]= new Bead (210,235, "beadindigo.png",0.2);
string[14]= new Bead (210, 340, "beadaqua.png",0.2);
string[15]= new Bead (210,400, "beadgreen.png",0.2);
string[16]= new Bead (210, 460, "beadwhite.png",0.2);
string[17]= new Bead (210,175, "beadspot.png",0.2);//end of pole three
string[18]= new Bead (290,43, "beadspot.png",0.2);
string[19]= new Bead (290, 235, "beadgreen.png",0.2);
string[20]= new Bead (290, 340, "beadwhite.png",0.2);
string[21]= new Bead (290, 400, "beadindigo.png",0.2);
string[22]= new Bead (290, 460, "beadaqua.png",0.2);
string[23]= new Bead (290, 174, "beadorange.png",0.2);// end of pole four
imageMode (CENTER);
loop();
}
void draw() {
background (199,214,227);
smooth();
ellipse(50,2,15,5);
ellipse(130,2,15,5);
ellipse(210,2,15,5);
ellipse(290,2,15,5);
ellipse(50,95,10,5);
ellipse(130,95,10,5);
ellipse (210,95,10,5);
ellipse (290,95,10,5);
fill (0,60,110);
line (50,0,50,520);
line(130,0,130,520);
line(210,0,210,520);
line(290,0,290,520);
line(0,95,400,95);
strokeWeight (1);
stroke(color(10,60,110));
if (dragBead != null) {
dragBead.setLocation(mouseX,mouseY);
}
for (int i=0; i<string.length;i++) {
string[i].display();
}
}
void mouseDragged() {
r= random (255);
g= random (255);
b= random (255);
if (keyPressed);
fill(r,g,b);
ellipseMode (CENTER);
ellipse (mouseX, mouseY, 20,20);
}
void mousePressed () {
//when we press the mouse loop through the ball
//array
for (int i=0; i<string.length;i++) {
//if the drag function for the ball we are
//currently checking returns true
if (string[i].drag()) {
//if we aren't already dragging something
//so dragging is false
if (!dragging) {
//then making dragging true
//as we are dragging, so we will stop checking
//the other balls (a bit flawed as it will just
//start dragging the first ball in the array
//that returns true
dragging = true;
//and store a reference to the ball we are
//currently dragging inside dragBall
dragBead = string[i];
}
}
}
}
void mouseReleased () {
//when we release the mouse
//set dragging to fall
//and remove the reference to the ball being
//currently dragged in dragBall by setting it
//to null again
dragging = false;
dragBead = null;
}
This traditional Abacus has a new Spin. All bead's have been personally designed by me and they Spin when you hold down the mouse!!
The bead's can be moved up and down the pole's for new patterns to be created.