Skip to content

Instantly share code, notes, and snippets.

@azisaka
Created November 24, 2008 17:27
Show Gist options
  • Save azisaka/28529 to your computer and use it in GitHub Desktop.
Save azisaka/28529 to your computer and use it in GitHub Desktop.
require 'parable'
p = Parable.new
x_start = 0
y_start = 0
p.point(x_start,y_start)
x_finish = 200
y_finish = 200
p.point(x_finish,y_finish)
xv = (x_finish.to_f-x_start.to_f)/2
yv = 100.0
distance = x_finish-xv
(0..250).each do |x|
k = (-yv)/distance**2
fx = k*((x-xv)**2)+yv
puts "#{x},#{fx}"
p.point(x,fx)
end
p.output
require 'rubygems'
require 'rmagick'
class Parable
def initialize
@canvas = Magick::Image.new(250,250)
@draw = Magick::Draw.new
File.delete('testing.gif') if File.exists? 'testing.gif'
end
def point(x,y)
@draw.point(x,y)
end
def output
@draw.draw(@canvas)
@canvas.write('testing.gif')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment