Ron Jeffries <ronjeffries / acm.org> writes: > Hi ... > > I'd like to implement Langston's Ant in Ruby. To do this I need to > display the path of the ant on the screen. Basically this consists of > setting the color of a (large) pixel to one of a couple of colors. > > What's an easy way in Ruby to draw some pixels on the screen or in a > window. > > Hint: No "easy way" could possibly include the sequence of characters > "tcl". OK you old curmudgeon, how about: require 'tk' class AntFarm SIZE=10 def initialize(root) @canvas = TkCanvas.new(root) { width 20*SIZE height 20*SIZE }.pack end def drawAntAt(x, y, color) TkcRectangle.new(@canvas, x*SIZE, y*SIZE, (x+1)*SIZE, (y+1)*SIZE) { fill color } end end root = TkRoot.new { title "Ant Farm" } farm = AntFarm.new(root) ant_drawer = proc { x = rand(20) y = rand(20) color = %w{ red green blue white }[rand(4)] farm.drawAntAt(x, y, color) Tk.after(500, &ant_drawer) } ant_drawer.call Tk.mainloop Not a 'tcl' in sight. Dave :)