Skip to content

Instantly share code, notes, and snippets.

@studioijeoma
Created January 28, 2012 21:57
Show Gist options
  • Save studioijeoma/1695890 to your computer and use it in GitHub Desktop.
Save studioijeoma/1695890 to your computer and use it in GitHub Desktop.
WheelsOfSteel.pjs
// Generated by the Processing.js exporter for Processing IDE.
// https://github.com/fjenett/processingjstool
// this code was autogenerated from PJS
(function($p) {
var sampleRate = 0;
$p.ArrayList<Float> ttPositions = new $p.ArrayList<Float>();
var ttPositionIndex = 0;
var ttPosition = 0,pttPosition = 0;
var ttPositionMax = 0;
var ttPositionSum = 0;
var ttPositionAvg = 0;
$p.ArrayList<Float> ttChanges = new $p.ArrayList<Float>();
var ttChange = 0;
var ttChangeMax = 0;
$p.ArrayList<Float> fPositions = new $p.ArrayList<Float>();
$p.ArrayList<Float> fTimes = new $p.ArrayList<Float>();
var frameStep = 0;
var progress = 0;
var radius = 100;
var rotation = 0;
function setup() {
$p.size(1024, 576);
$p.frameRate(30);
$p.ellipseMode($p.RADIUS);
var xml = new $p.XMLElement(this, "smlTest.xml");
var turntable = xml.getChild("performance/turntable");
var fader = xml.getChild("performance/mixer/fader");
sampleRate = parseFloat(turntable.getChild("samplerate").getContent());
var count = turntable.getChild("data").getChildCount();
var dataAvg = 0;
var dataSum = 0;
for (var i = 0; i < count; i++) {
var d = parseFloat(xml.getChild("performance/turntable/data")
.getChild(i).getContent());
dataSum += d;
}
dataAvg = dataSum / count;
for (var i = 0; i < count; i++) {
var d = parseFloat(xml.getChild("performance/turntable/data")
.getChild(i).getContent());
if (d >= dataAvg / 2) {
ttPositions.add(d);
ttPositionMax = $p.max(ttPositionMax, d);
}
}
for (var i = 0; i < ttPositions.size() - 1; i++) {
var c = ttPositions.get(i + 1) - ttPositions.get(i);
ttChanges.add(c);
ttChangeMax = $p.max(ttChangeMax, c);
}
count = fader.getChild("data").getChildCount();
for (var i = 0; i < count; i++) {
var event = fader.getChild("data").getChild(i);
var t = parseFloat(event.getChild("t").getContent());
var p = parseFloat(event.getChild("p").getContent());
fTimes.add(t);
fPositions.add(p);
}
frameStep = $p.floor((1000 / $p.__frameRate) / (1000 / sampleRate));
}
$p.setup = setup;
function draw() {
$p.background(255);
$p.smooth();
$p.pushMatrix();
$p.translate($p.width / 2, $p.height / 2);
$p.strokeWeight(5);
$p.fill(230, 230, 230);
$p.noStroke();
$p.ellipse(0, 0, radius, radius);
$p.stroke(220);
$p.arc(0, 0, radius, radius, $p.PI + $p.HALF_PI, 4 * $p.PI);
$p.stroke(180);
$p.arc(0, 0, radius, radius, $p.PI + $p.HALF_PI, (2 * $p.PI * progress) + $p.PI
+ $p.HALF_PI);
$p.fill(50, 50, 250);
$p.stroke(50, 50, 250);
if ($p.frameCount * frameStep < ttPositions.size()) {
ttPositionIndex = $p.frameCount * frameStep;
ttPosition = ttPositions.get(ttPositionIndex);
pttPosition = ttPosition;
if (ttPositionIndex < ttPositions.size() - 1)
ttChange = ttPositions.get(ttPositionIndex);
}
else {
$p.fill(255, 0, 0);
$p.stroke(255, 0, 0);
}
progress = ttPositionIndex / ttPositions.size();
rotation = $p.map(ttPosition, 0, 1800, 0, 2 * $p.PI);
rotation += $p.PI;
$p.line(0, 0, radius * $p.cos(rotation) * 0.92, radius * $p.sin(rotation)
* 0.92);
$p.text(ttPosition, radius / 4, 0);
$p.translate(-radius, -radius);
drawChange();
drawPosition();
$p.popMatrix();
}
$p.draw = draw;
function drawPosition() {
var y = radius * 2 + radius / 4;
var w = radius * 2;
var h = radius / 2;
$p.strokeWeight(5);
$p.stroke(200);
$p.noFill();
$p.rect(0, y, w, h);
$p.strokeWeight(2);
$p.beginShape();
for (var i = 0; i < ttPositionIndex; i++) {
var p = ttPositions.get(i);
var px = w * i / ttPositions.size();
var py = y + h * (p / ttPositionMax);
$p.vertex(px, py);
}
$p.endShape();
}
$p.drawPosition = drawPosition;
function drawChange() {
var y = radius * 3;
var w = radius * 2;
var h = radius / 2;
$p.strokeWeight(5);
$p.stroke(200);
$p.noFill();
$p.line(0, y + h / 2, w, y + h / 2);
$p.rect(0, y, w, h);
$p.strokeWeight(2);
$p.beginShape();
for (var i = 0; i < ttPositionIndex; i++) {
var c = ttChanges.get(i);
var cx = w * i / ttChanges.size();
var cy = y + h / 2 * (c / ttChangeMax) + h / 2;
$p.vertex(cx, cy);
}
$p.endShape();
}
$p.drawChange = drawChange;
function keyPressed() {
$p.frameCount = 0;
}
$p.keyPressed = keyPressed;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment