-
Notifications
You must be signed in to change notification settings - Fork 1
/
gif.rb
86 lines (79 loc) · 1.91 KB
/
gif.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require 'RMagick'
require 'progress'
include Magick
unless ARGV.length.between?(3,4)
puts "usage: gif.rb filename.gif <frames> <width> [<height>]"
end
filename = ARGV[0]
num_frames = ARGV[1].to_i
width = ARGV[2].to_i
height = ARGV[3] || width
height = height.to_i
def r(x,y,t)
# x = x/10
# y = y/10
# Math.sin(x * y + t / 10) * 200
(t)+Math.sqrt(x*y)
end
#puts "r(1.0,1.0,1.0) = #{r(1.0,1.0,1.0)}"
#puts "r(300.0,500.0,33.0) = #{r(300.0,500.0,33.0)}"
def g(x,y,t)
# x = x/100
# y = y/100
# Math.sin(x * y + t / 10) * 200
(t/2)+Math.sqrt(x*y)
end
def b(x,y,t)
# Math.sin(x * y + t / 10) * 200
(t/3)+Math.sqrt(x*y)
end
raise("#{filename} already exists!") if File.exist?(filename)
puts "warning: this may take awhile"
# $img = ChunkyPNG::Image.new(width,height)
$thingy = (1/256.0)*QuantumRange
threads = []
frames = ImageList.new
puts "starting?"
num_frames.times.with_progress("Making image") do |t|
#if threads.length >= 4
# threads.first.join
#end
#threads << Thread.new(t) do |t|
i = t
t = t.to_f + 1
frame = Image.new(width,height)
width.times do |x|
x = x.to_f + 1
height.times do |y|
y = y.to_f + 1
r = r(x,y,t).to_i % 256
g = g(x,y,t).to_i % 256
b = b(x,y,t).to_i % 256
r *= $thingy
g *= $thingy
b *= $thingy
puts "white point at #{x},#{y},#{t}" if r == 255 && g == 255 && b==255
frame.color_point(x,y,Pixel.new(r,g,b,0))
#puts 'omg' if r == 0 && g == 0 && b == 0
#frame += [r,g,b]
#frame << r*256
#frame << g*256
#frame << b*256
# $img[x,y] = ChunkyPNG::Color.rgb(r,g,b)
end
#end
frames[i]= frame
end
end
=begin
puts "Processing"
final_gif = ImageList.new
frames.each do |frame|
img = Image.new(width,height)
img.import_pixels(0,0,width,height,"RGB",frame)
final_gif << img
end
=end
#raise("#{filename} already exists!") if File.exist?(filename)
puts 'saving...'
frames.write(filename)