Created
November 9, 2011 02:32
-
-
Save automata/1350146 to your computer and use it in GitHub Desktop.
rem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100, 100, 0.09 | |
20, 20, 0.1 | |
220, 220, 0.1 | |
20, 200, 0.05 | |
20, 20, 0.05 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float beginX = 0.0; // Initial x-coordinate | |
float beginY = 0.0; // Initial y-coordinate | |
float endX = 0.0; // Final x-coordinate | |
float endY = 0.0; // Final y-coordinate | |
float distX; // X-axis distance to move | |
float distY; // Y-axis distance to move | |
float exponent = 1; // Determines the curve | |
float x = 0.0; // Current x-coordinate | |
float y = 0.0; // Current y-coordinate | |
float step = 0.09; // Size of each step along the path | |
float pct = 0.0; // Percentage traveled (0.0 to 1.0) | |
ArrayList positions = new ArrayList(); | |
int countPositions = 0; | |
BufferedReader reader; | |
String line; | |
void setup() { | |
size(640, 360); | |
noStroke(); | |
smooth(); | |
distX = endX - beginX; | |
distY = endY - beginY; | |
reader = createReader("/home/vilson/livecoding/positions.txt"); | |
do { | |
try { | |
line = reader.readLine(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
line = null; | |
} | |
if (line != null) { | |
String[] s = split(line, ','); | |
Position p = new Position(float(s[0]), float(s[1]), float(s[2])); | |
positions.add(p); | |
} | |
} while (line != null); | |
} | |
void draw() | |
{ background(0); | |
//fill(0, 2); | |
//rect(0, 0, width, height); | |
pct += step; | |
if (pct < 1.0) { | |
//x = beginX + (pct * distX); | |
//y = beginY + (pow(pct, exponent) * distY); | |
x = beginX + pct*distX; | |
y = beginY + pct*distY; | |
} else { | |
Position p = new Position(0,0,0); | |
p = (Position)positions.get(countPositions++%positions.size()); | |
pct = 0.0; | |
step = p.speed; | |
beginX = x; | |
beginY = y; | |
endX = p.targetX; | |
endY = p.targetY; | |
distX = endX - beginX; | |
distY = endY - beginY; | |
} | |
fill(255); | |
ellipse(x, y, 20, 20); | |
} | |
void mousePressed() { | |
pct = 0.0; | |
beginX = x; | |
beginY = y; | |
endX = mouseX; | |
endY = mouseY; | |
distX = endX - beginX; | |
distY = endY - beginY; | |
} | |
class Position { | |
float targetX, targetY, speed; | |
Position(float targetX, float targetY, float speed) { | |
this.targetX = targetX; | |
this.targetY = targetY; | |
this.speed = speed; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment