Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/monkstone/ruby-processing
Former-commit-id: d7f94f2 Former-commit-id: 3d23e194accc9f240cd5484089f9e58617ded3a1
- Loading branch information
Showing
5 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Xms256m -Xmx256m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
################################################ | ||
# extrude.rb is a processing sketch that shows | ||
# how you can use the anar library in ruby processing | ||
# see README.txt for more details | ||
################################################ | ||
|
||
load_libraries 'anar', 'opengl' | ||
import "anar" if library_loaded? "anar" | ||
import "processing.opengl" if library_loaded? "opengl" | ||
|
||
attr_accessor :my_obj | ||
full_screen | ||
|
||
def setup() | ||
library_loaded?(:opengl) ? setup_opengl : fail_opengl | ||
frame_rate(200) | ||
|
||
Anar.init(self) | ||
Anar.draw_axis(true) | ||
|
||
init_form() | ||
end | ||
|
||
def setup_opengl | ||
render_mode OPENGL | ||
hint ENABLE_OPENGL_4X_SMOOTH #optional | ||
hint DISABLE_OPENGL_ERROR_REPORT #optional | ||
end | ||
|
||
def init_form() | ||
|
||
#Create a new Line | ||
pts = Pts.new | ||
|
||
pts.add(Anar.Pt(100,110,20)) | ||
pts.add(Anar.Pt(110,100,40)) | ||
pts.add(Anar.Pt(110,90,60)) | ||
pts.add(Anar.Pt(90,90,90)) | ||
#Create a Face | ||
f = Star.new(50,100,5) | ||
#Extrude the face along the Line | ||
@my_obj = Extrude.new(f,pts) | ||
Anar.cam_target(my_obj) | ||
Anar.sliders(my_obj) | ||
end | ||
|
||
def draw() | ||
background(155) | ||
my_obj.draw() | ||
end | ||
|
||
def fail_opengl | ||
abort "!!!You absolutely need opengl for this sketch!!!" | ||
end | ||
|
||
#Toggle the display of the sliders | ||
def keyPressed() | ||
Anar.sliders_toggle() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
################################################ | ||
# l_sys_block.rb is a processing sketch that shows | ||
# how you can use the lsys features of the anar | ||
# library in ruby processing see README.txt for | ||
# more details | ||
################################################ | ||
|
||
|
||
load_libraries 'anar', 'opengl' | ||
import "anar" if library_loaded? "anar" | ||
import "lsys.Grammar" if library_loaded? "anar" | ||
import "processing.opengl" if library_loaded? "opengl" | ||
|
||
full_screen | ||
|
||
attr_accessor :my_obj, :grammar, :box, :ts, :tf, :init_t, :rot, :sz | ||
|
||
def setup() | ||
library_loaded?(:opengl) ? setup_opengl : fail_opengl | ||
hint(ENABLE_OPENGL_4X_SMOOTH) | ||
hint(DISABLE_OPENGL_ERROR_REPORT) | ||
Anar.init(self) | ||
Anar.draw_axis(true) | ||
init_grammar() | ||
interpret_init() | ||
end | ||
|
||
def init_grammar() | ||
@grammar = Grammar.new("bt") | ||
# here define the rules | ||
# * means any kind of symbol | ||
# the example rules below are therefore non contextual | ||
grammar.add_rule("*b*", "brb") | ||
grammar.add_rule("*t*", "rssb") | ||
grammar.add_rule("*r*", "rs") | ||
grammar.add_rule("*s*", "s") | ||
# this one makes it context dependant | ||
# grammar.add_rule("sss", "ss") | ||
puts(grammar) | ||
end | ||
|
||
|
||
def interpret_init | ||
# base element | ||
@box = Box.new(10, 10, 50) | ||
# initial position | ||
@init_t = Translate.new(0, 50, 0) | ||
# base transformations | ||
@ts = Translate.new(Anar.Pt(0, 10, -0.001)) | ||
@rot = RotateZ.new(0.5) | ||
@sz = Scale.new(Anar.Pt(0.99, 0.99, 0.99)) | ||
interpret_grammar() | ||
end | ||
|
||
def interpret_grammar() | ||
@my_obj = Obj.new | ||
@tf = Transform.new(init_t) | ||
|
||
grammar.num_of_symbols.times do |i| | ||
|
||
case(grammar.symbol(i)[0].chr) # todo this is bit of hack, I need understand grammar better | ||
when 'b' | ||
my_copy = Obj.new(box, tf) | ||
my_obj.add(my_copy) | ||
@tf = Transform.new(tf) | ||
when 't' | ||
tf.apply(ts) | ||
when 'r' | ||
tf.apply(rot) | ||
when 's' | ||
tf.apply(sz) | ||
else | ||
puts "grammar not understood" | ||
end | ||
end | ||
Anar.cam_target(my_obj) | ||
end | ||
|
||
def draw() | ||
background(153) | ||
my_obj.draw() | ||
end | ||
|
||
|
||
def key_pressed() | ||
if(key==' ') | ||
grammar.step() | ||
interpret_grammar() | ||
puts(grammar) | ||
end | ||
if(key=='r') | ||
grammar.reset() | ||
interpret_init() | ||
interpret_grammar() | ||
puts(grammar) | ||
end | ||
if(key=='p') | ||
save_frame("block.png") | ||
end | ||
if (key=='g') | ||
puts grammar.methods | ||
end | ||
end | ||
|
||
def setup_opengl | ||
render_mode OPENGL | ||
hint ENABLE_OPENGL_4X_SMOOTH #optional | ||
end | ||
|
||
|
||
def fail_opengl | ||
abort "!!!You absolutely need opengl for this sketch!!!" | ||
end |
1 change: 1 addition & 0 deletions
1
samples/processing_app/topics/anar/library/anar/anar.jar.REMOVED.git-id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1c22a52c985c50eede56f3affdc856ff85bab71b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
################################################ | ||
# many_forms.rb is a processing sketch that shows | ||
# how you can use the anar library in ruby processing | ||
# see README.txt for more details | ||
# hold down middle button to control orientation | ||
# of the working surface (prepare to be amazed!!!) | ||
################################################ | ||
|
||
load_libraries 'anar', 'opengl' | ||
import "anar" if library_loaded? "anar" | ||
import "processing.opengl" if library_loaded? "opengl" | ||
|
||
attr_accessor :my_obj, :group | ||
full_screen | ||
|
||
def setup() | ||
library_loaded?(:opengl) ? setup_opengl : fail_opengl | ||
Anar.init(self) | ||
Anar.draw_axis() | ||
Face.globalRender = RenderFaceNormal.new(OogColor.new(255, 100), OogColor.new(100)) | ||
init_form() | ||
end | ||
|
||
def init_form() | ||
@my_obj = Obj.new | ||
@group = Group.new | ||
|
||
################### | ||
#CONE | ||
################### | ||
cone = Cone.new(50,100,20) | ||
cone.set("cone") | ||
cone.translate(100,100,0) | ||
|
||
puts(cone.to_obj_exporter()) | ||
group.add(cone) | ||
|
||
################### | ||
#BOX | ||
################### | ||
box = Box.new(10,20,30) | ||
box.set("box") | ||
box.rotate_z(0) | ||
box.rotate_x(0) | ||
box.translate(100, 0, 0) | ||
puts(box.to_obj_exporter("box")) | ||
puts(box.parent_list(-1)) | ||
group.add(box) | ||
|
||
################### | ||
#CYLINDER | ||
################### | ||
cylinder = Cylinder.new(50, 24, 50) | ||
cylinder.set("cylinder") | ||
cylinder.translate(-100, 0, 0) | ||
puts(cylinder.to_obj_exporter("cylinder")) | ||
group.add(cylinder) | ||
|
||
################### | ||
#ELLIPSE | ||
################### | ||
ellipse = Ellipse.new(40, 20) | ||
ellipse.set("ellipse") | ||
puts(ellipse.to_obj_exporter("ellipse")) | ||
group.add(ellipse) | ||
|
||
################### | ||
#SWISSCROSS3D | ||
################### | ||
swissCross3D = SwissCross3D.new(10, 10) | ||
swissCross3D.set("swissCross3D") | ||
#swissCross3D.fill(255,0,0,200) | ||
puts(swissCross3D.to_obj_exporter("swissCross3D")) | ||
#swissCross3D.translate(-100,0,0) | ||
group.add(swissCross3D) | ||
|
||
################### | ||
#REVOLVER | ||
################### | ||
ctrlRevol = Pts.new() | ||
ctrlRevol.add(Anar.Pt(30,0,30)) | ||
ctrlRevol.add(Anar.Pt(10,0,40)) | ||
ctrlRevol.add(Anar.Pt(20,0,60)) | ||
ctrlRevol.add(Anar.Pt(20,0,70)) | ||
revolver = Revolve.new(ctrlRevol, Anar.Pt(0,0,20), 12) | ||
revolver.set("revolver") | ||
puts(revolver.to_obj_exporter("revolver")) | ||
group.add(revolver) | ||
|
||
################## | ||
################### | ||
my_obj.add(box) | ||
my_obj.add(cone) | ||
my_obj.add(cylinder) | ||
my_obj.add(ellipse) | ||
my_obj.add(swissCross3D) | ||
my_obj.add(revolver) | ||
Anar.sliders(swissCross3D) | ||
Anar.sliders(revolver) | ||
Anar.cam_target(revolver) | ||
end | ||
|
||
def fail_opengl | ||
abort "!!!You absolutely need opengl for this sketch!!!" | ||
end | ||
|
||
def setup_opengl | ||
render_mode OPENGL | ||
hint ENABLE_OPENGL_4X_SMOOTH #optional | ||
hint DISABLE_OPENGL_ERROR_REPORT #optional | ||
end | ||
|
||
#PFont font | ||
|
||
def draw() | ||
background(155) | ||
group.draw() | ||
end | ||
|
||
def key_pressed() | ||
if(key==' ') then | ||
init_form | ||
end | ||
end |