Sha256: 2439e65e4320d0ba26f448113ab1f6892239650e603c84334aebe4af82502900
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
#!/usr/local/bin/ruby -w # -*- coding: utf-8 -*- srand 42 require "graphics" ## # Virtual Ants -- inspired by a model in NetLogo. class Vant < Graphics::Body COUNT = 100 M = 1 attr_accessor :white, :black, :red, :s def initialize w super self.a = random_angle self.s = w.screen self.white = w.color[:white] self.black = w.color[:black] end def forward move_by a, M mutate end def mutate if s[x, y] == white then s[x, y] = black turn 270 else s[x, y] = white turn 90 end end end class Vants < Graphics::Simulation attr_accessor :vs def initialize super 850, 850, 16, self.class.name # cheat and reopen screen w/o double buffering self.screen = SDL::Screen.open 850, 850, 16, SDL::HWSURFACE clear :white self.vs = populate Vant end def update n vs.each(&:forward) end def draw_and_flip n self.draw n # no flip end def draw n screen.update 0, 0, 0, 0 end end Vants.new.run if $0 == __FILE__
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
graphics-1.0.0b5 | examples/vants.rb |
graphics-1.0.0b4 | examples/vants.rb |