Sha256: 39f5356cb76274e10f404f76b527d33aa4b7d49d08c7811abbe5b11da51f2679

Contents?: true

Size: 1.97 KB

Versions: 111

Compression:

Stored size: 1.97 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! :)

direc = File.dirname(__FILE__)

require 'rubygems'
require "texplay"
require "#{direc}/../lib/pry"

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

111 entries across 111 versions & 1 rubygems

Version Path
pry-0.7.6.1-java examples/example_image_edit.rb
pry-0.7.6.1 examples/example_image_edit.rb
pry-0.7.6.1-i386-mswin32 examples/example_image_edit.rb
pry-0.7.6.1-i386-mingw32 examples/example_image_edit.rb
pry-0.7.6-java examples/example_image_edit.rb
pry-0.7.6-i386-mswin32 examples/example_image_edit.rb
pry-0.7.6 examples/example_image_edit.rb
pry-0.7.6-i386-mingw32 examples/example_image_edit.rb
pry-0.7.5.3-java examples/example_image_edit.rb
pry-0.7.5.3 examples/example_image_edit.rb
pry-0.7.5.3-i386-mingw32 examples/example_image_edit.rb
pry-0.7.5.3-i386-mswin32 examples/example_image_edit.rb
pry-0.7.5.2-java examples/example_image_edit.rb
pry-0.7.5.2-i386-mswin32 examples/example_image_edit.rb
pry-0.7.5.2-i386-mingw32 examples/example_image_edit.rb
pry-0.7.5.2 examples/example_image_edit.rb
pry-0.7.4-i386-mswin32 examples/example_image_edit.rb
pry-0.7.4 examples/example_image_edit.rb
pry-0.7.4-i386-mingw32 examples/example_image_edit.rb
pry-0.7.4-java examples/example_image_edit.rb