Delayed Mouse Tracking
by Evan Raskob
HTML
<script type="application/processing">
float[] x = new float[20];
float[] y = new float[20];
float segLength = 10;
void setup() {
size(400, 500);
smooth();
}
void draw() {
//background(226);
if(typeof xdir=="undefined"){
xdir = 1;
}
if(typeof ydir=="undefined"){
ydir=1;
}
if(X<=0){
xdir = 1;
}else if(X>=(width-20)){
xdir = -1;
}
if(Y<=0){
ydir = 1;
}else if(Y>=(height-20)){
ydir = -1;
}
X += xdir;
Y += ydir;
rect(X, Y, 20,20)
}
</script>
<canvas width="200px" height="200px"></canvas>
JavaScript
var scripts=document.getElementsByTagName("script");
for(var i=0;i<scripts.length;i++) {
if(scripts[i].type=="application/processing"){
var src=scripts[i].src,canvas=scripts[i].nextSibling;
if(src&&src.indexOf("#")){
canvas=document.getElementById(src.substr(src.indexOf("#")+1));
}else{
while(canvas&&canvas.nodeName.toUpperCase()!="CANVAS")
canvas=canvas.nextSibling;
}
if(canvas){
new Processing(canvas,scripts[i].text);
}
}
}