Permalink
Browse files

Added ability to fade positions

  • Loading branch information...
1 parent 2f91d12 commit a3c8bc44928ac8bd9b28bdb0b89e760726bc7798 @bxt committed Apr 23, 2012
@@ -10,26 +10,77 @@
protected int[] edges;
protected int[] roundtrip;
- public Icosahedron(float size) {
+ public Icosahedron(float size, PositionSwitch positionSwitch) {
float phi = (float) (1.0+Math.sqrt(5)) / 2.0f;
float sizeBig = size * phi;
+ float sizeSqrt = size * (float) Math.sqrt(phi);
+
+ //float[] vertexData = new float[]{};
vertices = new Vertex[]{
- new Vertex("00",new PVector( sizeBig, 0, size)),
- new Vertex("01",new PVector(-sizeBig, 0, size)),
- new Vertex("02",new PVector(-sizeBig, 0,-size)),
- new Vertex("03",new PVector( sizeBig, 0,-size)),
+ new Vertex("00",new PVector[]{
+ new PVector( sizeBig, 0, size),
+ new PVector( 0, 0, size),
+ new PVector( sizeSqrt, 0, sizeSqrt),
+ },positionSwitch),
+ new Vertex("01",new PVector[]{
+ new PVector(-sizeBig, 0, size),
+ new PVector(-size/2, 0, size*3),
+ new PVector(-sizeSqrt, 0, sizeSqrt),
+ },positionSwitch),
+ new Vertex("02",new PVector[]{
+ new PVector(-sizeBig, 0,-size),
+ new PVector(-size/2, 0,-size*3),
+ new PVector(-sizeSqrt, 0,-sizeSqrt),
+ },positionSwitch),
+ new Vertex("03",new PVector[]{
+ new PVector( sizeBig, 0,-size),
+ new PVector( 0, 0,-size),
+ new PVector( sizeSqrt, 0,-sizeSqrt),
+ },positionSwitch),
- new Vertex("04",new PVector( size, sizeBig, 0)),
- new Vertex("05",new PVector( size,-sizeBig, 0)),
- new Vertex("06",new PVector(-size,-sizeBig, 0)),
- new Vertex("07",new PVector(-size, sizeBig, 0)),
+ new Vertex("04",new PVector[]{
+ new PVector( size, sizeBig, 0),
+ new PVector( 0, size, 0),
+ new PVector( sizeSqrt, sizeSqrt, 0),
+ },positionSwitch),
+ new Vertex("05",new PVector[]{
+ new PVector( size,-sizeBig, 0),
+ new PVector( 0,-size, 0),
+ new PVector( sizeSqrt,-sizeSqrt, 0),
+ },positionSwitch),
+ new Vertex("06",new PVector[]{
+ new PVector(-size,-sizeBig, 0),
+ new PVector(-size/2,-sizeBig-size, 0),
+ new PVector(-sizeSqrt,-sizeSqrt, 0),
+ },positionSwitch),
+ new Vertex("07",new PVector[]{
+ new PVector(-size, sizeBig, 0),
+ new PVector(-size/2, sizeBig+size, 0),
+ new PVector(-sizeSqrt, sizeSqrt, 0),
+ },positionSwitch),
- new Vertex("08",new PVector( 0, size, sizeBig)),
- new Vertex("09",new PVector( 0, size,-sizeBig)),
- new Vertex("10",new PVector( 0,-size,-sizeBig)),
- new Vertex("11",new PVector( 0,-size, sizeBig)),
+ new Vertex("08",new PVector[]{
+ new PVector( 0, size, sizeBig),
+ new PVector(-size/4, size, size),
+ new PVector( 0, sizeSqrt, sizeSqrt),
+ },positionSwitch),
+ new Vertex("09",new PVector[]{
+ new PVector( 0, size,-sizeBig),
+ new PVector(-size/4, size,-size),
+ new PVector( 0, sizeSqrt,-sizeSqrt),
+ },positionSwitch),
+ new Vertex("10",new PVector[]{
+ new PVector( 0,-size,-sizeBig),
+ new PVector(-size/4,-size,-size),
+ new PVector( 0,-sizeSqrt,-sizeSqrt),
+ },positionSwitch),
+ new Vertex("11",new PVector[]{
+ new PVector( 0,-size, sizeBig),
+ new PVector(-size/4,-size, size),
+ new PVector( 0,-sizeSqrt, sizeSqrt),
+ },positionSwitch),
};
// zeile: vertex, spalten 0,1 und 2,3, von/nach vtxs
@@ -0,0 +1,43 @@
+package bxt.icosahedron.geometry;
+
+import processing.core.PVector;
+
+public class PositionSwitch {
+
+ private int position = 0;
+ private float fade = 1.0f;
+
+ public PVector getPosition(PVector[] positions) {
+ if(fade < 1.0f) {
+
+ PVector old = positions[(position+positions.length-1) % positions.length];
+ PVector nev = positions[ position % positions.length];
+
+ PVector returnValue = PVector.sub(nev, old);
+ returnValue.mult(fade);
+ returnValue.add(old);
+ return returnValue;
+
+ } else {
+ return positions[ position % positions.length];
+ }
+ }
+
+ public void nextPosition() {
+ if(!(fade < 1.0f)) {
+ position++;
+ fade = 0.0f;
+ } else {
+ System.out.println("ig!");
+ }
+ }
+
+ public void step() {
+ if(fade < 1.0f) {
+ fade += 0.05;
+ }
+ if(!(fade < 1.0f)) {
+ fade = 1.0f;
+ }
+ }
+}
@@ -5,17 +5,20 @@
public class Vertex {
private String name;
- private PVector position;
+ private PVector[] positions;
+ private PositionSwitch positionSwitch;
- public Vertex(String name, PVector position) {
+ public Vertex(String name, PVector[] positions, PositionSwitch positionSwitch) {
this.name = name;
- this.position = position;
+ this.positions = positions;
+ this.positionSwitch = positionSwitch;
}
public String getName() {
return name;
}
public PVector getPosition() {
- return position;
+ return positionSwitch.getPosition(positions);
}
+
}
@@ -2,6 +2,7 @@
import bxt.icosahedron.geometry.Icosahedron;
+import bxt.icosahedron.geometry.PositionSwitch;
import bxt.icosahedron.geometry.Vertex;
import processing.core.PApplet;
import processing.core.PVector;
@@ -19,8 +20,10 @@
private PApplet p;
- public IcosahedronRenderer(float size, PApplet p) {
- super(size);
+ public IcosahedronRenderer(float size,
+ PositionSwitch positionSwitch, PApplet p) {
+
+ super(size, positionSwitch);
this.p = p;
C_VERTEX_X = p.color(255, 0, 0, 170);
@@ -1,4 +1,5 @@
package bxt.icosahedron.processing;
+import bxt.icosahedron.geometry.PositionSwitch;
import processing.core.PApplet;
import processing.core.PFont;
@@ -11,6 +12,8 @@
private Drawable[] drawables;
+ PositionSwitch positionSwitch;
+
public static void main(String args[]) {
PApplet.main(new String[]{
"--present",IcosahedronSketch.class.getCanonicalName()});
@@ -24,8 +27,10 @@ public void setup() {
font = loadFont("BitstreamVeraSans-Roman-48.vlw");
textFont(font);
+ positionSwitch = new PositionSwitch();
+
drawables = new Drawable[]{
- new IcosahedronRenderer(100, this),
+ new IcosahedronRenderer(100, positionSwitch, this),
new RotationCamera(this),
new FpsPrinter(this),
};
@@ -36,9 +41,18 @@ public void draw() {
background(10);
lights();
+ positionSwitch.step();
+
for (Drawable drawable : drawables) {
drawable.draw();
}
}
+
+ public void mouseClicked() {
+ if(mouseButton == LEFT) {
+ positionSwitch.nextPosition();
+ }
+ }
+
}

0 comments on commit a3c8bc4

Please sign in to comment.