Sha256: d145ace98394b97df13584c98956254f1778ec726cce32e0b1db238c9ca09edc

Contents?: true

Size: 1.94 KB

Versions: 186

Compression:

Stored size: 1.94 KB

Contents

# Note: this requires you to have Gosu and TexPlay installed.
# `gem install gosu`
# `gem install texplay`
#
# 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! :)

require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))

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

  import_from Pry::Commands, "ls", "!"
end

class WinClass < Gosu::Window

  def initialize
    super(WIDTH, HEIGHT, false)
    @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)

    @pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
  end

  def draw
    @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
  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()`
    @pry_instance.rep(@binding)
  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\")"

w = WinClass.new
w.show

Version data entries

186 entries across 186 versions & 1 rubygems

Version Path
pry-0.9.10 examples/example_image_edit.rb
pry-0.9.10-i386-mswin32 examples/example_image_edit.rb
pry-0.9.10-i386-mingw32 examples/example_image_edit.rb
pry-0.9.10-java examples/example_image_edit.rb
pry-0.9.10pre1 examples/example_image_edit.rb
pry-0.9.10pre1-i386-mswin32 examples/example_image_edit.rb
pry-0.9.10pre1-i386-mingw32 examples/example_image_edit.rb
pry-0.9.10pre1-java examples/example_image_edit.rb
pry-0.10.pre.1-i386-mingw32 examples/example_image_edit.rb
pry-0.10.pre.1-java examples/example_image_edit.rb
pry-0.10.pre.1-i386-mswin32 examples/example_image_edit.rb
pry-0.9.9.6 examples/example_image_edit.rb
pry-0.9.9.6-i386-mswin32 examples/example_image_edit.rb
pry-0.9.9.6-i386-mingw32 examples/example_image_edit.rb
pry-0.9.9.6-java examples/example_image_edit.rb
pry-0.9.9.6pre2 examples/example_image_edit.rb
pry-0.9.9.6pre2-i386-mswin32 examples/example_image_edit.rb
pry-0.9.9.6pre2-i386-mingw32 examples/example_image_edit.rb
pry-0.9.9.6pre2-java examples/example_image_edit.rb
pry-0.9.9.6pre1 examples/example_image_edit.rb