diff --git a/day2/sketch_transformable_oscillator/Oscillator.pde b/day2/sketch_transformable_oscillator/Oscillator.pde index d3702d2..b58533e 100644 --- a/day2/sketch_transformable_oscillator/Oscillator.pde +++ b/day2/sketch_transformable_oscillator/Oscillator.pde @@ -1,4 +1,5 @@ class Oscillator { + float _step, _theta; float _min, _max, _length; diff --git a/day3/sketch_creature/CircleCreature.pde b/day3/sketch_creature/CircleCreature.pde new file mode 100644 index 0000000..6e3f141 --- /dev/null +++ b/day3/sketch_creature/CircleCreature.pde @@ -0,0 +1,18 @@ +class CircleCreature extends Creature { + + public CircleCreature(int x, int y, int r) { + super(x, y, r); + ellipseMode(RADIUS); + } + + public void draw_shape(){ + ellipse(0, 0, radius(), radius()); + line(0, 0, radius(), 0); + } + + public boolean inside(int mx, int my) { + if(dist(mx, my, position().x, position().y) < radius()) return true; + return false; + } + +}; diff --git a/day3/sketch_creature/Creature.pde b/day3/sketch_creature/Creature.pde new file mode 100644 index 0000000..7f35285 --- /dev/null +++ b/day3/sketch_creature/Creature.pde @@ -0,0 +1,37 @@ +import teilchen.BehaviorParticle; +import mathematik.Vector3f; + +class Creature extends BehaviorParticle { + + float _scale; + + public Creature(int x, int y, int r) { + super(); + position().set(x, y); + maximumInnerForce(100); + radius(r); + _scale = 1.0; + } + + public void display() { + pushMatrix(); + translate(position().x, position().y); + rotate(getRotation()); + scale(_scale); + draw_shape(); + popMatrix(); + + } + + private float getRotation() { + if(velocity().isNaN() || velocity().magnitude() == 0) return 0; + Vector3f v = new Vector3f(-1, 0, 0); + return velocity().angle(v); + } + + public void draw_shape() {} + + public boolean inside(int mx, int my){return false;} + +}; + diff --git a/day3/sketch_creature/SquareCreature.pde b/day3/sketch_creature/SquareCreature.pde new file mode 100644 index 0000000..c218805 --- /dev/null +++ b/day3/sketch_creature/SquareCreature.pde @@ -0,0 +1,22 @@ +class SquareCreature extends Creature { + + int _width; + int _height; + + public SquareCreature(int x, int y, int w, int h) { + super(x, y, (int)sqrt(pow(w / 2, 2) + pow(h / 2, 2))); + _width = w; + _height = h; + rectMode(CENTER); + } + + public void draw_shape(){ + rect(0, 0, _width, _height); + } + + public boolean inside(int mx, int my) { + if(dist(mx, my, position().x, position().y) < radius()) return true; + return false; + } + +}; diff --git a/day3/sketch_creature/TriangleCreature.pde b/day3/sketch_creature/TriangleCreature.pde new file mode 100644 index 0000000..fc4e50b --- /dev/null +++ b/day3/sketch_creature/TriangleCreature.pde @@ -0,0 +1,36 @@ +class TriangleCreature extends Creature { + + PVector A, B, C; + + public TriangleCreature(int x, int y, int r) { + super(x, y, r); + + A = new PVector(); + B = new PVector(); + C = new PVector(); + + float theta = TWO_PI/3; + + A.x = cos(0 * theta) * r; + A.y = sin(0 * theta) * r; + + B.x = cos(1 * theta) * r; + B.y = sin(1 * theta) * r; + + C.x = cos(2 * theta) * r; + C.y = sin(2 * theta) * r; + + } + + public void draw_shape(){ + triangle(A.x, A.y, B.x, B.y, C.x, C.y); + line(0, 0, A.x, 0); + } + + public boolean inside(int mx, int my) { + if(dist(mx, my, position().x, position().y) < radius()) return true; + return false; + } + + +}; diff --git a/day3/sketch_creature/sketch.properties b/day3/sketch_creature/sketch.properties new file mode 100644 index 0000000..8630fa2 --- /dev/null +++ b/day3/sketch_creature/sketch.properties @@ -0,0 +1,2 @@ +mode.id=processing.mode.java.JavaMode +mode=Java diff --git a/day3/sketch_creature/sketch_creature.pde b/day3/sketch_creature/sketch_creature.pde new file mode 100644 index 0000000..8e2de12 --- /dev/null +++ b/day3/sketch_creature/sketch_creature.pde @@ -0,0 +1,40 @@ +import teilchen.Physics; + +final int CANVAS_WIDTH = 500; +final int CANVAS_HEIGHT = 500; + +Physics physics; + +Creature creature; + +void setup() { + size(CANVAS_WIDTH, CANVAS_HEIGHT); + background(23, 68, 250); + frameRate(30); + + physics = new Physics(); + + creature = new CircleCreature(width / 2, height / 2, 30); + + physics.add(creature); + +} + +void draw() { + + physics.step(1.0 / frameRate); + + background(23, 68, 250); + stroke(255); + noFill(); + + creature.display(); + +} + +void mousePressed() { + + creature.position().set(mouseX, mouseY); + +} + diff --git a/day3/sketch_creature_gravity/CircleCreature.pde b/day3/sketch_creature_gravity/CircleCreature.pde new file mode 100644 index 0000000..6e3f141 --- /dev/null +++ b/day3/sketch_creature_gravity/CircleCreature.pde @@ -0,0 +1,18 @@ +class CircleCreature extends Creature { + + public CircleCreature(int x, int y, int r) { + super(x, y, r); + ellipseMode(RADIUS); + } + + public void draw_shape(){ + ellipse(0, 0, radius(), radius()); + line(0, 0, radius(), 0); + } + + public boolean inside(int mx, int my) { + if(dist(mx, my, position().x, position().y) < radius()) return true; + return false; + } + +}; diff --git a/day3/sketch_creature_gravity/Creature.pde b/day3/sketch_creature_gravity/Creature.pde new file mode 100644 index 0000000..7f35285 --- /dev/null +++ b/day3/sketch_creature_gravity/Creature.pde @@ -0,0 +1,37 @@ +import teilchen.BehaviorParticle; +import mathematik.Vector3f; + +class Creature extends BehaviorParticle { + + float _scale; + + public Creature(int x, int y, int r) { + super(); + position().set(x, y); + maximumInnerForce(100); + radius(r); + _scale = 1.0; + } + + public void display() { + pushMatrix(); + translate(position().x, position().y); + rotate(getRotation()); + scale(_scale); + draw_shape(); + popMatrix(); + + } + + private float getRotation() { + if(velocity().isNaN() || velocity().magnitude() == 0) return 0; + Vector3f v = new Vector3f(-1, 0, 0); + return velocity().angle(v); + } + + public void draw_shape() {} + + public boolean inside(int mx, int my){return false;} + +}; + diff --git a/day3/sketch_creature_gravity/SquareCreature.pde b/day3/sketch_creature_gravity/SquareCreature.pde new file mode 100644 index 0000000..c218805 --- /dev/null +++ b/day3/sketch_creature_gravity/SquareCreature.pde @@ -0,0 +1,22 @@ +class SquareCreature extends Creature { + + int _width; + int _height; + + public SquareCreature(int x, int y, int w, int h) { + super(x, y, (int)sqrt(pow(w / 2, 2) + pow(h / 2, 2))); + _width = w; + _height = h; + rectMode(CENTER); + } + + public void draw_shape(){ + rect(0, 0, _width, _height); + } + + public boolean inside(int mx, int my) { + if(dist(mx, my, position().x, position().y) < radius()) return true; + return false; + } + +}; diff --git a/day3/sketch_creature_gravity/TriangleCreature.pde b/day3/sketch_creature_gravity/TriangleCreature.pde new file mode 100644 index 0000000..fc4e50b --- /dev/null +++ b/day3/sketch_creature_gravity/TriangleCreature.pde @@ -0,0 +1,36 @@ +class TriangleCreature extends Creature { + + PVector A, B, C; + + public TriangleCreature(int x, int y, int r) { + super(x, y, r); + + A = new PVector(); + B = new PVector(); + C = new PVector(); + + float theta = TWO_PI/3; + + A.x = cos(0 * theta) * r; + A.y = sin(0 * theta) * r; + + B.x = cos(1 * theta) * r; + B.y = sin(1 * theta) * r; + + C.x = cos(2 * theta) * r; + C.y = sin(2 * theta) * r; + + } + + public void draw_shape(){ + triangle(A.x, A.y, B.x, B.y, C.x, C.y); + line(0, 0, A.x, 0); + } + + public boolean inside(int mx, int my) { + if(dist(mx, my, position().x, position().y) < radius()) return true; + return false; + } + + +}; diff --git a/day3/sketch_creature_gravity/sketch.properties b/day3/sketch_creature_gravity/sketch.properties new file mode 100644 index 0000000..8630fa2 --- /dev/null +++ b/day3/sketch_creature_gravity/sketch.properties @@ -0,0 +1,2 @@ +mode.id=processing.mode.java.JavaMode +mode=Java diff --git a/day3/sketch_creature_gravity/sketch_creature_gravity.pde b/day3/sketch_creature_gravity/sketch_creature_gravity.pde new file mode 100644 index 0000000..9232892 --- /dev/null +++ b/day3/sketch_creature_gravity/sketch_creature_gravity.pde @@ -0,0 +1,47 @@ +import teilchen.Physics; +import teilchen.force.Gravity; + +final int CANVAS_WIDTH = 500; +final int CANVAS_HEIGHT = 500; + +Physics physics; + +Creature creature; + +void setup() { + size(CANVAS_WIDTH, CANVAS_HEIGHT); + background(23, 68, 250); + frameRate(30); + + physics = new Physics(); + + Gravity mGravity = new Gravity(); + mGravity.force().set(0, 30, 0); + + physics.add(mGravity); + + creature = new TriangleCreature(width / 2, height / 2, 30); + + physics.add(creature); + +} + +void draw() { + + physics.step(1.0 / frameRate); + + background(23, 68, 250); + stroke(255); + noFill(); + + creature.display(); + +} + +void mousePressed() { + + creature.position().set(mouseX, mouseY); + creature.velocity().set(mouseX - pmouseX, mouseY - pmouseY); + +} +