2011-01-20 09:41:41 -05:00
|
|
|
# Note: this requires you to have Gosu and TexPlay installed.
|
|
|
|
# `gem install gosu`
|
|
|
|
# `gem install texplay`
|
2011-06-02 11:22:59 -04:00
|
|
|
#
|
2011-01-20 09:41:41 -05:00
|
|
|
# Extra instructions for installing Gosu on Linux can be found here:
|
|
|
|
# http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
|
|
|
|
#
|
|
|
|
# Instructions for using TexPlay can be found here:
|
|
|
|
# http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
|
|
|
|
#
|
|
|
|
# Have fun! :)
|
|
|
|
|
2011-06-02 11:22:59 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2011-01-20 09:41:41 -05:00
|
|
|
|
|
|
|
WIDTH = 640
|
|
|
|
HEIGHT = 480
|
|
|
|
|
|
|
|
IMAGE_PROMPT = [ proc { "(image edit)> " }, proc { "(image edit)* " } ]
|
|
|
|
|
|
|
|
class ImageCommands < Pry::CommandBase
|
|
|
|
command "drawing_methods", "Show a list of TexPlay methods" do
|
|
|
|
output.puts "#{Pry.view(TexPlay.public_instance_methods)}"
|
|
|
|
end
|
|
|
|
|
|
|
|
command "exit", "Exit the program." do
|
|
|
|
output.puts "Thanks for dropping by!"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2011-02-16 16:22:59 -05:00
|
|
|
import_from Pry::Commands, "ls", "!"
|
2011-01-20 09:41:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class WinClass < Gosu::Window
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(WIDTH, HEIGHT, false)
|
2011-02-16 16:22:59 -05:00
|
|
|
@img = TexPlay.create_image(self, 200, 200).clear :color => :black
|
|
|
|
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
|
|
|
|
|
|
|
@binding = Pry.binding_for(@img)
|
2011-06-02 11:22:59 -04:00
|
|
|
|
2011-01-20 09:41:41 -05:00
|
|
|
@pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2011-06-02 11:22:59 -04:00
|
|
|
@img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
|
2011-01-20 09:41:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
exit if button_down?(Gosu::KbEscape)
|
|
|
|
|
|
|
|
# We do not want a REPL session as the loop prevents the image
|
|
|
|
# being updated; instead we do a REP session, and let the image
|
|
|
|
# update each time the user presses enter. We maintain the same
|
|
|
|
# binding object to keep locals between calls to `Pry#rep()`
|
2011-02-16 16:22:59 -05:00
|
|
|
@pry_instance.rep(@binding)
|
2011-01-20 09:41:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Welcome to ImageEdit; type `help` for a list of commands and `drawing_methods` for a list of drawing methods available."
|
|
|
|
puts "--"
|
|
|
|
puts "Example: Try typing 'circle width/2, height/2, 95, :color => :blue, :fill => true'"
|
|
|
|
puts "If you want to save your image, type: save(\"img.png\")"
|
|
|
|
|
2011-02-13 10:49:53 -05:00
|
|
|
w = WinClass.new
|
|
|
|
w.show
|
2011-01-20 09:41:41 -05:00
|
|
|
|