Created
September 26, 2016 15:19
-
-
Save am17an/765b029039fd5688135494bd638bbca9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| void setup() { | |
| size(600, 600, P3D); | |
| smooth(8); | |
| hint(ENABLE_STROKE_PURE); | |
| } | |
| ArrayList<Ripple> ripples = new ArrayList<Ripple>(); | |
| // R is total radius of the thing | |
| float R = 150; | |
| //nHops is the number of circles | |
| //nMod is the frames it takes to go from one circle to another | |
| //nHops*nMod is total no. of frames | |
| int nHops = 8; | |
| int nMod = 50; | |
| //lSwimmer is length of the swimmer | |
| //B is the amplitude of it | |
| float B = 40; | |
| int lSwimmer = 32; | |
| int nFrames = 0; | |
| boolean saving = true; | |
| void draw() { | |
| background(#00628B); | |
| translate(width/2, height/2); | |
| rotateX(PI/2.5); | |
| // at this point the circle and wave intersect | |
| if (nFrames%nMod == 0) { | |
| float th = map(nFrames, 0, nHops*nMod, 0, TWO_PI); | |
| float x = (R)*cos(th); | |
| float y = (R)*sin(th); | |
| ripples.add(new Ripple(x, y, nHops*nMod)); | |
| } | |
| for (Ripple ripple : ripples) { | |
| ripple.display(); | |
| } | |
| for (int i = 1; i < lSwimmer; ++i) { | |
| float th = map(nFrames-i, 0, nHops*nMod, 0, TWO_PI); | |
| float alpha = map(nFrames-i, 0, nHops*nMod, 0, (nHops/2)*TWO_PI); | |
| float th2 = map(nFrames-i-1, 0, nHops*nMod, 0, TWO_PI); | |
| float alpha2 = map(nFrames-i-1, 0, nHops*nMod, 0, (nHops/2)*TWO_PI); | |
| float x = (R)*cos(th); | |
| float y = (R)*sin(th); | |
| float z = B*sin(alpha); | |
| float x2 = (R)*cos(th2); | |
| float y2 = (R)*sin(th2); | |
| float z2 = B*sin(alpha2); | |
| stroke(#E6E6DC); | |
| strokeWeight(map(i, 0, lSwimmer, 6, 0)); | |
| //White | |
| line(x, y, z, x2, y2, z2); | |
| z = -z; | |
| z2 = -z2; | |
| //black, z values inversed | |
| stroke(0); | |
| line(x, y, z, x2, y2, z2); | |
| } | |
| nFrames += 1; | |
| // the loop is from the second hop, so ripples are all visible by then | |
| if (nFrames == nHops*nMod*2) { | |
| exit(); | |
| } | |
| if (saving && nFrames >= nHops*nMod) { | |
| saveFrame("out/####.gif"); | |
| } | |
| } | |
| class Ripple { | |
| float x, y; | |
| float r; | |
| int l, maxL; | |
| Ripple(float x_, float y_, int lifetime_) { | |
| x = x_; | |
| y = y_; | |
| l = lifetime_; | |
| maxL = l; | |
| r = R; | |
| } | |
| void display() { | |
| if (l>=0) { | |
| float rr = map(l, 0, maxL, r, 0); | |
| float alpha = map(l, 0, maxL, 0, 255); | |
| stroke(238, alpha); | |
| strokeWeight(1); | |
| noFill(); | |
| ellipse(x, y, rr, rr); | |
| l--; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment