Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created February 16, 2017 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/ff9635dfcb290fa483ce887141d26056 to your computer and use it in GitHub Desktop.
Save JoshCheek/ff9635dfcb290fa483ce887141d26056 to your computer and use it in GitHub Desktop.
Coffee Skimmer
require "graphics"
class CoffeeSkimmer < Graphics::Simulation
CLEAR_COLOR = [36, 30, 10]
def initialize
super 800, 450, 24
color.default_proc = -> h, k { k }
@points = 500.times.map { [rand(3*w)-1*w, rand(3*h)-1*h] }
@points.concat @points.take(200)
200.times do
@points = @points.each_cons(2).map do |(x1, y1), (x2, y2)|
[x1+(x2-x1)*0.5, y1+(y2-y1)*0.5]
end
end
end
def draw(ticks)
clear
@points.rotate!.take(10).each_cons(2) do |(x1, y1), (x2, y2)|
line x1, y1, x2, y2, :white
end
end
end
CoffeeSkimmer.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment