float myAngle = 0.0; final float ANGLE_CHANGE = 0.001; final int MAX_POINTS = 500; long frameNumber=0; ArrayList myPoints = new ArrayList(); class Vector { public float x,y,z; public Vector(float randomRange) { x = random(-randomRange, randomRange); y = random(-randomRange, randomRange); z = random(-randomRange, randomRange); } public Vector(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } } class Vertex { private final float MAX_MOVE_SPEED = 0.5f; public float x,y,z; private Vector myVector = new Vector(random(MAX_MOVE_SPEED)); final int DOT_SIZE = 3; final long SHAKE_FREQUENCY = 3000; final long SHAKE_DURATION = 500; final long SHAKE_AMOUNT = 15; long lastShakeTime = 0; long shakeBeginTime = 0; public Vertex() { x=y=z=0; } public Vertex(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } public void Move() { Vector offset = new Vector(1,1,1); long now = Now(); if ( (now - lastShakeTime) >= SHAKE_FREQUENCY ) { if ( 0 == shakeBeginTime ) shakeBeginTime = now; if ( now - shakeBeginTime >= SHAKE_DURATION ) { // stop shaking lastShakeTime = now; shakeBeginTime = 0; } offset.x = random( -SHAKE_AMOUNT, SHAKE_AMOUNT ); offset.y = random( -SHAKE_AMOUNT, SHAKE_AMOUNT ); offset.z = random( -SHAKE_AMOUNT, SHAKE_AMOUNT ); } x += myVector.x * offset.x; y += myVector.y * offset.y; z += myVector.z * offset.z; } } long Now() { return millis(); } void setup() { size(800,600,P3D); noFill(); background(0); smooth(); myPoints.add(new Vertex(width/2,height/2,100)); } void draw() { background(0); frameNumber++; try { drawScene(); movePoints(); } catch (Exception ex) { //println(ex.getMessage()); } } void drawScene() throws Exception { try { if ( myPoints.size() >= 3 ) { Vertex startVertex = myPoints.get(0); Vertex endVertex = myPoints.get(myPoints.size()-1); beginShape(); curveVertex(startVertex.x, startVertex.y, startVertex.z); int C=0; for ( int i=0; i < myPoints.size(); i++ ) { C++; C %= 255; if ( i < myPoints.size()/3 ) stroke(C,0,0); else if ( i < 2*(myPoints.size()/3) ) stroke(0,C,0); else stroke(0,0,C); Vertex thisPoint = myPoints.get(i); curveVertex(thisPoint.x, thisPoint.y, thisPoint.z); } curveVertex(endVertex.x, endVertex.y, endVertex.z); endShape(); } if ( myPoints.size() < MAX_POINTS ) addPoint(); } catch (Exception ex) { throw ex; } } void movePoints() { for ( int i=0; i < myPoints.size(); i++ ) { Vertex thisPoint = myPoints.get(i); thisPoint.Move(); } } void addPoint() { Vertex lastPoint = myPoints.get((int)random(0,myPoints.size()-1)); Vertex newPoint = new Vertex( lastPoint.x + random(-50,50), lastPoint.y + random(-50,50), lastPoint.z + random(-50,50) ); myPoints.add(newPoint); }