Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'rmagick'
  3.  
  4. TWO_PI = 2 * Math::PI
  5.  
  6. image_path = ARGV[0] # User input
  7. extname = File.extname image_path
  8. planet_path = image_path + '.planet' + extname
  9.  
  10. original = Magick::Image.read(image_path).first
  11. width = original.columns
  12. height = original.rows
  13.  
  14. target_size = height * 2
  15. planet = Magick::Image.new(target_size, target_size)
  16.  
  17. target_size.times do |x|
  18. target_size.times do |y|
  19. r, θ = Complex(height - y, height - x).polar # Cheat using complex plane
  20. next if r > height
  21. x_original = width / 2 - θ * width / TWO_PI
  22. color = original.pixel_color(x_original, height - r)
  23. planet.pixel_color(x, y, color)
  24. end
  25. end
  26.  
  27. planet.write(planet_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement