Created
February 2, 2010 22:32
-
-
Save anonymous/293118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# Plot random pixels. | |
require ‘rubygame‘ | |
Width = 640 | |
Height = 400 | |
module Rubygame | |
class Surface | |
def put_pixel(point, color) | |
self.draw_box point, point, color | |
end | |
end | |
end | |
class RandomPixels | |
include Rubygame | |
def initialize | |
@screen = Screen.new [Width, Height] | |
@events = EventQueue.new | |
@screen.fill [0, 0, 0] | |
@screen.update | |
end | |
def event_loop | |
loop do | |
@events.each { |event| | |
case event | |
when QuitEvent | |
return | |
end | |
} | |
draw | |
@screen.update | |
end | |
end | |
def draw | |
point = [rand(Width), rand(Height)] | |
color = [rand(255), rand(255), rand(255)] | |
@screen.put_pixel point, color | |
end | |
end | |
Rubygame.init | |
RandomPixels.new.event_loop | |
Rubygame.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment