Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save baroquebobcat/636681 to your computer and use it in GitHub Desktop.
# http://gist.github.com/636681
# http://tinyurl.com/learn-ruby-processing
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
o.stroke 255, 0, 0 #Red outline
o.fill 0, 0, 255 #Blue center
o.ellipse 100, 50, 200, 400 #Tall oval
o.rect 350, 100, 400, 200 #Wide rectangle
o.line 0, 0, o.width, o.height #line across
#"gem install rubyonacid" first!
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
require 'rubyonacid/factories/example'
f = RubyOnAcid::ExampleFactory.new
o.no_stroke
max_x, max_y = o.width, o.height
loop do
o.fill(
f.get(:red, :max => 255),
f.get(:green, :max => 255),
f.get(:blue, :max => 255),
f.get(:alpha, :min => 50, :max => 200)
)
x = f.get(:x, :max => max_x)
y = f.get(:y, :max => max_y)
width = f.get(:width, :max => 200)
height = f.get(:height, :max => 200)
case f.choose(:shape, :rectangle, :ellipse)
when :rectangle
o.rect_mode 3 #CENTER
o.rect x, y, width, height
when :ellipse
o.ellipse_mode 3 #CENTER
o.ellipse x, y, width, height
end
end
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
o.background 0
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
o.stroke 0
o.background 0
o.fill 50, 255, 100
o.translate 200, 200
o.rotate 3.14 / 5.0
o.rect 50, 50, 75, 100
o.smooth
o.ellipse 40, 20, 16, 16
o.line 90, 150, 80, 160
o.text_font o.create_font "Courier", 72, true
o.text "foo", 10, 100
puts "mouse_x: #{o.mouse_x}, mouse_y: #{o.mouse_y}, pmouse_x: #{o.pmouse_x}, pmouse_y: #{o.pmouse_y}"
puts "width: #{o.width}, height: #{o.height}"
puts "random(255): #{o.random(255)}"
puts "constrain(300, 0, 255): #{o.constrain(300, 0, 255)}"
puts "millis: #{o.millis}"
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
#sample.jpg must exist in data/ directory.
image = o.load_image("sample.jpg")
o.image(image, 10, 20)
require "ruboto.rb"
confirm_ruboto_version(4, false)
java_import "org.ruboto.embedded.RubotoView"
require 'drb'
DRb.start_service
$activity.start_ruboto_activity "$druby" do
setup_content do
@service = DRbObject.new(nil, "druby://192.168.0.100:9000")
RubotoView.new($druby)
end
handle_touch_event do |event|
@service.fill 50, 255, 100
@service.stroke 50, 255, 100
@service.ellipse event.get_x, event.get_y, 16, 16
end
end
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
max_x, max_y = o.width, o.height
loop do
o.stroke 0
o.fill 155
o.ellipse rand(max_x), rand(max_y), rand(100), rand(100)
end
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
text = $<.read
o.fill 0, 0, 0, 240
o.text_font o.create_font "Courier", 32, true
o.text text, 12, 52
o.fill 255, 255, 255, 240
o.text text, 10, 50
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
width, height = o.width, o.height
require 'tk'
canvas = TkCanvas.new(:width => 640, :height => 440)
canvas.pack
canvas.bind(
"B1-Motion",
lambda { |x, y|
o.ellipse(
width * (x.to_f / canvas.width),
height * (y.to_f / canvas.height),
50, 50
)
},
"%x %y"
)
Tk.mainloop
@bkerley
Copy link

bkerley commented Nov 12, 2010

require 'drb'
o = DRbObject.new(nil, 'druby://192.168.66.245:9000')
text = "BRYCE"
o.text_font o.create_font "Helvetica", 64, true
(0..10).each do |i|
  o.fill 255-(10*i), 255-(5*i), 255-(25*i), 240
 o.text text, 10+(5*i), 50+(15*i)
end

@bkerley
Copy link

bkerley commented Nov 12, 2010

require 'drb'
o = DRbObject.new(nil, 'druby://192.168.66.245:9000')
text = "//BRYCE web 2.0"
o.text_font o.create_font "Helvetica", 64, true
(0..2).each do |i|
  o.fill 255-(100*i), 255-(50*i), 255-(120*i), 240
  o.text text, 80+(5*i), 100+(15*i)
end
o.stroke 255, 255, 255
o.line 30, 50, 120, 50
o.line 120,50, 90, 20
o.line 120, 50, 90, 80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment