Skip to content

Instantly share code, notes, and snippets.

@volfegan
Created December 28, 2019 03:08
Show Gist options
  • Save volfegan/a2f5196430310070d7de5d3ec5700949 to your computer and use it in GitHub Desktop.
Save volfegan/a2f5196430310070d7de5d3ec5700949 to your computer and use it in GitHub Desktop.
Floating road of binary traffic animation
//based on: https://twitter.com/ntsutae/status/1209356755433443331
float C=0, D, W=720, sizeText=18, x, y, X;
long t;
char binary, b0 = '0', b1 = '1';
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);
t = millis();
}
void draw() {
background(0);
D=W/2;
x=D;
y=D;
String s="";
if (t+500 < millis()) {
b0 = (random(0, 1) < 0.5) ? '0' : '1';
b1 = (random(0, 1) < 0.5) ? '0' : '1';
t = millis();
}
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);
textSize(dist(X, y-D, X, y+D)/3.5);
String b = (j > 0) ? b0+"\n"+b1 : b1+"\n"+b0;
text(b, X, y+D);
}
if (sizeText > 1) textSize(sizeText);
else textSize(1);
textAlign(LEFT, BASELINE);
}
}
sizeText=18;
textSize(sizeText);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment