Sha256: 3b655de9bd4ca74886b65e999a42b4d5d57dccb04c0ad73a52092dac01458fac

Contents?: true

Size: 976 Bytes

Versions: 4

Compression:

Stored size: 976 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 tree(size)
    if size < 5
      forward size
      backward size
    else
      forward size / 3

      left 30
      tree size * 2 / 3
      right 30

      forward size / 6

      right 25
      tree size / 2
      left 25

      forward size / 3
      right 25
      tree size / 2
      left 25

      forward size / 6
      backward size
    end
  end
end

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

  scene :tree do
    tree = Ray::Image.new window.size
    tree.turtle do
      pen_up
      left 90
      center
      backward 180
      pen_down
      tree(240.0)
    end

    @sprite = sprite tree

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

  push_scene :tree
end

Version data entries

4 entries across 4 versions & 1 rubygems

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