Sha256: 2b48e2b6b281289525f3e9b4b475bed643c7cc4a783f836d95d709ebe83fc04a

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

#!/usr/bin/ruby

require 'vips'

image = Vips::Image.new_from_file ARGV[0]

module Vips
    class Image
        def wobble
            # this makes an image where pixel (0, 0) (at the top-left) has 
            # value [0, 0], and pixel (image.width - 1, image.height - 1) at the 
            # bottom-right has value [image.width - 1, image.height - 1]
            index = Vips::Image.xyz width, height 

            # make a version with (0, 0) at the centre, negative values up 
            # and left, positive down and right
            centre = index - [width / 2, height / 2]

            # to polar space, so each pixel is now distance and angle in degrees
            polar = centre.polar

            # scale sin(distance) by 1/distance to make a wavey pattern
            d = ((polar[0] * 3).sin * 10000) / (polar[0] + 1)

            # and back to rectangular coordinates again to make a set of 
            # vectors we can apply to the original index image
            index += d.bandjoin(polar[1]).rect

            # finally, use our modified index image to distort!
            mapim index 
        end
    end
end

image = image.wobble
image.write_to_file ARGV[1]

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
vips-8.6.3.2 example/wobble.rb
vips-8.7.0.1 example/wobble.rb
ruby-vips-2.0.13 example/wobble.rb
vips-8.6.3.1 example/wobble.rb
vips-8.6.3 example/wobble.rb
ruby-vips-2.0.12 example/wobble.rb
ruby-vips-2.0.11 example/wobble.rb
ruby-vips-2.0.10 example/wobble.rb
ruby-vips-2.0.9 example/wobble.rb
ruby-vips-2.0.8 example/wobble.rb
ruby-vips-2.0.7 example/wobble.rb
ruby-vips-2.0.6 example/wobble.rb