Created
November 5, 2012 23:54
-
-
Save Mongey/4021231 to your computer and use it in GitHub Desktop.
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 '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