Last active
August 29, 2015 13:55
-
-
Save mfwhitman/8768502 to your computer and use it in GitHub Desktop.
Creates a animated dotted line.
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
| int shutter = 0; | |
| int changeover = 0; | |
| float[] interx; | |
| float[] intery; | |
| int headx = 20; | |
| int heady = 20; | |
| int tailx = 460; | |
| int taily = 460; | |
| int divisions = 20; | |
| int shutterspeed = 50; | |
| void setup() { | |
| interx = new float[divisions+2]; | |
| intery = new float[divisions+2]; | |
| interx[0] = headx; | |
| intery[0] = heady; | |
| interx[divisions+1] = tailx; | |
| intery[divisions+1] = taily; | |
| size(480, 480, P2D); | |
| if (frame != null) { | |
| frame.setResizable(true); | |
| } | |
| smooth(8); strokeWeight(2); | |
| } | |
| void draw() { | |
| clear(); | |
| background(55); | |
| noFill(); | |
| shutter++; | |
| if (shutter == shutterspeed) | |
| { | |
| shutter = 0; | |
| changeover = ++changeover % 2; | |
| } | |
| for (int i = 0; i < divisions; i++) | |
| { | |
| float pos = shutter / float(shutterspeed); | |
| float startx = lerp(headx, tailx, (float(i)/divisions)); | |
| float endx = lerp(headx, tailx, ((float(i)+1)/divisions)); | |
| float starty = lerp(heady, taily, (float(i)/divisions)); | |
| float endy = lerp(heady, taily, ((float(i)+1)/divisions)); | |
| interx[i+1] = lerp (startx, endx, pos); | |
| intery[i+1] = lerp (starty, endy, pos); | |
| } | |
| for (int i = 0; i < divisions+1; i++) | |
| { | |
| if ((i + changeover) % 2 == 0) stroke(100); | |
| else stroke(255); | |
| line(interx[i], intery[i], interx[i+1], intery[i+1]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment