Created
March 26, 2014 13:31
-
-
Save emad-elsaid/9783169 to your computer and use it in GitHub Desktop.
Draw a Moving line with mouse using Ruby and Gosu gem
This file contains hidden or 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/env ruby | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
require 'gosu' | |
include Gosu | |
$dimension = 200 | |
$line_limit = 70 | |
class GameWindow < Window | |
def initialize | |
super $dimension, $dimension, false | |
self.caption = "Drawing board" | |
@points = [] | |
end | |
def update | |
@points << [ mouse_x, mouse_y ] | |
@points.shift if @points.size > $line_limit | |
end | |
def draw | |
return if @points.empty? | |
@points.inject(@points[0]) do |last, point| | |
draw_line last[0],last[1], Color::GREEN, | |
point[0],point[1], Color::GREEN | |
point | |
end | |
end | |
end | |
GameWindow.new.show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment