Created
February 18, 2017 21:19
-
-
Save JoshCheek/c9cb4068882658b435570db8b6a889cf to your computer and use it in GitHub Desktop.
Shaft Shearing
This file contains 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
require "graphics" | |
class ShaftShearing < Graphics::Simulation | |
# I should soooo make one called "fruit flies ponder a pond where the bg is | |
# like [10, 21, 36], and there is a circle at the end of the bezier | |
CLEAR_COLOR = [36, 30, 10] | |
def initialize | |
super 800, 450, 24 | |
@points = [[-1, -1], [-1, h], [w, h], [w, -1]] | |
# @points = 100.times.map { |i| [ | |
# w/2*Math.cos(2*Math::PI*i/30.0)+w/2, | |
# h/2*Math.sin(2*Math::PI*i/30.0)+h/2, | |
# ] } | |
color.default_proc = -> h, k { k } | |
@drawers = [] | |
n = 500 | |
n.times do |i| | |
color = [255, 255, 255] | |
points = @points.dup | |
percent = | |
Math.sin(Math.sin(Math.sin(Math.sin(Math.sin( | |
Math.sin(Math::PI*(i/n.to_f%1)-Math::PI/2) | |
))))) | |
./( | |
Math.sin(Math.sin(Math.sin(Math.sin(Math.sin( | |
1 | |
))))) | |
).+(1)./(2) | |
@drawers[i] = [] | |
200.times do | |
points << points.first | |
crnt_points = points | |
@drawers[i] << lambda { draw_lines_between crnt_points, color } | |
points = percentages_between points, percent | |
end | |
end | |
end | |
def draw(ticks) | |
clear | |
@drawers[ticks % @drawers.length].each(&:call) | |
end | |
def dim((r, g, b), percent) | |
end_r, end_g, end_b = CLEAR_COLOR | |
[ r + (end_r-r)*percent, | |
g + (end_g-g)*percent, | |
b + (end_b-b)*percent, | |
] | |
end | |
def draw_lines_between(points, color) | |
points.each_cons 2 do |(x1, y1), (x2, y2)| | |
line x1, y1, x2, y2, color | |
end | |
end | |
# feels like if I think about calculus for a little bit, I might be able to | |
# come up with an equation for htis so that we don't have to repeatedly invoke it | |
def percentages_between(points, percent) | |
points.each_cons(2).map do |(x1, y1), (x2, y2)| | |
[x1+(x2-x1)*percent, y1+(y2-y1)*percent] | |
end | |
end | |
def rand_point | |
return [rand(w), rand(h)] | |
[rand(5*w)-2*w, rand(5*h)-2*h] | |
end | |
end | |
ShaftShearing.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment