Sha256: d98a938b3d0847a3bb3d5dad5fec249ff60a1d0ee38c8742180b10bc4e00ee06

Contents?: true

Size: 1.52 KB

Versions: 46

Compression:

Stored size: 1.52 KB

Contents

# Gosu Zen example based on erisdiscord's comment here:
# https://github.com/jlnr/gosu/pull/120

# Gosu Zen is the (inline) Sinatra of Ruby multimedia programming.
# The interface is still in flux. If you want to tune the interface
# a little further or provide more examples, please fork Gosu and
# send a pull request. Thanks!

require 'rubygems'
require 'gosu/zen'
include Gosu::Zen

window 480, 240, :fullscreen => false

button_down Gosu::KbEscape do
  close
end

update do
  t = Gosu.milliseconds / 1000.0

  @radius = [width, height].min * 0.37
  @angle = t * Math::PI

  a, b =\
    (Math.cos(t) + 0.5) * 0xff,
    (Math.sin(t) + 0.5) * 0xff

  c = (a + b) / 2

  @colors = [
    Gosu::Color.rgb(a, b, 0xff),
    Gosu::Color.rgb(a, 0x00, b),
    Gosu::Color.rgb(0xff, b, a),
    Gosu::Color.rgb(b, a, 0x00),
    Gosu::Color.rgb(b, 0xff, a),
    Gosu::Color.rgb(0x00, a, b) ]

  @background = Gosu::Color.rgb(c, c, c)
end

draw do
  draw_quad\
    0,     0,      @background,
    0,     height, @background,
    width, height, @background,
    width, 0,      @background, 0

  translate width / 2, height / 2 do
    @colors.each.with_index do |color, i|

      angle = @angle + i.to_f / @colors.length * 2.0 * Math::PI
      x = @radius * Math.sin(angle)
      y = @radius * Math.cos(angle)
      w, h = x, y

      translate x, y do
        rotate Gosu.radians_to_degrees(angle) do
          draw_quad\
            -w, +h, color,
            -w, -h, color,
            +w, -h, color,
            +w, +h, color, 0
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
gosu-0.8.7.2 examples/GosuZen.rb
gosu-0.8.7.1 examples/GosuZen.rb
gosu-0.8.7 examples/GosuZen.rb
gosu-0.8.6 examples/GosuZen.rb
gosu-0.8.6-x86-mingw32 examples/GosuZen.rb
gosu-0.8.6.pre1 examples/GosuZen.rb
gosu-0.8.5 examples/GosuZen.rb
gosu-0.8.5-x86-mingw32 examples/GosuZen.rb
gosu-0.8.5.pre1 examples/GosuZen.rb
gosu-0.8.4-x86-mingw32 examples/GosuZen.rb
gosu-0.8.4 examples/GosuZen.rb
gosu-0.8.3-x86-mingw32 examples/GosuZen.rb
gosu-0.8.3 examples/GosuZen.rb
gosu-0.8.2-x86-mingw32 examples/GosuZen.rb
gosu-0.8.2 examples/GosuZen.rb
gosu-0.8.1-x86-mingw32 examples/GosuZen.rb
gosu-0.8.1 examples/GosuZen.rb
gosu-0.8.0 examples/GosuZen.rb
gosu-0.8.0-x86-mingw32 examples/GosuZen.rb
gosu-0.8.0.pre7 examples/GosuZen.rb