Sha256: a9e04b09502cb99806d58d86c8566d6b39c45b1aa4f363d670e468f8a01b9d96

Contents?: true

Size: 815 Bytes

Versions: 3

Compression:

Stored size: 815 Bytes

Contents

# Drawing code stolen from here:
#  http://www.rubyquiz.com/quiz104.html

$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../lib")
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../../ext")

require 'ray'

class Ray::Turtle
  def byzantium(r, n)
    return if n < 1
    forward r
    right 135

    4.times do
      pen_down
      forward 2 * r * sin(PI / 4)

      pen_up
      byzantium(r / 2, n - 1)
      right 90
    end

    left 135
    backward r
  end
end

Ray::Game.new("Turtle") do
  register do
    add_hook :quit, method(:exit!)
  end

  scene :byzantium do
    img = Ray::Image.new window.size
    img.turtle do
      pen_up
      center
      byzantium(100, 5)
    end

    @sprite = sprite img

    render do |win|
      win.draw @sprite
    end
  end

  push_scene :byzantium
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ray-0.2.0 samples/turtle/byzantium.rb
ray-0.1.1 samples/turtle/byzantium.rb
ray-0.1.0 samples/turtle/byzantium.rb