From 31dfd2ab1d0519bd6e1c046b90cdaa9d8d19fedc Mon Sep 17 00:00:00 2001 From: gauthiier Date: Tue, 3 Mar 2015 14:04:38 +0100 Subject: [PATCH] day1 sketch --- day1/sketch_things_and_surfaces/Cup.pde | 54 +++++++++++++++++++ day1/sketch_things_and_surfaces/Desk.pde | 15 ++++++ day1/sketch_things_and_surfaces/Surface.pde | 31 +++++++++++ day1/sketch_things_and_surfaces/Thing.pde | 27 ++++++++++ .../sketch.properties | 2 + .../sketch_things_and_surfaces.pde | 44 +++++++++++++++ 6 files changed, 173 insertions(+) create mode 100644 day1/sketch_things_and_surfaces/Cup.pde create mode 100644 day1/sketch_things_and_surfaces/Desk.pde create mode 100644 day1/sketch_things_and_surfaces/Surface.pde create mode 100644 day1/sketch_things_and_surfaces/Thing.pde create mode 100644 day1/sketch_things_and_surfaces/sketch.properties create mode 100644 day1/sketch_things_and_surfaces/sketch_things_and_surfaces.pde diff --git a/day1/sketch_things_and_surfaces/Cup.pde b/day1/sketch_things_and_surfaces/Cup.pde new file mode 100644 index 0000000..11334d6 --- /dev/null +++ b/day1/sketch_things_and_surfaces/Cup.pde @@ -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(); + } + + + } + + } + +}; + diff --git a/day1/sketch_things_and_surfaces/Desk.pde b/day1/sketch_things_and_surfaces/Desk.pde new file mode 100644 index 0000000..a046eec --- /dev/null +++ b/day1/sketch_things_and_surfaces/Desk.pde @@ -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(); + } + +}; + diff --git a/day1/sketch_things_and_surfaces/Surface.pde b/day1/sketch_things_and_surfaces/Surface.pde new file mode 100644 index 0000000..d973add --- /dev/null +++ b/day1/sketch_things_and_surfaces/Surface.pde @@ -0,0 +1,31 @@ +class Surface { + + ArrayList array = new ArrayList(); + + 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); + } + + } + +}; + diff --git a/day1/sketch_things_and_surfaces/Thing.pde b/day1/sketch_things_and_surfaces/Thing.pde new file mode 100644 index 0000000..30f793e --- /dev/null +++ b/day1/sketch_things_and_surfaces/Thing.pde @@ -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) {} + +}; + diff --git a/day1/sketch_things_and_surfaces/sketch.properties b/day1/sketch_things_and_surfaces/sketch.properties new file mode 100644 index 0000000..8630fa2 --- /dev/null +++ b/day1/sketch_things_and_surfaces/sketch.properties @@ -0,0 +1,2 @@ +mode.id=processing.mode.java.JavaMode +mode=Java diff --git a/day1/sketch_things_and_surfaces/sketch_things_and_surfaces.pde b/day1/sketch_things_and_surfaces/sketch_things_and_surfaces.pde new file mode 100644 index 0000000..4d3e69e --- /dev/null +++ b/day1/sketch_things_and_surfaces/sketch_things_and_surfaces.pde @@ -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); + +} + + + + + + + + + + +