Skip to content

Instantly share code, notes, and snippets.

@nasser
Last active August 29, 2015 14:01
Show Gist options
  • Save nasser/9dbc9b3f4b19e1360310 to your computer and use it in GitHub Desktop.
Save nasser/9dbc9b3f4b19e1360310 to your computer and use it in GitHub Desktop.
Stack Syntax Sketch
int num = 2000;
int range = 6;
float[] ax = new float[num];
float[] ay = new float[num];
void setup()
{
size(640, 360);
for(int i = 0; i < num; i++) {
ax[i] = width/2;
ay[i] = height/2;
}
frameRate(30);
}
void draw()
{
background(51);
// Shift all elements 1 place to the left
for(int i = 1; i < num; i++) {
ax[i-1] = ax[i];
ay[i-1] = ay[i];
}
// Put a new value at the end of the array
ax[num-1] += random(-range, range);
ay[num-1] += random(-range, range);
// Constrain all points to the screen
ax[num-1] = constrain(ax[num-1], 0, width);
ay[num-1] = constrain(ay[num-1], 0, height);
// Draw a line connecting the points
for(int i=1; i<num; i++) {
float val = float(i)/num * 204.0 + 51;
stroke(val);
line(ax[i-1], ay[i-1], ax[i], ay[i]);
}
}
6 : range
[ { width 2 / : x height 2 / : y } ] : points
640:w 360:h size
30 frame-rate
[
51:gray background
; Put a new value at the end of the array
points head dup
range neg range random x + : x
range neg range random y + : y
; Constrain all points to the screen
0 width x clamp : x
0 height y clamp : y
; Draw a line connecting the points
[
i points length / 204 * 51 +:gray stroke
points i get points i 1 - get line
] points length times
] : draw
range : 6
points : [ { x: / 2 width y: / 2 height } ]
size w:640 h:360
frame-rate 30
draw : [
background gray:51
; Put a new value at the end of the array
dup head points
x : + x random range neg range
y : + y random range neg range
; Constrain all points to the screen
x : clamp x width
y : clamp y height
; Draw a line connecting the points
times length points [
stroke gray:+ 51 * 204 / length points i
line get - 1 i points get i points
]
]
@nasser
Copy link
Author

nasser commented May 16, 2014

This is a sketch and probably not 100% coherent or consistent

Brownian motion in

  1. Processing
  2. A fictional traditionally ordered stack language with first class dictionaries
  3. A fictional reverse ordered stack language with first class dictionaries

3 is the same as 2, but each line of input is read from right to left so that the resulting source code is allegedly "more natural"

5 6 + becomes + 6 5
a b line becomes line b a

@brendanberg
Copy link

WELL GITHUB DELETED MY COMMENT WHEN I TRIED TO PREVIEW IT SO YOU DON'T GET FEEDBACK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment