Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rmagick'
- TWO_PI = 2 * Math::PI
- image_path = ARGV[0] # User input
- extname = File.extname image_path
- planet_path = image_path + '.planet' + extname
- original = Magick::Image.read(image_path).first
- width = original.columns
- height = original.rows
- target_size = height * 2
- planet = Magick::Image.new(target_size, target_size)
- target_size.times do |x|
- target_size.times do |y|
- r, θ = Complex(height - y, height - x).polar # Cheat using complex plane
- next if r > height
- x_original = width / 2 - θ * width / TWO_PI
- color = original.pixel_color(x_original, height - r)
- planet.pixel_color(x, y, color)
- end
- end
- planet.write(planet_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement