Skip to content

Instantly share code, notes, and snippets.

@DanielVartanov
Created March 15, 2014 12:26
Show Gist options
  • Save DanielVartanov/9566380 to your computer and use it in GitHub Desktop.
Save DanielVartanov/9566380 to your computer and use it in GitHub Desktop.
class Graphics < Struct.new(:screen)
def initialize(*args)
super
extend_point_class
end
def extend_point_class
screen_centre = screen.size.map { |axis| axis / 2 }
point_extension = Module.new do
define_method :to_screen_coordinates do
[screen_centre[0] + x, screen_centre[1] - y]
end
end
::Geometry::Point.class_eval do
include point_extension
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment