Skip to content

Commit

Permalink
Bump up to JRubyArt-1.4.9, processing-3.3.7 and jruby-9.1.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed May 9, 2018
1 parent 1eb21b3 commit ee8814f
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.3-p392
2.3.3
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ simple live coding
===============

This is a proof of concept for a live drawing app in Ruby with
the [Ruby-Processing Gem (based on processing-2.0.1, and jruby-1.7.4)](https://github.com/monkstone/ruby-processing)
the [JRubyArt Gem (based on processing-3.3.7, and jruby-9.1.17.0)](https://github.com/ruby-processing/JRubyArt)

Get inspired by [Bret Victor](http://worrydream.com/#!/LearnableProgramming) or join the project with your own idea..

Expand All @@ -16,7 +16,7 @@ With "ellipse 50, 50, 80, 80" or "rect/line/fill" you can draw and with mouse dr
Notice
===============

Start Ruby-Processing with "rp5 watch simple_live_coding.rb". This reloads "simple_live_coding.rb" after safing and you can implement your ideas in this file
Start JRubyArt with `k9 -w simple_live_coding.rb`. This reloads `simple_live_coding.rb` after saving and you can implement your ideas in this file
without need to restart. After implementation of the new feature just copy your code in a seperate file in the "main" directory and do "require_relative" for the file.

This is live coding a live coding app...
This is a live coding app...
3 changes: 1 addition & 2 deletions main/canvas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ def send_if_runnable(methode, args)
puts "#{ e } (#{ e.class })!"
end
end

end
end
8 changes: 4 additions & 4 deletions main/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class Cursor

def initialize(line)
@line = line
@x = $app.start_of_editor_text
@y = $app.editor_top_margin
@x = Processing.app.start_of_editor_text
@y = Processing.app.editor_top_margin
end

def set_position(x,y) #on mouse down
Expand All @@ -30,11 +30,11 @@ def draw_line
end

def go_to_new_line #after tap enter button
@y += $app.line_height+$app.line_space
@y += Processing.app.line_height+Processing.app.line_space
end

def go_to_previous_line
@y -= $app.line_height+$app.line_space
@y -= Processing.app.line_height+Processing.app.line_space
end

private
Expand Down
6 changes: 3 additions & 3 deletions main/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def draw_content
def draw_text
@lines.elements.each do |str_obj|
eval("text '#{str_obj.content}',
#{$app.width/2},
#{Processing.app.width/2},
#{str_obj.get_position.to_a.last}")
end
end

def draw_explanation
return eval("text '#{@description.explanation}',
#{$app.width-@description.explanation_length-$app.editor_right_margin},
#{@description.position+$app.editor_top_margin}")
#{Processing.app.width-@description.explanation_length-Processing.app.editor_right_margin},
#{@description.position+Processing.app.editor_top_margin}")

end
end
6 changes: 3 additions & 3 deletions main/lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class Lines

def initialize
@elements = []
@line_height = $app.line_height
@line_space = $app.line_space
@line_height = Processing.app.line_height
@line_space = Processing.app.line_space
@positiontable = generate_hashtable
initialize_positiontable
end
Expand All @@ -21,7 +21,7 @@ def position(x,y)
#get the linge and extract x, y param
line_range = @positiontable[y].get_position
y = line_range.to_a.last
[$app.start_of_editor_text, y]
[Processing.app.start_of_editor_text, y]
end

def make_new_line(cursor)
Expand Down
8 changes: 4 additions & 4 deletions main/string_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def methode

def update_param(x_mouse, y_mouse)
#Try to find beginn of param and set this as the char_position to prevent unintendet param change!!!
char_position = find_char($app.pressed[0])
char_position = find_char(Processing.app.pressed[0])
found_number = find_number(char_position) unless char_position.nil?
if found_number and found_number != [0..0]
new_param_value = -$app.width/2+x_mouse-length($app.initial_param[:string])+$app.initial_param[:value]
new_param_value = -Processing.app.width/2+x_mouse-length(Processing.app.initial_param[:string])+Processing.app.initial_param[:value]
begin_of_param = found_number[0].first
current_param_length = @content[found_number[0]].to_s.length
@content[begin_of_param, current_param_length] = new_param_value.to_s
Expand All @@ -34,7 +34,7 @@ def update_param(x_mouse, y_mouse)

def get_param_values
#get the rigth param of x position and give the value back
char_position = find_char($app.pressed[0])
char_position = find_char(Processing.app.pressed[0])
if char_position
found_number = find_number(char_position)[0]
unless found_number == [0..0]
Expand Down Expand Up @@ -63,7 +63,7 @@ def length(s)
end

def update_char_position
start_position = $app.width/2
start_position = Processing.app.width/2
char_length_new = 0
@char_position = Hash.new {|this_hash,missing_key| #set always a new hash to keep track of growing numbers
found_key = this_hash.keys.find {|this_key| this_key.class == Range && this_key.include?(missing_key) }
Expand Down
4 changes: 2 additions & 2 deletions main/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(lines, description, cursor)
end

def check_line(x, y)
if x > ($app.width/2) + $app.editor_left_margin
if x > (Processing.app.width/2) + Processing.app.editor_left_margin
if @lines.positiontable(y) == :undefined
@description.position = [-50] # set it outside the view field
else
Expand All @@ -19,7 +19,7 @@ def check_line(x, y)
def check_param(x,y)
y_position = @cursor.y_position
string_object = @lines.positiontable(y_position)
if (string_object.position[0]).include?($app.pressed[1])
if (string_object.position[0]).include?(Processing.app.pressed[1])
string_object.update_param(x,y) unless string_object == :undefined
end
end
Expand Down
24 changes: 14 additions & 10 deletions simple_live_coding.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'ruby-processing'
require 'jruby_art'

class RubyDraw < Processing::App

Expand All @@ -13,8 +13,12 @@ class RubyDraw < Processing::App

attr_reader :editor_left_margin, :editor_right_margin, :editor_top_margin, :start_of_editor_text, :line_height, :line_space, :pressed, :initial_param

def settings
size 700, 600 # access with Processing.app.width
end

def setup
size 700, 600 # access with $app.width
sketch_title 'Simple Live Coding'
@editor_left_margin = 10
@editor_right_margin = 15
@editor_top_margin = 15
Expand All @@ -37,32 +41,32 @@ def setup
#initial drawing for testing:
"rect 20, 30, 30, 40".chars.each{ |c| @parser.update_line(c, 0) }
end

def draw
background 55
@canvas.draw_canvas
fill color 304, 353, 300
rect ($app.width/2)-10,0,($app.width/2)+10,height
rect (Processing.app.width/2)-10,0,(Processing.app.width/2)+10,height
fill color 104, 153, 0
@editor.draw_content

text mouse_x.to_s, $app.width/2, $app.height-60
text "this is a DEMO app", $app.width/2, $app.height-40
text "write 'rect 20, 20, 200, 200' and drag the values...", $app.width/2, $app.height-20
text mouse_x.to_s, Processing.app.width/2, Processing.app.height-60
text "this is a DEMO app", Processing.app.width/2, Processing.app.height-40
text "write 'rect 20, 20, 200, 200' and drag the values...", Processing.app.width/2, Processing.app.height-20

fill color 14, 13, 0
@cursor.draw_line #we need a line marking the text position
fill color 104, 153, 0

if mouse_pressed?
sleep(0.12) #needed because of unintented param change line selection
sleep(0.12) #needed because of unintented param change line selection
loop
@watcher.check_param(mouse_x, mouse_y)
else
@pressed = false
no_loop
end

end

def key_pressed
Expand All @@ -84,4 +88,4 @@ def mouse_pressed

end

RubyDraw.new :title => "simple_live_coding"
RubyDraw.new
2 changes: 1 addition & 1 deletion spec/simple_live_coding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe "app" do
it "should open window" do
$app.width.should == 700
Processing.app.width.should == 700
end
end

Expand Down

2 comments on commit ee8814f

@monkstone
Copy link
Owner Author

@monkstone monkstone commented on ee8814f May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcel12bell just bumped your ruby-processing app to run on JRubyArt, seems to to work after a fashion, changes:-

Since processing-3.0 need settings to define sketch size (can set hidpi resolution if reqd). I refactored $app to Processing.app (but you should not need to call it too much, Processing::Proxy makes width and height available.

@marcel12bell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Long time ago since I looked into it...

Please sign in to comment.