Last active
April 7, 2021 03:38
-
-
Save volfegan/44ea84305dfdfe3244bc2fe39754a62a to your computer and use it in GitHub Desktop.
Floating road of binary traffic animation v2.0
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
//based on: https://twitter.com/ntsutae/status/1209356755433443331 | |
import java.lang.StringBuilder; | |
import java.util.*; | |
float C=0, D, W=720, sizeText=18, x, y, X; | |
char binary; | |
PFont font; | |
void setup() { | |
size(720, 720); | |
//printArray(PFont.list()); | |
font = createFont("Calibri", sizeText);//Calibri; Candara; Malgun Gothic; Monospaced.plain; Ubuntu Mono; | |
textFont(font); | |
fill(0, 255, 0); | |
} | |
void draw() { | |
background(0); | |
D=W/2; | |
x=D; | |
y=D; | |
String s=""; | |
String b = ""; | |
for (float i=C++; i<C+150; i++) { | |
x+=cos(noise(i*.01)*PI*9)*5; | |
D*=.965; | |
while (textWidth(s) < D*2) { | |
if (random(0, 1) < 0.5) binary = '0'; | |
else binary = '1'; | |
s+=binary; | |
} | |
text(s, x-D, y+D); | |
sizeText*=.965; | |
if (sizeText > 1) textSize(sizeText); | |
//poles | |
if (i%32==0) { | |
for (float j=-D; j<=D; j+=2*D) { | |
X=x+j*1.5; | |
textAlign(CENTER, BOTTOM); | |
float distSize = dist(X, y-D, X, y+D)/9; | |
textSize(distSize); | |
while (b.length() < distSize) | |
b += (random(0, 1) < 0.4) ? round(random(0, 1))+"\n" : round(random(0, 1)); | |
//if (j==D) b = new StringBuilder(b).reverse().toString(); | |
if (j==D) b = scrambleLines(b); | |
text(b, X, y+D); | |
} | |
if (sizeText > 1) textSize(sizeText); | |
else textSize(1); | |
textAlign(LEFT, BASELINE); | |
} | |
} | |
sizeText=18; | |
textSize(sizeText); | |
} | |
String scrambleLines(String s) { | |
String[] scram = s.split("\n"); | |
List<String> letters = Arrays.asList(scram); | |
Collections.shuffle(letters); | |
StringBuilder sb = new StringBuilder(s.length()); | |
for (String c : letters) { | |
sb.append(c); | |
sb.append("\n"); | |
} | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment