day1 sketch
This commit is contained in:
parent
c1f2e00c38
commit
31dfd2ab1d
54
day1/sketch_things_and_surfaces/Cup.pde
Normal file
54
day1/sketch_things_and_surfaces/Cup.pde
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
15
day1/sketch_things_and_surfaces/Desk.pde
Normal file
15
day1/sketch_things_and_surfaces/Desk.pde
Normal 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();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
31
day1/sketch_things_and_surfaces/Surface.pde
Normal file
31
day1/sketch_things_and_surfaces/Surface.pde
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
27
day1/sketch_things_and_surfaces/Thing.pde
Normal file
27
day1/sketch_things_and_surfaces/Thing.pde
Normal 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) {}
|
||||
|
||||
};
|
||||
|
||||
2
day1/sketch_things_and_surfaces/sketch.properties
Normal file
2
day1/sketch_things_and_surfaces/sketch.properties
Normal file
@ -0,0 +1,2 @@
|
||||
mode.id=processing.mode.java.JavaMode
|
||||
mode=Java
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user