ruby-processing 1.0.9 → 1.0.10.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,49 @@
1
+ # Extrusion.
2
+ #
3
+ # Converts a flat image into spatial data points and rotates the points
4
+ # around the center.
5
+
6
+ class Extrusion < Processing::App
7
+
8
+ def setup
9
+
10
+ size 640, 360, P3D
11
+
12
+ @angle = 0.0
13
+
14
+ @extrude = load_image "ystone08.jpg"
15
+ @extrude.load_pixels
16
+
17
+ @values = []
18
+ (0...@extrude.height).each { |y|
19
+ @values[y] = []
20
+ (0...@extrude.width).each { |x|
21
+ pxl = @extrude.get x, y
22
+ @values[y][x] = brightness( pxl ).to_i
23
+ }
24
+ }
25
+
26
+ end
27
+
28
+ def draw
29
+
30
+ background 0
31
+
32
+ @angle += 0.005
33
+
34
+ translate width/2, 0, -128
35
+ rotate_y @angle
36
+ translate -@extrude.width/2, 100, -128
37
+
38
+ (0...@extrude.height).each { |y|
39
+ (0...@extrude.width).each { |x|
40
+ stroke @values[y][x]
41
+ point x, y, -@values[y][x]
42
+ }
43
+ }
44
+
45
+ end
46
+
47
+ end
48
+
49
+ Extrusion.new :title => "Extrusion"
@@ -0,0 +1,83 @@
1
+ # Zoom.
2
+ #
3
+ # Move the cursor over the image to alter its position. Click and press
4
+ # the mouse to zoom and set the density of the matrix by typing numbers 1-5.
5
+ # This program displays a series of lines with their heights corresponding to
6
+ # a color value read from an image.
7
+
8
+ class Zoom < Processing::App
9
+
10
+ def setup
11
+
12
+ size 640, 360, P3D
13
+
14
+ no_fill
15
+ stroke 255
16
+
17
+ @nmx = 0.0
18
+ @nmy = 0.0
19
+ @sval = 1.0
20
+ @res = 5
21
+
22
+ @img = load_image "ystone08.jpg"
23
+ @img_pixels = []
24
+ (0...@img.height).each { |y|
25
+ @img_pixels.push []
26
+ (0...@img.width).each { |x|
27
+ @img_pixels.last.push @img.get y, x
28
+ }
29
+ }
30
+
31
+ end
32
+
33
+ def draw
34
+
35
+ background 0
36
+
37
+ @nmx += (mouse_x - @nmx) / 20
38
+ @nmy += (mouse_y - @nmy) / 20
39
+
40
+ if mouse_pressed?
41
+ @sval += 0.005
42
+ else
43
+ @sval -= 0.01
44
+ end
45
+
46
+ @sval = constrain @sval, 1.0, 2.5
47
+
48
+ translate width/2 + @nmx * @sval - 100, height/2 + @nmy * @sval - 200, -50
49
+ scale @sval
50
+ rotate_z PI/9 - @sval + 1
51
+ rotate_x PI/@sval/8 - 0.125
52
+ rotate_y @sval/8 - 0.125
53
+
54
+ translate -width/2, -height/2
55
+
56
+ (0...@img.height).step(@res) { |y|
57
+ (0...@img.width).step(@res) { |x|
58
+
59
+ rr = red @img_pixels[y][x]
60
+ gg = green @img_pixels[y][x]
61
+ bb = blue @img_pixels[y][x]
62
+
63
+ tt = rr + gg + bb
64
+
65
+ stroke rr, gg, gg
66
+
67
+ line y, x, tt/10 - 20, y, x, tt/10
68
+ }
69
+ }
70
+
71
+ end
72
+
73
+ def key_pressed
74
+
75
+ k = key.to_i
76
+
77
+ @res = k if k > 0 && k < 6
78
+
79
+ end
80
+
81
+ end
82
+
83
+ Zoom.new :title => "Zoom"
@@ -0,0 +1,41 @@
1
+ # Directional.
2
+ #
3
+ # Move the mouse the change the direction of the light.
4
+ # Directional light comes from one direction and is stronger
5
+ # when hitting a surface squarely and weaker if it hits at a
6
+ # a gentle angle. After hitting a surface, a directional lights
7
+ # scatters in all directions.
8
+
9
+ class Directional < Processing::App
10
+
11
+ def setup
12
+
13
+ size 640, 360, P3D
14
+
15
+ no_stroke
16
+ fill 204
17
+
18
+ end
19
+
20
+ def draw
21
+
22
+ background 0
23
+
24
+ dir_x = (mouse_x / width.to_f - 0.5) * 2
25
+ dir_y = (mouse_y / height.to_f - 0.5) * 2
26
+
27
+ directional_light 204, 204, 204, -dir_x, -dir_y, -1
28
+
29
+ translate width/2 - 100, height/2
30
+
31
+ sphere 80
32
+
33
+ translate 200, 0
34
+
35
+ sphere 80
36
+
37
+ end
38
+
39
+ end
40
+
41
+ Directional.new :title => "Directional"
@@ -0,0 +1,39 @@
1
+ # Lights 1.
2
+ #
3
+ # Uses the default lights to show a simple box. The lights() function
4
+ # is used to turn on the default lighting.
5
+
6
+ class Lights1 < Processing::App
7
+
8
+ def setup
9
+
10
+ size 640, 360, P3D
11
+
12
+ @spin = 0.0
13
+
14
+ no_stroke
15
+
16
+ end
17
+
18
+ def draw
19
+
20
+ background 51
21
+ lights
22
+
23
+ @spin += 0.01
24
+
25
+ push_matrix
26
+
27
+ translate width/2, height/2
28
+ rotate_x PI/9
29
+ rotate_y PI/5 + @spin
30
+
31
+ box 150
32
+
33
+ pop_matrix
34
+
35
+ end
36
+
37
+ end
38
+
39
+ Lights1.new :title => "Lights1"
@@ -0,0 +1,42 @@
1
+ # Lights 2
2
+ # by Simon Greenwold.
3
+ #
4
+ # Display a box with three different kinds of lights.
5
+
6
+ class Lights2 < Processing::App
7
+
8
+ def setup
9
+
10
+ size 640, 360, P3D
11
+
12
+ no_stroke
13
+
14
+ end
15
+
16
+ def draw
17
+
18
+ background 0
19
+
20
+ translate width/2, height/2
21
+
22
+ point_light 150, 100, 0, #color
23
+ 200, -150, 0 #position
24
+
25
+ directional_light 0, 102, 255, #color
26
+ 1, 0, 0 #x-,y-,z-axis direction
27
+
28
+ spot_light 255, 255, 109, #color
29
+ 0, 40, 200, #position
30
+ 0,-0.5,-0.5, #direction
31
+ PI/2, 2 #angle, concentration
32
+
33
+ rotate_y map( mouse_x, 0, width, 0, PI )
34
+ rotate_x map( mouse_y, 0, height, 0, PI )
35
+
36
+ box 150
37
+
38
+ end
39
+
40
+ end
41
+
42
+ Lights2.new :title => "Lights2"
@@ -0,0 +1,38 @@
1
+ # Reflection
2
+ # by Simon Greenwold.
3
+ #
4
+ # Vary the specular reflection component of a material
5
+ # with the horizontal position of the mouse.
6
+
7
+ class Reflection < Processing::App
8
+
9
+ def setup
10
+
11
+ size 640, 360, P3D
12
+
13
+ no_stroke
14
+ color_mode RGB, 1
15
+ fill 0.4
16
+
17
+ end
18
+
19
+ def draw
20
+
21
+ background 0
22
+
23
+ translate width/2, height/2
24
+
25
+ light_specular 1, 1, 1
26
+ directional_light 0.8, 0.8, 0.8, 0, 0, -1
27
+
28
+ s = mouse_x / width.to_f
29
+
30
+ specular s
31
+
32
+ sphere 120
33
+
34
+ end
35
+
36
+ end
37
+
38
+ Reflection.new :title => "Reflection"
@@ -0,0 +1,39 @@
1
+ # Spot.
2
+ #
3
+ # Move the mouse the change the position and concentation
4
+ # of a blue spot light.
5
+
6
+ class Spot < Processing::App
7
+
8
+ def setup
9
+
10
+ size 640, 360, P3D
11
+
12
+ @concentration = 600 # try values between 1 <-> 10000
13
+
14
+ no_stroke
15
+ fill 204
16
+
17
+ sphere_detail 60
18
+
19
+ end
20
+
21
+ def draw
22
+
23
+ background 0
24
+
25
+ directional_light 51, 102, 126, 0, -1, 0
26
+
27
+ spot_light 204, 153, 0, 360, 160, 600, 0, 0, -1, PI/2, @concentration
28
+
29
+ spot_light 102, 153, 204, 360, mouse_y, 600, 0, 0, -1, PI/2, @concentration
30
+
31
+ translate width/2, height/2
32
+
33
+ sphere 120
34
+
35
+ end
36
+
37
+ end
38
+
39
+ Spot.new :title => "Spot"
@@ -0,0 +1,41 @@
1
+ # Texture 1.
2
+ #
3
+ # Load an image and draw it onto a quad. The texture() function sets
4
+ # the texture image. The vertex() function maps the image to the geometry.
5
+
6
+ class Texture1 < Processing::App
7
+
8
+ def setup
9
+
10
+ size 640, 360, P3D
11
+
12
+ @img = load_image "berlin-1.jpg"
13
+
14
+ no_stroke
15
+
16
+ end
17
+
18
+ def draw
19
+
20
+ background 0
21
+
22
+ translate width/2, height/2
23
+ rotate_y map(mouse_x, 0, width, -PI, PI)
24
+ rotate_z PI/6
25
+
26
+ begin_shape
27
+
28
+ texture @img
29
+
30
+ vertex -100, -100, 0, 0, 0
31
+ vertex 100, -100, 0, @img.width, 0
32
+ vertex 100, 100, 0, @img.width, @img.height
33
+ vertex -100, 100, 0, 0, @img.height
34
+
35
+ end_shape
36
+
37
+ end
38
+
39
+ end
40
+
41
+ Texture1.new :title => "Texture1"
@@ -0,0 +1,38 @@
1
+ # Texture 2.
2
+ #
3
+ # Using a rectangular image to map a texture onto a triangle.
4
+
5
+ class Texture2 < Processing::App
6
+
7
+ def setup
8
+
9
+ size 640, 360, P3D
10
+
11
+ @img = load_image "berlin-1.jpg"
12
+ no_stroke
13
+
14
+ end
15
+
16
+ def draw
17
+
18
+ background 0
19
+
20
+ translate width/2, height/2
21
+
22
+ rotate_y map( mouse_x, 0, width, -PI, PI )
23
+
24
+ begin_shape
25
+
26
+ texture @img
27
+
28
+ vertex -100, -100, 0, 0, 0
29
+ vertex 100, -40, 0, @img.width, @img.height/3
30
+ vertex 0, 100, 0, @img.width/2, @img.height
31
+
32
+ end_shape
33
+
34
+ end
35
+
36
+ end
37
+
38
+ Texture2.new :title => "Texture2"
@@ -0,0 +1,68 @@
1
+ # Texture 3.
2
+ #
3
+ # Load an image and draw it onto a cylinder and a quad.
4
+
5
+ class Texture3 < Processing::App
6
+
7
+ def setup
8
+
9
+ size 640, 360, P3D
10
+
11
+ @tube_res = 32
12
+ @tube_x = []
13
+ @tube_y = []
14
+
15
+ @img = load_image "berlin-1.jpg"
16
+
17
+ angle = 270.0 / @tube_res
18
+
19
+ (0...@tube_res).each { |i|
20
+ @tube_x.push cos( radians( i * angle ) )
21
+ @tube_y.push sin( radians( i * angle ) )
22
+ }
23
+
24
+ no_stroke
25
+
26
+ end
27
+
28
+ def draw
29
+
30
+ background 0
31
+
32
+ translate width/2, height/2
33
+ rotate_x map( mouse_y, 0, height, -PI, PI )
34
+ rotate_y map( mouse_x, 0, width, -PI, PI )
35
+
36
+ begin_shape QUAD_STRIP
37
+
38
+ texture @img
39
+
40
+ (0...@tube_res).each { |i|
41
+
42
+ x = @tube_x[i] * 100
43
+ z = @tube_y[i] * 100
44
+ u = @img.width / @tube_res * i
45
+
46
+ vertex x, -100, z, u, 0
47
+ vertex x, 100, z, u, @img.height
48
+
49
+ }
50
+
51
+ end_shape
52
+
53
+ begin_shape QUADS
54
+
55
+ texture @img
56
+
57
+ vertex 0, -100, 0, 0, 0
58
+ vertex 100, -100, 0, 100, 0
59
+ vertex 100, 100, 0, 100, 100
60
+ vertex 0, 100, 0, 0, 100
61
+
62
+ end_shape
63
+
64
+ end
65
+
66
+ end
67
+
68
+ Texture3.new :title => "Texture3"