-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rb
43 lines (36 loc) · 822 Bytes
/
main.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
require 'chunky_png'
require 'progress'
filename = ARGV[0]
width = ARGV[1].to_i
height = ARGV[2].to_i || width
if filename.nil? || width.nil?
puts <<END
Usage: ruby main.rb <filename> <width> [height]
if height is omitted it is assumed to be the same as the width
END
exit
end
def r(x,y)
(x*x)**(1/2.0)
end
def g(x,y)
(y*y)**(1/2.0)
end
def b(x,y)
(x*y)**(1/2.0)
end
error("#{filename} already exists!") if File.exist?(filename)
$img = ChunkyPNG::Image.new(width,height)
width.times.with_progress("Generating image") do |x|
x = x.to_f
height.times do |y|
y = y.to_f
r = r(x,y).to_i % 256
g = g(x,y).to_i % 256
b = b(x,y).to_i % 256
$img[x,y] = ChunkyPNG::Color.rgb(r,g,b)
end
end
error("#{filename} already exists!") if File.exist?(filename)
puts 'saving...'
$img.save(filename)