day1 sketch

This commit is contained in:
gauthiier 2015-03-03 14:04:38 +01:00
parent c1f2e00c38
commit 31dfd2ab1d
6 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,54 @@
class Cup extends Thing {
int _temperature;
boolean _empty;
public Cup(int x, int y, int w, int h) {
super(x, y, w, h);
}
public void filled() {
_empty = false;
}
public void drink() {
_empty = true;
}
public void display() {
super.display();
if(_empty) {
fill(255);
} else {
fill(0,0,255);
}
ellipse(_position.x, _position.y, _width, _height);
}
public void mousePressed(int mx, int my) {
float d = dist( _position.x, _position.y, mx, my);
println("mouse");
if(d < _width) {
println("touched!");
if(_empty) {
filled();
} else {
drink();
}
}
}
};

View File

@ -0,0 +1,15 @@
class Desk extends Surface {
int nbr_legs;
public void display() {
fill(0,255,0);
rect(20, 20, 20 + _width, 20 + _height);
super.display();
}
};

View File

@ -0,0 +1,31 @@
class Surface {
ArrayList<Thing> array = new ArrayList<Thing>();
int _width;
int _height;
public void addItem(Thing item) {
array.add(item);
}
public void display() {
for(int i = 0; i < array.size(); i++) {
Thing t = array.get(i);
t.display();
}
}
public void mousePressed(int mx, int my) {
for(int i = 0; i < array.size(); i++) {
Thing t = array.get(i);
t.mousePressed(mx, my);
}
}
};

View File

@ -0,0 +1,27 @@
class Thing {
PVector _position;
int _weight;
color _color;
int _width;
int _height;
public Thing(int x, int y, int w, int h) {
_position = new PVector();
_position.x = x;
_position.y = y;
_width = w;
_height = h;
}
public void move(int x, int y) {
_position.x = x;
_position.y = y;
}
public void display() {}
public void mousePressed(int mx, int my) {}
};

View File

@ -0,0 +1,2 @@
mode.id=processing.mode.java.JavaMode
mode=Java

View File

@ -0,0 +1,44 @@
Desk desk = new Desk();
int NBR_CUPS = 5;
void setup() {
size(500, 500);
desk._width = 450;
desk._height = 450;
for(int i = 0; i < NBR_CUPS; i++) {
Cup c = new Cup(i * 100, i * 100, 20, 20);
desk.addItem(c);
}
}
void draw() {
desk.display();
}
void mousePressed() {
desk.mousePressed(mouseX, mouseY);
}