Created
January 28, 2012 21:55
-
-
Save studioijeoma/1695886 to your computer and use it in GitHub Desktop.
WheelsOfSteel.pde
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
import java.util.ArrayList; | |
float sampleRate; | |
ArrayList<Float> ttPositions = new ArrayList<Float>(); | |
int ttPositionIndex; | |
float ttPosition, pttPosition; | |
float ttPositionMax = 0; | |
float ttPositionSum = 0; | |
float ttPositionAvg = 0; | |
ArrayList<Float> ttChanges = new ArrayList<Float>(); | |
float ttChange; | |
float ttChangeMax = 0; | |
ArrayList<Float> fPositions = new ArrayList<Float>(); | |
ArrayList<Float> fTimes = new ArrayList<Float>(); | |
int frameStep; | |
float progress; | |
float radius = 100; | |
float rotation = 0; | |
void setup() { | |
size(1024, 576); | |
frameRate(30); | |
ellipseMode(RADIUS); | |
XMLElement xml = new XMLElement(this, "smlTest.xml"); | |
XMLElement turntable = xml.getChild("performance/turntable"); | |
XMLElement fader = xml.getChild("performance/mixer/fader"); | |
sampleRate = parseFloat(turntable.getChild("samplerate").getContent()); | |
int count = turntable.getChild("data").getChildCount(); | |
float dataAvg = 0; | |
float dataSum = 0; | |
for (int i = 0; i < count; i++) { | |
float d = parseFloat(xml.getChild("performance/turntable/data") | |
.getChild(i).getContent()); | |
dataSum += d; | |
} | |
dataAvg = dataSum / count; | |
for (int i = 0; i < count; i++) { | |
float d = parseFloat(xml.getChild("performance/turntable/data") | |
.getChild(i).getContent()); | |
if (d >= dataAvg / 2) { | |
ttPositions.add(d); | |
ttPositionMax = max(ttPositionMax, d); | |
} | |
} | |
for (int i = 0; i < ttPositions.size() - 1; i++) { | |
float c = ttPositions.get(i + 1) - ttPositions.get(i); | |
ttChanges.add(c); | |
ttChangeMax = max(ttChangeMax, c); | |
} | |
count = fader.getChild("data").getChildCount(); | |
for (int i = 0; i < count; i++) { | |
XMLElement event = fader.getChild("data").getChild(i); | |
float t = parseFloat(event.getChild("t").getContent()); | |
float p = parseFloat(event.getChild("p").getContent()); | |
fTimes.add(t); | |
fPositions.add(p); | |
} | |
frameStep = floor((1000f / frameRate) / (1000f / sampleRate)); | |
} | |
void draw() { | |
background(255); | |
smooth(); | |
pushMatrix(); | |
translate(width / 2, height / 2); | |
strokeWeight(5); | |
fill(230, 230, 230); | |
noStroke(); | |
ellipse(0, 0, radius, radius); | |
stroke(220); | |
arc(0, 0, radius, radius, PI + HALF_PI, 4 * PI); | |
stroke(180); | |
arc(0, 0, radius, radius, PI + HALF_PI, (2 * PI * progress) + PI | |
+ HALF_PI); | |
fill(50, 50, 250); | |
stroke(50, 50, 250); | |
if (frameCount * frameStep < ttPositions.size()) { | |
ttPositionIndex = frameCount * frameStep; | |
ttPosition = ttPositions.get(ttPositionIndex); | |
pttPosition = ttPosition; | |
if (ttPositionIndex < ttPositions.size() - 1) | |
ttChange = ttPositions.get(ttPositionIndex); | |
} | |
else { | |
fill(255, 0, 0); | |
stroke(255, 0, 0); | |
} | |
progress = (float) ttPositionIndex / ttPositions.size(); | |
rotation = map(ttPosition, 0f, 1800f, 0f, 2f * PI); | |
rotation += PI; | |
line(0, 0, radius * cos(rotation) * 0.92f, radius * sin(rotation) | |
* 0.92f); | |
// fill(200); | |
text(ttPosition, radius / 4, 0); | |
translate(-radius, -radius); | |
drawChange(); | |
drawPosition(); | |
popMatrix(); | |
} | |
void drawPosition() { | |
float y = radius * 2 + radius / 4; | |
float w = radius * 2; | |
float h = radius / 2; | |
strokeWeight(5); | |
stroke(200); | |
noFill(); | |
rect(0, y, w, h); | |
strokeWeight(2); | |
beginShape(); | |
for (int i = 0; i < ttPositionIndex; i++) { | |
// position | |
float p = ttPositions.get(i); | |
float px = w * (float) i / ttPositions.size(); | |
float py = y + h * (p / ttPositionMax); | |
vertex(px, py); | |
} | |
endShape(); | |
} | |
void drawChange() { | |
float y = radius * 3; | |
float w = radius * 2; | |
float h = radius / 2; | |
strokeWeight(5); | |
stroke(200); | |
noFill(); | |
line(0, y + h / 2, w, y + h / 2); | |
rect(0, y, w, h); | |
strokeWeight(2); | |
beginShape(); | |
for (int i = 0; i < ttPositionIndex; i++) { | |
// change | |
float c = ttChanges.get(i); | |
float cx = w * (float) i / ttChanges.size(); | |
float cy = y + h / 2 * (c / ttChangeMax) + h / 2; | |
vertex(cx, cy); | |
} | |
endShape(); | |
} | |
void keyPressed() { | |
frameCount = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment