Sha256: 9d8b2fa241811f992ebf4d06f4709a6a0f59b90d5b0a982fcda252b853e0ed5e

Contents?: true

Size: 1.52 KB

Versions: 29

Compression:

Stored size: 1.52 KB

Contents

# Make a 32x32 animated GIF that resembles the OS X animation.
# This produces a very small (~2.6Kb) GIF file.

require 'RMagick'

puts <<END_INFO
This example creates an animated GIF that resembles the OS X "waiting" icon.
You can view the GIF with the command

    animate spinner.gif
END_INFO


NFRAMES = 12                    # number of frames in the animation
DIM = 32                        # width & height of image in pixels
DELAY = 100.0 / (NFRAMES/2)     # 2 rotations per second

# 'frame' is a single frame in the animation.
frame = Magick::Image.new(DIM, DIM) {self.background_color = 'transparent'}

# 'spinner' will contain the frames that make up the animated GIF
spinner = Magick::ImageList.new

# 'level' is the change from darkest gray to white
level = Magick::QuantumRange / 2 / NFRAMES

NFRAMES.times do |x|
    gc = Magick::Draw.new
    gc.translate(DIM/2, DIM/2)
    gc.stroke('none')
    intensity = 0.58 * Magick::QuantumRange
    fill_color = Magick::Pixel.new(intensity, intensity, intensity).to_color
    gc.fill(fill_color)
    angle = x * (360/NFRAMES)
    NFRAMES.times do
        gc.rotate(angle)
        intensity = [intensity, Magick::QuantumRange].min
        fill_color = Magick::Pixel.new(intensity, intensity, intensity).to_color
        gc.fill(fill_color)
        gc.roundrectangle(7, -1, 15, 0, 1, 1)
        angle = -(360/NFRAMES)
        intensity += level
    end
    spinner << frame.copy
    gc.draw(spinner)
end

spinner.delay = DELAY
spinner.compression = Magick::LZWCompression
spinner.write('spinner.gif')

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
rmagick-2.13.4 examples/spinner.rb
rmagick-2.13.3 examples/spinner.rb
rmagick-2.13.3.rc1 examples/spinner.rb
rmagick-2.13.2 examples/spinner.rb
rdp-rmagick-0.0.0 examples/spinner.rb
rmagick-2.13.1 examples/spinner.rb
rmagick-2.12.2 examples/spinner.rb
rmagick-2.12.1 examples/spinner.rb
rmagick-2.12.0 examples/spinner.rb
rmagick-2.11.1 examples/spinner.rb
rmagick-2.10.0 examples/spinner.rb
rmagick-2.11.0 examples/spinner.rb
rmagick-2.1.0 examples/spinner.rb
rmagick-2.0.0 examples/spinner.rb
rmagick-2.3.0 examples/spinner.rb
rmagick-2.2.0 examples/spinner.rb
rmagick-2.2.2 examples/spinner.rb
rmagick-2.4.0 examples/spinner.rb
rmagick-2.5.2 examples/spinner.rb
rmagick-2.5.1 examples/spinner.rb