RubyGem 'Salamander' がようやく動いたよ
RubyGem 'Salamander' が動かないよ - Marginalia
RubyGem の Turtle グラフィックス・ライブラリの使い方がわからないかったのだが、ようやく動き始めた。
例えばこんな感じ。
require 'bundler/setup' require 'salamander' include Salamander include Salamander::Drawing screen = Salamander.setup(410, 410) Actor.draw(screen) do color :cyan circle 200 color :green circle 150 color :red circle 100 color :magenta circle 50 end screen.redraw while true event = SDL.WaitEvent break if event.type == SDL::QUIT end
こんなのは。
require 'bundler/setup' require 'salamander' require 'salamander/support/radians' include Salamander include Salamander::Drawing::Shapes screen = Salamander.setup(300, 300) Actor.draw(screen) do 4.times do [:red, :green, :cyan, :magenta, :blue].each do |c| color c star 15, 100 turn 18.degrees end end end screen.redraw while true event = SDL.WaitEvent break if event.type == SDL::QUIT end
こんなのも。
require 'bundler/setup' require 'salamander' include Salamander include Salamander::Drawing class Actor def grid(width, height, cells) origin = position (cells - 1).times do turn :right move height / cells.to_f turn :left line width turn :around move width turn :around end move_to *origin turn :right (cells - 1).times do turn :left move width / cells.to_f turn :right line height turn :around move height turn :around end move_to *origin turn :left end def main(screen) move_to 0, 0 face :east grid screen.w, screen.h, 5 end end canvas = Salamander.setup(300, 300) Actor.new(canvas).main(canvas.surface) canvas.redraw while true event = SDL.WaitEvent break if event.type == SDL::QUIT end
以上はここにある samples を手直しして頑張って走るようにしたもの。一生懸命にソースコードを読んでやりましたよ。自分には相当にわかりにくかった。実力のある人ならともかく、複雑に require したり include しなければならないのがまるで暗号を解くような感じ。ソースを読まないと使えないって、初心者に対してやさしくないですね。
degree メソッドを使うのに require 'salamander/support/radians' しないといけないなんて、そんなのわかるかっての。