public
Created

Brownian motion sketch

  • Download Gist
brownian.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
num = 2000
range = 6
 
a = []
 
setup do
size 420, 500
title "Brownian"
a << Point.new(width/2, height/2)
end
 
draw do
a << a.last.clone + Point.rand(range)
a.last.clamp! 0, width, 0, height
a.shift if a.length > num
 
for i in 0..(a.length-2)
color i.to_f/a.length * 240 + 32
line a[i].x, a[i].y, a[i+1].x, a[i+1].y
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.