Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created March 26, 2014 13:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emad-elsaid/9783169 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9783169 to your computer and use it in GitHub Desktop.
Draw a Moving line with mouse using Ruby and Gosu gem
#!/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