Skip to content

Instantly share code, notes, and snippets.

@Mongey
Created November 5, 2012 23:54
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 Mongey/4021231 to your computer and use it in GitHub Desktop.
Save Mongey/4021231 to your computer and use it in GitHub Desktop.
require 'RMagick'
include Magick
width = 90
height = 100
matrix = [
[0,1,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[0,1,0,0,0],
[0,1,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[0,0,0,1,0],
[0,0,0,0,1],
[0,1,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[0,1,0,0,0],
[0,1,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[0,0,0,1,0],
[0,0,0,0,1]
]
canvas_height = height * matrix.size
canvas_width = width * matrix.first.size
canvas = Image.new(canvas_width, canvas_height,
HatchFill.new('white','lightcyan2'))
gc = Draw.new
gc.stroke('blue')
count = 0
start_x,start_y = 0
finish_x,finish_y = 0
matrix.each_with_index do |row,row_index|
row.each_with_index do |value, col_index|
if value == 1
#finish drawing of the last bit
if row_index >0
finish_x = width * col_index
finish_y = height * row_index
#enposition
gc.line(start_x, start_y, finish_x, finish_y)
end
# draw a line
start_x = width * col_index
start_y = height * row_index
end
end
gc.draw(canvas)
if count < 10
filename = "bezier0" + count.to_s + ".gif"
else
filename = "bezier" + count.to_s + ".gif"
end
canvas.write (filename)
count +=1
end
# create a gif from all the .gifs here
animation = ImageList.new(*Dir["*.gif"].sort)
animation.delay = 10
animation.write("animated.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment