Draw a Moving line with mouse using Ruby and Gosu gem
Join the DZone community and get the full member experience.Join For Free
#!/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) do |last, point| draw_line last,last, Color::GREEN, point,point, Color::GREEN point end end end GameWindow.new.show
Opinions expressed by DZone contributors are their own.