From: Martin DeMello Date: 2006-09-09T18:26:20+09:00 Subject: Re: DRAW 1280, 1024 On 9/9/06, Benjohn Barnes wrote: > 20 years ago, the subject line would have drawn me a line across one > of my screen's diagonals. Ruby is awesomely more powerful than BBC > BASIC, but why no trivial graphics support? > > My two requirements are that it should be really easy to draw, and it > should be possible to do so interactively (from irb). You could build something atop Rubygame [ http://rubygame.seul.org/ ] fairly easily. In fact you could probably write a BBC graphics emulator, though the cursor-based thing would seem slightly odd in this day and age :) A QBasic graphics emulator otoh might be a worthwhile effort - IIRC it was pretty well thought-out and simple to use. Here's a quick example using plain Rubygame: irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'rubygame' => false irb(main):003:0> Rubygame.init => nil irb(main):004:0> screen = Rubygame::Screen.set_mode([640, 480]) => # irb(main):005:0> red = [255, 0, 0] => [255, 0, 0] irb(main):006:0> Rubygame::Draw.line(screen, [0, 0], [639, 479], red) => # irb(main):007:0> screen.update => # The simplest way would be to have a class that automatically initialized a screen and held it as an instance variable, and a set of methods that wrapped the methods in Rubygame::Draw but passed in the default screen and remembered the last colour that was used in case no colour was supplied. For example ------------------------------------------------------------------------------------------- require 'rubygems' require 'rubygame' class Sketchpad def initialize(x,y) @screen = Rubygame::Screen.set_mode([x, y]) @color = [255, 255, 255] #white Thread.new { loop { @screen.update sleep 0.01 } } end def line(x1, y1, x2, y2, color=@color) @color = color Rubygame::Draw.line(@screen, [x1, y1], [x2, y2], @color) @screen.update end end ------------------------------------------------------------------------------------------- irb(main):001:0> require 'sketchpad.rb' => true irb(main):002:0> s = Sketchpad.new(640, 480) => #> irb(main):003:0> s.line(0, 0, 639, 479) => # irb(main):004:0> s.line(0, 479, 639, 0, [0, 0, 255]) => # martin