// globals Graviton gravioli; void setup(){ size(200,200); background(0); gravioli = new Graviton(); } void draw(){ background(0); gravioli.draw(); } class Graviton{ float x, y; float cnt, detail, radius, offset; float[] xlist = new float[200]; float[] ylist = new float[200]; // constructor Graviton(){ radius = width * 0.4; // orbit size offset = width / 2; // center detail = 6.28 / 1000; // speed cnt = random(-3.14, 3.14); // starting location } // called every refresh from main draw loop void draw(){ this.move(); stroke(255); point(x,y); } void move(){ x = sin(cnt) * radius + offset; y = cos(cnt) * radius + offset; cnt = cnt + detail; if (cnt > 3.14){ cnt = -3.14; } this.trail(); } void trail(){ xlist = reverse(xlist); // turn arrays around ylist = reverse(ylist); xlist = append(xlist, x); // appends to back of array ylist = append(ylist, y); xlist = reverse(xlist); // reflip so "back" is front ylist = reverse(ylist); xlist = contract(xlist, 200); // resize to drop oldest element ylist = contract(ylist, 200); // draw trail beginShape(LINE_STRIP); curveVertex(x, y); curveVertex(xlist[1], ylist[1]); curveVertex(xlist[50], ylist[50]); curveVertex(xlist[100], ylist[100]); curveVertex(xlist[150], ylist[150]); curveVertex(xlist[199], ylist[199]); endShape(); } }