BaubleBlog/0000755000076500007650000000000011040652214013225 5ustar unclebobunclebobBaubleBlog/Bauble-0.1.gem0000644000076500007650000000600011040652214015401 0ustar unclebobunclebobdata.tar.gz0000644000000000000000000000075500000000000013326 0ustar00wheelwheel00000000000000/~HSQk0b,/-#c CdRkN'-즱S7 βVռXi`dLú?|Z`D Q9T{(T/Z+C\v-EYrX{: BCBe2shQBvӾjllN@6\V9SwMW!̝?$/`tL7ne փݥd9>:`@\0p|v7ElvL ńַm*^Joͻ޶«Zh݁ïg Ɇfw@w >m|kpoye%~CC|Ylf>#e(X22;.`,tzg!5$`4EJej$JA3<N  metadata.gz0000644000000000000000000000065100000000000013403 0ustar00wheelwheel00000000000000/~HSKo0ϯ0;V* K(Tₐe;3Ix&|#s&U};">iAc֨bc`G>OLa_O ;?t8U1yZZ昲`Y ơ9c&Jdچ&2mH3+K_v?e և^0QUW$E%q0b0΃$U.W։[}Mpa`h^dG{FG*Y}' +V*=.jjJ!^*wޛ&UsQWyldqxu}w *IμhY'h+!%zlv 6LOz zAY~qrDZ)=_/yUBaubleBlog/cellular_automaton/0000755000076500007650000000000011040651775017132 5ustar unclebobunclebobBaubleBlog/cellular_automaton/Cellular_automaton.iml0000644000076500007650000000145711040651775023476 0ustar unclebobunclebob BaubleBlog/cellular_automaton/cellular_automaton.ipr0000644000076500007650000005150511040651775023546 0ustar unclebobunclebob BaubleBlog/cellular_automaton/cellular_automaton.iws0000644000076500007650000004737111040651775023564 0ustar unclebobunclebob BaubleBlog/cellular_automaton/lib/0000755000076500007650000000000011022371066017670 5ustar unclebobunclebobBaubleBlog/cellular_automaton/lib/cell_panel.rb0000644000076500007650000000077611022370764022331 0ustar unclebobunclebob class CellPanel < JPanel def init(xcells, ycells, cell_size, clear_screen, world_class) @xcells = xcells @ycells = ycells @cell_size = cell_size @clear_screen = clear_screen @world_class = world_class @world = world_class.new(xcells, ycells) end def paintComponent(g) super if @clear_screen @screen = g @world.step(self) end def draw_cell(x,y,color) @screen.setColor(color) @screen.fillRect(x*@cell_size, y*@cell_size, @cell_size, @cell_size) end endBaubleBlog/cellular_automaton/lib/cellular_automaton.rb0000644000076500007650000000236311022371251024107 0ustar unclebobunclebobrequire 'helper' require 'cell_panel.rb' class CellularAutomaton def initialize @mutex = Mutex.new @swing_is_running = ConditionVariable.new @cellPanel = CellPanel.new end def title(title) @title = title end def world_size(xcells, ycells) @xcells = xcells; @ycells = ycells; end def cell_size(cell_size) @cell_size = cell_size end def clear_screen_each_step(clear_screen) @clear_screen = clear_screen end def world(world_class) @world_class = world_class end def makeFrame @frame = JFrame.new @title @frame.set_size(@xcells*@cell_size, @ycells*@cell_size) @frame.default_close_operation = JFrame::EXIT_ON_CLOSE @cellPanel.init(@xcells, @ycells, @cell_size, @clear_screen, @world_class) @frame.add @cellPanel @frame.show @swing_is_running.signal end def wait_for_swing_to_start_running @mutex.synchronize do @swing_is_running.wait(@mutex) end end def run wait_for_swing_to_start_running while (true) @frame.repaint Thread.yield end end def self.start(&proc) frame = CellularAutomaton.new frame.instance_eval(&proc) javax.swing.SwingUtilities.invokeLater(proc {frame.makeFrame}) frame.run end end BaubleBlog/cellular_automaton/lib/helper.rb0000644000076500007650000000042511022370764021501 0ustar unclebobunclebobrequire 'java' require 'thread' include_class ['javax.swing.JFrame', 'javax.swing.JLabel', 'javax.swing.JButton', 'javax.swing.JPanel'] include_class ['java.lang.Runnable', 'javax.swing.SwingUtilities', 'java.awt.Graphics', 'java.lang.Thread'] include_class ['java.awt.Color']BaubleBlog/LangtonsAnt/0000755000076500007650000000000011040652134015456 5ustar unclebobunclebobBaubleBlog/LangtonsAnt/LangtonsAnt.iml0000644000076500007650000000132111012451437020410 0ustar unclebobunclebob BaubleBlog/LangtonsAnt/LangtonsAnt.ipr0000644000076500007650000005105311012447207020430 0ustar unclebobunclebob BaubleBlog/LangtonsAnt/LangtonsAnt.iws0000644000076500007650000005341311040652134020440 0ustar unclebobunclebob BaubleBlog/LangtonsAnt/langtonsAnt.rb0000644000076500007650000000233411040643742020302 0ustar unclebobunclebobrequire 'rubygems' require 'bauble' Bauble.use('../cellular_automaton') class AntWorld def initialize(xcells, ycells) @xcells = xcells @ycells = ycells @world = [] @xcells.times {@world << []} @x = @xcells/2 @y = @ycells/2 @direction = 0 end def step(screen) @screen = screen if (white?) blacken turn_right else whiten turn_left end end def white? cell = @world[@x][@y] cell == nil || cell == true end def whiten @world[@x][@y] = true white_cell end def blacken @world[@x][@y] = false black_cell end def white_cell @screen.draw_cell(@x, @y, Color.white) end def black_cell @screen.draw_cell(@x, @y, Color.black) end def turn_right @direction += 90 move end def turn_left @direction -= 90 move end def move @direction %= 360 case @direction when 0 @x = (@x + 1) % @xcells when 90 @y = (@y + 1) % @ycells when 180 @x = (@x - 1) % @xcells when 270 @y = (@y - 1) % @ycells end end end CellularAutomaton.start do title "Langton's Ant" world_size(1000,1000) cell_size(1) clear_screen_each_step false world AntWorld end BaubleBlog/LangtonsAnt/spec/0000755000076500007650000000000010770540705016421 5ustar unclebobunclebob