ruby-processing 1.0.9 → 1.0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. data/CHANGELOG +13 -1
  2. data/bin/rp5 +8 -2
  3. data/lib/core/core.jar +0 -0
  4. data/lib/core/jruby-complete.jar +0 -0
  5. data/lib/ruby-processing.rb +2 -2
  6. data/lib/ruby-processing/app.rb +108 -338
  7. data/lib/ruby-processing/config.rb +6 -0
  8. data/lib/ruby-processing/helper_methods.rb +120 -0
  9. data/lib/ruby-processing/library_loader.rb +140 -0
  10. data/lib/ruby-processing/runner.rb +34 -4
  11. data/lib/ruby-processing/runners/base.rb +10 -11
  12. data/lib/ruby-processing/runners/live.rb +1 -1
  13. data/lib/ruby-processing/runners/run.rb +1 -1
  14. data/lib/ruby-processing/runners/watch.rb +18 -76
  15. data/lib/templates/applet/index.html.erb +8 -9
  16. data/library/control_panel/control_panel.rb +1 -1
  17. data/library/dxf/library/dxf.jar +0 -0
  18. data/library/dxf/library/export.txt +1 -0
  19. data/library/javascript/library/export.txt +3 -1
  20. data/library/minim/library/export.txt +1 -0
  21. data/library/minim/library/jl1.0.jar +0 -0
  22. data/library/minim/library/jsminim.jar +0 -0
  23. data/library/minim/library/minim-spi.jar +0 -0
  24. data/library/minim/library/minim.jar +0 -0
  25. data/library/minim/library/mp3spi1.9.4.jar +0 -0
  26. data/library/minim/library/tritonus_aos.jar +0 -0
  27. data/library/minim/library/tritonus_share.jar +0 -0
  28. data/library/net/library/export.txt +1 -0
  29. data/library/net/library/net.jar +0 -0
  30. data/library/opengl/library/export.txt +7 -10
  31. data/library/opengl/library/gluegen-rt.jar +0 -0
  32. data/library/opengl/library/jogl.jar +0 -0
  33. data/library/opengl/library/{libgluegen-rt.so → linux32/libgluegen-rt.so} +0 -0
  34. data/library/opengl/library/{libjogl.so → linux32/libjogl.so} +0 -0
  35. data/library/opengl/library/{libjogl_awt.so → linux32/libjogl_awt.so} +0 -0
  36. data/library/opengl/library/{libjogl_cg.so → linux32/libjogl_cg.so} +0 -0
  37. data/library/opengl/library/linux64/libgluegen-rt.so +0 -0
  38. data/library/opengl/library/linux64/libjogl.so +0 -0
  39. data/library/opengl/library/linux64/libjogl_awt.so +0 -0
  40. data/library/opengl/library/linux64/libjogl_cg.so +0 -0
  41. data/library/opengl/library/{libgluegen-rt.jnilib → macosx/libgluegen-rt.jnilib} +0 -0
  42. data/library/opengl/library/{libjogl.jnilib → macosx/libjogl.jnilib} +0 -0
  43. data/library/opengl/library/{libjogl_awt.jnilib → macosx/libjogl_awt.jnilib} +0 -0
  44. data/library/opengl/library/{libjogl_cg.jnilib → macosx/libjogl_cg.jnilib} +0 -0
  45. data/library/opengl/library/opengl.jar +0 -0
  46. data/library/opengl/library/{gluegen-rt.dll → windows32/gluegen-rt.dll} +0 -0
  47. data/library/opengl/library/{jogl.dll → windows32/jogl.dll} +0 -0
  48. data/library/opengl/library/{jogl_awt.dll → windows32/jogl_awt.dll} +0 -0
  49. data/library/opengl/library/{jogl_cg.dll → windows32/jogl_cg.dll} +0 -0
  50. data/library/opengl/library/windows64/gluegen-rt.dll +0 -0
  51. data/library/opengl/library/windows64/jogl.dll +0 -0
  52. data/library/opengl/library/windows64/jogl_awt.dll +0 -0
  53. data/library/opengl/library/windows64/jogl_cg.dll +0 -0
  54. data/library/pdf/library/export.txt +1 -0
  55. data/library/pdf/library/itext.jar +0 -0
  56. data/library/pdf/library/pdf.jar +0 -0
  57. data/library/serial/library/RXTXcomm.jar +0 -0
  58. data/library/serial/library/export.txt +1 -3
  59. data/library/serial/library/linux32/librxtxSerial.so +0 -0
  60. data/library/serial/library/linux64/librxtxSerial.so +0 -0
  61. data/library/serial/library/macosx/librxtxSerial.jnilib +0 -0
  62. data/library/serial/library/serial.jar +0 -0
  63. data/library/serial/library/windows32/rxtxSerial.dll +0 -0
  64. data/library/serial/library/windows64/rxtxSerial.dll +0 -0
  65. data/library/video/library/export.txt +1 -0
  66. data/library/video/library/video.jar +0 -0
  67. data/samples/{animator.rb → contributed/animator.rb} +0 -0
  68. data/samples/{bezier_playground.rb → contributed/bezier_playground.rb} +0 -0
  69. data/samples/{circle_collision.rb → contributed/circle_collision.rb} +0 -0
  70. data/samples/contributed/drawolver.rb +182 -0
  71. data/samples/{empathy.rb → contributed/empathy.rb} +7 -7
  72. data/samples/{fern.rb → contributed/fern.rb} +0 -0
  73. data/samples/{flight_patterns.rb → contributed/flight_patterns.rb} +0 -0
  74. data/samples/{full_screen.rb → contributed/full_screen.rb} +0 -0
  75. data/samples/{getting_started.rb → contributed/getting_started.rb} +0 -0
  76. data/samples/{gravity.rb → contributed/gravity.rb} +0 -0
  77. data/samples/{jwishy.rb → contributed/jwishy.rb} +0 -0
  78. data/samples/{orbit.rb → contributed/orbit.rb} +0 -0
  79. data/samples/{pong.rb → contributed/pong.rb} +0 -0
  80. data/samples/{reflection.rb → contributed/reflection.rb} +0 -0
  81. data/samples/{simple_buffer.rb → contributed/simple_buffer.rb} +0 -0
  82. data/samples/{tree.rb → contributed/tree.rb} +0 -0
  83. data/samples/peasy_cam/library/hilbert/hilbert.rb +11 -10
  84. data/samples/processing_app/3D/camera/move_eye.rb +29 -0
  85. data/samples/processing_app/3D/form/brick_tower.rb +11 -11
  86. data/samples/processing_app/3D/form/cubic_grid.rb +51 -0
  87. data/samples/processing_app/3D/form/icosahedra/icosahedra.rb +76 -0
  88. data/samples/processing_app/3D/form/icosahedra/icosahedron.rb +116 -0
  89. data/samples/processing_app/3D/form/icosahedra/shape_3D.rb +25 -0
  90. data/samples/processing_app/3D/form/primitives.rb +42 -0
  91. data/samples/processing_app/3D/form/rgb_cube.rb +88 -0
  92. data/samples/processing_app/3D/form/shape_transform.rb +94 -0
  93. data/samples/processing_app/3D/form/toroid.rb +130 -0
  94. data/samples/processing_app/3D/form/vertices.rb +81 -0
  95. data/samples/processing_app/3D/image/data/eames.jpg +0 -0
  96. data/samples/processing_app/3D/image/data/ystone08.jpg +0 -0
  97. data/samples/processing_app/3D/image/explode.rb +56 -0
  98. data/samples/processing_app/3D/image/extrusion.rb +49 -0
  99. data/samples/processing_app/3D/image/zoom.rb +83 -0
  100. data/samples/processing_app/3D/lights/directional.rb +41 -0
  101. data/samples/processing_app/3D/lights/lights1.rb +39 -0
  102. data/samples/processing_app/3D/lights/lights2.rb +42 -0
  103. data/samples/processing_app/3D/lights/reflection.rb +38 -0
  104. data/samples/processing_app/3D/lights/spot.rb +39 -0
  105. data/samples/processing_app/3D/textures/data/berlin-1.jpg +0 -0
  106. data/samples/processing_app/3D/textures/texture1.rb +41 -0
  107. data/samples/processing_app/3D/textures/texture2.rb +38 -0
  108. data/samples/processing_app/3D/textures/texture3.rb +68 -0
  109. data/samples/processing_app/3D/textures/texture_cube.rb +106 -0
  110. data/samples/processing_app/3D/transform/bird.rb +61 -0
  111. data/samples/processing_app/3D/transform/birds/bird.rb +87 -0
  112. data/samples/processing_app/3D/transform/birds/birds.rb +48 -0
  113. data/samples/processing_app/3D/transform/cubes_in_cube/cube.rb +57 -0
  114. data/samples/processing_app/3D/transform/cubes_in_cube/cubes_in_cube.rb +102 -0
  115. data/samples/processing_app/3D/transform/push_pop_cubes.rb +152 -0
  116. data/samples/processing_app/3D/transform/rotate1.rb +43 -0
  117. data/samples/processing_app/3D/transform/rotate2.rb +45 -0
  118. data/samples/processing_app/3D/typography/data/Univers45.vlw +0 -0
  119. data/samples/processing_app/3D/typography/letter_k.rb +136 -0
  120. data/samples/processing_app/3D/typography/typing.rb +77 -0
  121. data/samples/processing_app/basics/form/triangle_strip.rb +19 -19
  122. data/samples/processing_app/basics/math/distance1.rb +59 -0
  123. data/samples/processing_app/basics/math/distance2.rb +38 -0
  124. data/samples/processing_app/basics/math/double_random.rb +38 -0
  125. data/samples/processing_app/basics/math/graphing_2_d_equation.rb +53 -0
  126. data/samples/processing_app/basics/math/increment_decrement.rb +59 -0
  127. data/samples/processing_app/basics/math/modulo.rb +43 -0
  128. data/samples/processing_app/basics/math/noise_1_d.rb +37 -0
  129. data/samples/processing_app/basics/math/noise_2_d.rb +47 -0
  130. data/samples/processing_app/basics/math/noise_3_d.rb +50 -0
  131. data/samples/processing_app/basics/math/noise_wave.rb +61 -0
  132. data/samples/processing_app/basics/math/operator_precedence.rb +70 -0
  133. data/samples/processing_app/basics/math/polar_to_cartesian.rb +44 -0
  134. data/samples/processing_app/basics/math/random.rb +35 -0
  135. data/samples/processing_app/basics/math/sine.rb +49 -0
  136. data/samples/processing_app/basics/math/sine_cosine.rb +60 -0
  137. data/samples/processing_app/basics/math/sine_wave.rb +62 -0
  138. data/samples/processing_app/basics/objects/composite_objects.rb +139 -0
  139. data/samples/processing_app/basics/objects/inheritance.rb +104 -0
  140. data/samples/processing_app/basics/objects/multiple_constructors.rb +66 -0
  141. data/samples/processing_app/basics/objects/objects.rb +72 -0
  142. data/samples/processing_app/basics/shape/data/bot1.svg +160 -0
  143. data/samples/processing_app/basics/shape/data/usa-wikipedia.svg +452 -0
  144. data/samples/processing_app/basics/shape/disable_style.rb +36 -0
  145. data/samples/processing_app/basics/shape/get_child.rb +43 -0
  146. data/samples/processing_app/basics/shape/load_display_shape.rb +33 -0
  147. data/samples/processing_app/basics/shape/scale_shape.rb +33 -0
  148. data/samples/processing_app/basics/structure/coordinates.rb +55 -0
  149. data/samples/processing_app/basics/structure/create_graphics.rb +39 -0
  150. data/samples/processing_app/basics/structure/functions.rb +41 -0
  151. data/samples/processing_app/basics/structure/loop.rb +39 -0
  152. data/samples/processing_app/basics/structure/noloop.rb +33 -0
  153. data/samples/processing_app/basics/structure/recursion1.rb +42 -0
  154. data/samples/processing_app/basics/structure/recursion2.rb +39 -0
  155. data/samples/processing_app/basics/structure/redraw.rb +36 -0
  156. data/samples/processing_app/basics/structure/setup_draw.rb +30 -0
  157. data/samples/processing_app/basics/structure/statements_comments.rb +32 -0
  158. data/samples/processing_app/basics/structure/width_height.rb +29 -0
  159. data/samples/processing_app/basics/transform/arm.rb +47 -0
  160. data/samples/processing_app/basics/transform/rotate.rb +43 -0
  161. data/samples/processing_app/basics/transform/scale.rb +45 -0
  162. data/samples/processing_app/basics/transform/translate.rb +41 -0
  163. data/samples/processing_app/basics/transform/triangle_flower.rb +69 -0
  164. data/samples/processing_app/basics/typography/data/CourierNew36.vlw +0 -0
  165. data/samples/processing_app/basics/typography/data/Ziggurat-HTF-Black-32.vlw +0 -0
  166. data/samples/processing_app/basics/typography/letters.rb +52 -0
  167. data/samples/processing_app/basics/typography/words.rb +37 -0
  168. data/samples/processing_app/basics/web/embedded_links.rb +58 -0
  169. data/samples/processing_app/basics/web/loading_images.rb +25 -0
  170. metadata +181 -86
  171. data/lib/patches/JRubyApplet.diff +0 -24
  172. data/lib/patches/PATCHES.txt +0 -3
  173. data/lib/patches/PApplet.diff +0 -27
  174. data/library/minim/license.txt +0 -339
  175. data/library/minim/version.txt +0 -1
  176. data/library/opengl/library/gluegen-rt-natives-linux-amd64.jar +0 -0
  177. data/library/opengl/library/gluegen-rt-natives-linux-i586.jar +0 -0
  178. data/library/opengl/library/gluegen-rt-natives-macosx-ppc.jar +0 -0
  179. data/library/opengl/library/gluegen-rt-natives-macosx-universal.jar +0 -0
  180. data/library/opengl/library/gluegen-rt-natives-windows-amd64.jar +0 -0
  181. data/library/opengl/library/gluegen-rt-natives-windows-i586.jar +0 -0
  182. data/library/opengl/library/gluegen-rt.jar.pack.gz +0 -0
  183. data/library/opengl/library/jogl-natives-linux-amd64.jar +0 -0
  184. data/library/opengl/library/jogl-natives-linux-i586.jar +0 -0
  185. data/library/opengl/library/jogl-natives-macosx-ppc.jar +0 -0
  186. data/library/opengl/library/jogl-natives-macosx-universal.jar +0 -0
  187. data/library/opengl/library/jogl-natives-windows-amd64.jar +0 -0
  188. data/library/opengl/library/jogl-natives-windows-i586.jar +0 -0
  189. data/library/opengl/library/jogl.jar.pack.gz +0 -0
  190. data/library/pdf/notes.txt +0 -8
  191. data/library/serial/library/librxtxSerial.jnilib +0 -0
  192. data/library/serial/library/librxtxSerial.so +0 -0
  193. data/library/serial/library/rxtxSerial.dll +0 -0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -39,9 +39,9 @@ end
39
39
  ###########################
40
40
  class Hilbert
41
41
  include Processing::Proxy
42
-
42
+ ADJUSTMENT = [0, 0.5, 1.5, 3.5, 7.5, 15]
43
43
  attr_reader :grammar, :axiom, :production, :premis, :rule,
44
- :theta, :scale_factor, :distance, :phi, :len
44
+ :theta, :distance, :phi, :gen
45
45
 
46
46
  def initialize(len)
47
47
  @axiom = "X"
@@ -49,16 +49,14 @@ class Hilbert
49
49
  @production = axiom
50
50
  @premis = "X"
51
51
  @rule = "^<XF^<XFX-F^>>XFX&F+>>XFX-F>X->"
52
- @len = len
53
- @distance = len/12 # distance value relative to screen height
52
+ @distance = len
54
53
  @theta = Math::PI/180 * 90
55
- @phi = Math::PI/180 * 90
54
+ @phi = Math::PI/180 * 90
56
55
  grammar.add_rule(premis, rule)
57
- no_stroke()
58
56
  end
59
57
 
60
- def render()
61
- translate(-len/42, len/42, -len/42) # use the "answer?" to center the Hilbert
58
+ def render()
59
+ translate( -distance * ADJUSTMENT[gen], distance * ADJUSTMENT[gen], -distance * ADJUSTMENT[gen])
62
60
  fill(0, 75, 152)
63
61
  light_specular(204, 204, 204)
64
62
  specular(255, 255, 255)
@@ -93,7 +91,10 @@ class Hilbert
93
91
  ##############################
94
92
 
95
93
  def create_grammar(gen)
96
- @distance *= 0.5**gen
94
+ @gen = gen # required for depth adjustment
95
+ @distance *= 1/(pow(2, gen) - 1)
97
96
  @production = @grammar.generate gen
98
97
  end
99
- end
98
+
99
+
100
+ end
@@ -0,0 +1,29 @@
1
+ # Move Eye.
2
+ # by Simon Greenwold.
3
+ #
4
+ # The camera lifts up (controlled by mouseY) while looking at the same point.
5
+
6
+ class MoveEye < Processing::App
7
+
8
+ def setup
9
+ size 640, 360, P3D
10
+ fill 204
11
+ end
12
+
13
+ def draw
14
+ lights
15
+ background 0
16
+
17
+ camera 30, mouseY, 220, 0, 0, 0, 0, 1, 0
18
+
19
+ noStroke
20
+ box 90
21
+ stroke 255
22
+ line( -100, 0, 0, 100, 0, 0)
23
+ line( 0, -100, 0, 0, 100, 0)
24
+ line( 0, 0, -100, 0, 0, 100)
25
+ end
26
+
27
+ end
28
+
29
+ MoveEye.new :title => "Move Eye"
@@ -2,7 +2,7 @@
2
2
 
3
3
  # 3D castle tower constructed out of individual bricks.
4
4
  # Uses the PVecor and Cube classes.
5
-
5
+
6
6
  def setup
7
7
  @bricks_per_layer = 16
8
8
  @brick_layers = 18
@@ -27,7 +27,7 @@ end
27
27
 
28
28
  def draw_layer(layer_num)
29
29
  @layer_num = layer_num
30
- @temp_y -= @brick_height # increment rows
30
+ @temp_y -= @brick_height # increment rows
31
31
  @angle = 360.0 / @bricks_per_layer * @layer_num / 2.0 # alternate brick seams
32
32
  @bricks_per_layer.times {|i| draw_bricks(i) }
33
33
  end
@@ -59,14 +59,14 @@ class Cubeish
59
59
  :back => ['---', ' --', ' -', '- -'],
60
60
  :top => ['-- ', '---', ' --', ' - '],
61
61
  :bottom => ['- ', '- -', ' -', ' ']}
62
-
63
- SIGNS = {'-' => -1,
62
+
63
+ SIGNS = {'-' => -1,
64
64
  ' ' => 1}
65
-
65
+
66
66
  def initialize(width, height, depth)
67
67
  @vertices = {}
68
68
  @w, @h, @d = width, height, depth
69
-
69
+
70
70
  SIDES.each do |side, signs|
71
71
  @vertices[side] = signs.map do |s|
72
72
  s = s.split('').map {|el| SIGNS[el] }
@@ -74,13 +74,13 @@ class Cubeish
74
74
  end
75
75
  end
76
76
  end
77
-
77
+
78
78
  def create
79
79
  @vertices.each do |name, vectors|
80
- shape(App::QUADS) do
81
- vectors.each {|v| vertex(v.x, v.y, v.z) }
82
- end
80
+ begin_shape App::QUADS
81
+ vectors.each {|v| vertex(v.x, v.y, v.z) }
82
+ end_shape
83
83
  end
84
84
  end
85
-
85
+
86
86
  end
@@ -0,0 +1,51 @@
1
+ # Cubic Grid
2
+ # by Ira Greenberg.
3
+ #
4
+ # 3D translucent colored grid uses nested pushMatrix()
5
+ # and popMatrix() functions.
6
+
7
+ class CubicGrid < Processing::App
8
+
9
+ def setup
10
+ size 640, 360, P3D
11
+ no_stroke
12
+
13
+ @box_size = 40
14
+ @margin = @box_size * 2
15
+ @depth = 400
16
+ end
17
+
18
+ def draw
19
+ background 255
20
+
21
+ translate width/2, height/2, -@depth
22
+ rotate_x frame_count * 0.01
23
+ rotate_y frame_count * 0.01
24
+
25
+ ((-@depth/2 + @margin)..(@depth/2 - @margin)).step( @box_size ) { |i|
26
+ push_matrix
27
+
28
+ ((-height + @margin)..(height - @margin)).step( @box_size ) { |j|
29
+ push_matrix
30
+
31
+ ((-width + @margin)..(width - @margin)).step( @box_size ) { |k|
32
+ box_fill = color i.abs, j.abs, k.abs, 50
33
+ push_matrix
34
+
35
+ translate k, j, i
36
+ fill box_fill
37
+ box @box_size
38
+
39
+ pop_matrix
40
+ }
41
+
42
+ pop_matrix
43
+ }
44
+
45
+ pop_matrix
46
+ }
47
+ end
48
+
49
+ end
50
+
51
+ CubicGrid.new :title => "Cubic Grid"
@@ -0,0 +1,76 @@
1
+ # I Like Icosahedra
2
+ # by Ira Greenberg.
3
+ #
4
+ # This example plots icosahedra. The Icosahdron is a regular
5
+ # polyhedron composed of twenty equalateral triangles.
6
+
7
+ # fjenett, 2010-03-11:
8
+ # This is by far not an exact translation of Iras code. I removed
9
+ # the unneeded Dimension3D class, simplyfied Shape3D and improved
10
+ # the Icosahedron class. That and the rubyfication ...
11
+
12
+
13
+ class Icosahedra < Processing::App
14
+
15
+ def setup
16
+
17
+ size 640, 360, P3D
18
+
19
+ @ico1 = Icosahedron.new 75
20
+ @ico2 = Icosahedron.new 75
21
+ @ico3 = Icosahedron.new 75
22
+
23
+ end
24
+
25
+ def draw
26
+
27
+ background 0
28
+ lights
29
+
30
+ translate width/2, height/2
31
+
32
+ push_matrix
33
+
34
+ translate -width/3.5, 0
35
+ rotate_x frame_count * PI / 185
36
+ rotate_y frame_count * PI / -200
37
+
38
+ stroke 170, 0, 0
39
+ no_fill
40
+
41
+ @ico1.draw
42
+
43
+ pop_matrix
44
+
45
+ push_matrix
46
+
47
+ rotate_x frame_count * PI / 200
48
+ rotate_y frame_count * PI / 300
49
+
50
+ stroke 170, 0, 180
51
+ fill 170, 170, 0
52
+
53
+ @ico2.draw
54
+
55
+ pop_matrix
56
+
57
+ push_matrix
58
+
59
+ translate width/3.5, 0
60
+ rotate_x frame_count * PI / -200
61
+ rotate_y frame_count * PI / 200
62
+
63
+ no_stroke
64
+ fill 0, 0, 185
65
+
66
+ @ico3.draw
67
+
68
+ pop_matrix
69
+
70
+ end
71
+
72
+ require 'icosahedron' # load icosahedron.rb
73
+
74
+ end
75
+
76
+ Icosahedra.new :title => "Icosahedra"
@@ -0,0 +1,116 @@
1
+
2
+ # fjenett, 2010-03-11:
3
+ # Mixing in Processing::Proxy makes classes behave like inner classes(*) of
4
+ # a Processing sketch (any class that's defined in a sketch and that is
5
+ # inside a .pde file). This is needed for a class to be able to call any
6
+ # drawing commands etc.
7
+ # (*) Ruby does not know inner classes btw. ...
8
+
9
+
10
+ require 'shape_3D' # load shape_3D.rb
11
+
12
+ class Icosahedron < Shape3D # extends Shape3D
13
+
14
+ include Processing::Proxy # mixin Processing::Proxy
15
+
16
+ attr_accessor :top_point, :top_pent
17
+ attr_accessor :bottom_point, :bottom_pent
18
+ attr_accessor :angle, :radius
19
+ attr_accessor :tri_dist, :tri_ht
20
+ attr_accessor :a, :b, :c
21
+
22
+ def initialize ( *args )
23
+
24
+ super args # call Shape3D.new( args )
25
+
26
+ @radius = args.first
27
+ @top_pent = Array.new 5
28
+ @bottom_pent = Array.new 5
29
+ @angle = 0.0
30
+
31
+ init
32
+
33
+ end
34
+
35
+ def init
36
+
37
+ @c = dist( cos(0) * @radius,
38
+ sin(0) * @radius,
39
+ cos(radians( 72 )) * @radius,
40
+ sin(radians( 72 )) * @radius )
41
+
42
+ @b = @radius
43
+
44
+ @a = sqrt(@c*@c - @b*@b)
45
+
46
+ @tri_ht = sqrt( @c*@c - (@c/2) * (@c/2) )
47
+
48
+ @top_pent.each_with_index { |v, i|
49
+
50
+ @top_pent[i] = PVector.new( cos(@angle) * @radius,
51
+ sin(@angle) * @radius,
52
+ @tri_ht / 2 )
53
+
54
+ @angle += radians 72
55
+ }
56
+
57
+ @top_point = PVector.new 0, 0, @tri_ht / 2 + @a
58
+
59
+ @angle = 72.0/2
60
+
61
+ @bottom_pent.each_with_index { |v, i|
62
+
63
+ @bottom_pent[i] = PVector.new( cos(@angle) * @radius,
64
+ sin(@angle) * @radius,
65
+ -@tri_ht / 2 )
66
+ @angle += radians 72
67
+ }
68
+
69
+ @bottom_point = PVector.new 0, 0, -(@tri_ht / 2 + @a)
70
+
71
+ end
72
+
73
+ def draw
74
+
75
+ [@top_pent, @bottom_pent].each { |pent| # top and bottom pentagram
76
+
77
+ (0...pent.length).each { |i|
78
+
79
+ begin_shape
80
+
81
+ # next or first
82
+ n = i+1
83
+ n = n % @top_pent.length # wrap around
84
+
85
+ # choose point depending on pentagram
86
+ pnt = @top_point
87
+ pnt = @bottom_point if pent == @bottom_pent
88
+
89
+ # draw triangle
90
+ vertex @x + pent[i].x, @y + pent[i].y, @z + pent[i].z
91
+ vertex @x + pnt.x, @y + pnt.y, @z + pnt.z
92
+ vertex @x + pent[n].x, @y + pent[n].y, @z + pent[n].z
93
+
94
+ end_shape CLOSE
95
+ }
96
+ }
97
+
98
+ begin_shape TRIANGLE_STRIP
99
+
100
+ 0.upto(6) { |i| # stitch pentagrams together with triangles
101
+
102
+ j = i
103
+ j = j % @top_pent.length
104
+
105
+ n = i+2
106
+ n = n % @bottom_pent.length
107
+
108
+ vertex @x + @top_pent[j].x, @y + @top_pent[j].y, @z + @top_pent[j].z
109
+ vertex @x + @bottom_pent[n].x, @y + @bottom_pent[n].y, @z + @bottom_pent[n].z
110
+ }
111
+
112
+ end_shape
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,25 @@
1
+
2
+ # fjenett, 2010-03-11:
3
+ # Left this in although it's not needed as an example for
4
+ # how to extend classes.
5
+
6
+ class Shape3D
7
+
8
+ attr_accessor :x, :y, :z
9
+ attr_accessor :w, :h, :d
10
+
11
+ def initialize (*args)
12
+ @x, @y, @z = 0.0, 0.0, 0.0
13
+ @w, @h, @d = 0.0, 0.0, 0.0
14
+ end
15
+
16
+ def rotate_x ( theta )
17
+ end
18
+
19
+ def rotate_y ( theta )
20
+ end
21
+
22
+ def rotate_z ( theta )
23
+ end
24
+
25
+ end
@@ -0,0 +1,42 @@
1
+ # Primitives 3D.
2
+ #
3
+ # Placing mathematically 3D objects in synthetic space.
4
+ # The lights() method reveals their imagined dimension.
5
+ # The box() and sphere() functions each have one parameter
6
+ # which is used to specify their size. These shapes are
7
+ # positioned using the translate() function.
8
+
9
+ class Primitives < Processing::App
10
+
11
+ def setup
12
+
13
+ size 640, 360, P3D
14
+
15
+ background 0
16
+ lights
17
+
18
+ no_stroke
19
+ push_matrix
20
+
21
+ translate 130, height/2, 0
22
+ rotate_y 1.25
23
+ rotate_x -0.4
24
+
25
+ box 100
26
+
27
+ pop_matrix
28
+
29
+ no_fill
30
+ stroke 255
31
+ push_matrix
32
+
33
+ translate 500, height*0.35, -200
34
+ sphere 280
35
+
36
+ pop_matrix
37
+
38
+ end
39
+
40
+ end
41
+
42
+ Primitives.new :title => "Primitives"