Sha256: 81e673771334d79b6ba25de9d55d80b7c307d175f32330acdb16e9fa38907884
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
#!/usr/local/bin/ruby -w # -*- coding: utf-8 -*- require "graphics" $: << "." require "examples/editor" class Turtle < Graphics::Body attr_accessor :src, :pen def initialize w, src super w self.x = w.w/2 self.y = w.h/2 self.a = 90 self.src = src self.pen = true end def draw self.x = w.w/2 self.y = w.h/2 self.a = 90 src.each do |line| case line when "pd" then self.pen = true when "pu" then self.pen = false when /rt (\d+)/ then self.a -= $1.to_i when /lt (\d+)/ then self.a += $1.to_i when /f (\d+)/ then dist = $1.to_i if pen then w.angle x, y, a, dist, :white end move_by a, dist else src.delete line warn "ERROR: #{line}" end end draw_turtle end def draw_turtle p1 = w.project(x, y, a, 15) p2 = w.project(x, y, a+90, 5) p3 = w.project(x, y, a-90, 5) polygon p1, p2, p3, :green end end class Logo < Editor attr_accessor :turtle def initialize super self.turtle = Turtle.new self, lines end def draw_scene turtle.draw end end if $0 == __FILE__ Logo.new.run end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
graphics-1.0.0b1 | examples/logo.rb |