ruby-processing 2.6.2 → 2.6.3

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 (129) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rpextras.jar +0 -0
  3. data/lib/ruby-processing.rb +5 -8
  4. data/lib/ruby-processing/app.rb +26 -27
  5. data/lib/ruby-processing/config.rb +0 -2
  6. data/lib/ruby-processing/exporters/application_exporter.rb +1 -1
  7. data/lib/ruby-processing/exporters/base_exporter.rb +1 -1
  8. data/lib/ruby-processing/exporters/creator.rb +11 -11
  9. data/lib/ruby-processing/helper_methods.rb +33 -31
  10. data/lib/ruby-processing/helpers/numeric.rb +1 -1
  11. data/lib/ruby-processing/helpers/range.rb +11 -0
  12. data/lib/ruby-processing/library_loader.rb +11 -16
  13. data/lib/ruby-processing/runner.rb +22 -24
  14. data/lib/ruby-processing/runners/watch.rb +1 -1
  15. data/lib/ruby-processing/version.rb +1 -1
  16. data/library/boids/boids.rb +39 -70
  17. data/library/control_panel/control_panel.rb +3 -3
  18. data/samples/contributed/circle_collision.rb +3 -3
  19. data/samples/contributed/fern.rb +7 -10
  20. data/samples/contributed/fibonacci_sphere.rb +2 -2
  21. data/samples/contributed/full_screen.rb +23 -22
  22. data/samples/contributed/grapher.rb +3 -3
  23. data/samples/contributed/gravity.rb +1 -1
  24. data/samples/contributed/mandelbrot.rb +10 -13
  25. data/samples/external_library/java_processing/box2d_processing/bumpy_surface_noise.rb +1 -1
  26. data/samples/external_library/java_processing/box2d_processing/library/custom_shape/custom_shape.rb +2 -2
  27. data/samples/external_library/java_processing/box2d_processing/library/particle_system/particle_system.rb +1 -1
  28. data/samples/external_library/java_processing/box2d_processing/library/surface/surface.rb +2 -2
  29. data/samples/external_library/java_processing/box2d_processing/liquidy.rb +1 -1
  30. data/samples/external_library/java_processing/fisica/bubbles.rb +2 -2
  31. data/samples/external_library/java_processing/fisica/joints.rb +4 -4
  32. data/samples/external_library/java_processing/generative_design/node_spring_attractor.rb +2 -2
  33. data/samples/external_library/java_processing/geomerative/hello_world_rotate_firstletter.rb +7 -7
  34. data/samples/external_library/java_processing/hemesh/twin_iso.rb +3 -3
  35. data/samples/external_library/java_processing/pbox2d/bumpy_surface_noise.rb +1 -1
  36. data/samples/external_library/java_processing/pbox2d/library/custom_shape/custom_shape.rb +2 -2
  37. data/samples/external_library/java_processing/pbox2d/library/particle_system/particle_system.rb +1 -1
  38. data/samples/external_library/java_processing/pbox2d/library/surface/surface.rb +2 -2
  39. data/samples/external_library/java_processing/pbox2d/liquidy.rb +1 -1
  40. data/samples/external_library/java_processing/peasy_cam/library/hilbert/hilbert.rb +4 -4
  41. data/samples/external_library/ruby_gem/draw_test.rb +2 -2
  42. data/samples/external_library/ruby_gem/game_of_life.rb +3 -3
  43. data/samples/processing_app/basics/arrays/array_objects.rb +2 -2
  44. data/samples/processing_app/basics/color/hue.rb +1 -1
  45. data/samples/processing_app/basics/control/conditionals1.rb +5 -24
  46. data/samples/processing_app/basics/control/conditionals2.rb +1 -1
  47. data/samples/processing_app/basics/form/bezier_ellipse.rb +1 -1
  48. data/samples/processing_app/basics/form/brick_tower.rb +4 -8
  49. data/samples/processing_app/basics/form/regular_polygon.rb +1 -1
  50. data/samples/processing_app/basics/form/star.rb +1 -1
  51. data/samples/processing_app/basics/form/triangle_strip.rb +1 -1
  52. data/samples/processing_app/basics/input/storing_input.rb +1 -1
  53. data/samples/processing_app/basics/lights/spot.rb +1 -1
  54. data/samples/processing_app/basics/math/additive_wave.rb +2 -2
  55. data/samples/processing_app/basics/math/double_random.rb +2 -2
  56. data/samples/processing_app/basics/math/noise_wave.rb +1 -1
  57. data/samples/processing_app/basics/math/random.rb +1 -1
  58. data/samples/processing_app/basics/objects/module.rb +1 -1
  59. data/samples/processing_app/basics/objects/struct.rb +1 -1
  60. data/samples/processing_app/basics/structure/loop.rb +19 -14
  61. data/samples/processing_app/basics/structure/recursion2.rb +2 -2
  62. data/samples/processing_app/basics/textures/texture3.rb +13 -33
  63. data/samples/processing_app/basics/transform/birds.rb +5 -5
  64. data/samples/processing_app/basics/transform/cubes_in_cube.rb +3 -3
  65. data/samples/processing_app/basics/transform/rotate.rb +1 -1
  66. data/samples/processing_app/basics/typography/kinetic_type.rb +1 -1
  67. data/samples/processing_app/demos/graphics/bezier_patch.rb +34 -34
  68. data/samples/processing_app/demos/graphics/trefoil.rb +1 -1
  69. data/samples/processing_app/demos/graphics/wiggling.rb +5 -5
  70. data/samples/processing_app/demos/performance/esfera.rb +4 -4
  71. data/samples/processing_app/demos/performance/text_rendering.rb +1 -1
  72. data/samples/processing_app/library/dxf/simple_export.rb +3 -3
  73. data/samples/processing_app/library/pdf/complex_3D.rb +11 -11
  74. data/samples/processing_app/library/vecmath/vec2d/bouncing_ball.rb +1 -1
  75. data/samples/processing_app/library/vecmath/vec2d/circle_collision.rb +3 -3
  76. data/samples/processing_app/library/vecmath/vec2d/library/flock/flock.rb +5 -5
  77. data/samples/processing_app/library/vecmath/vec2d/library/particle/{particle_system.rb → particle.rb} +28 -21
  78. data/samples/processing_app/library/vecmath/vec2d/morph.rb +3 -3
  79. data/samples/processing_app/library/vecmath/vec2d/particle_system_pshape.rb +3 -3
  80. data/samples/processing_app/library/vecmath/vec2d/reflection1.rb +2 -2
  81. data/samples/processing_app/library/vecmath/vec2d/seeking_neural.rb +3 -2
  82. data/samples/processing_app/library/vecmath/vec2d/simple_particle_system.rb +1 -1
  83. data/samples/processing_app/library/vecmath/vec3d/frame_of_reference.rb +4 -4
  84. data/samples/processing_app/topics/advanced_data/library/word/word.rb +1 -1
  85. data/samples/processing_app/topics/advanced_data/load_save_XML.rb +1 -1
  86. data/samples/processing_app/topics/advanced_data/load_save_json.rb +1 -1
  87. data/samples/processing_app/topics/advanced_data/load_save_struct_yaml.rb +1 -1
  88. data/samples/processing_app/topics/advanced_data/load_save_yaml.rb +1 -1
  89. data/samples/processing_app/topics/advanced_data/threads_two.rb +1 -2
  90. data/samples/processing_app/topics/cellular_automata/game_of_life.rb +3 -3
  91. data/samples/processing_app/topics/cellular_automata/library/ca/ca.rb +2 -2
  92. data/samples/processing_app/topics/cellular_automata/library/cell/cell.rb +4 -4
  93. data/samples/processing_app/topics/cellular_automata/library/simple_cell/simple_cell.rb +1 -1
  94. data/samples/processing_app/topics/cellular_automata/spore1.rb +1 -1
  95. data/samples/processing_app/topics/cellular_automata/spore2.rb +1 -1
  96. data/samples/processing_app/topics/create_shapes/group_pshape.rb +2 -2
  97. data/samples/processing_app/topics/create_shapes/library/particle/particle_system.rb +3 -3
  98. data/samples/processing_app/topics/create_shapes/library/polygon/polygon.rb +2 -2
  99. data/samples/processing_app/topics/create_shapes/library/star/star.rb +3 -3
  100. data/samples/processing_app/topics/create_shapes/particle_system_pshape.rb +1 -1
  101. data/samples/processing_app/topics/create_shapes/path_pshape.rb +1 -1
  102. data/samples/processing_app/topics/drawing/scribble_plotter.rb +2 -2
  103. data/samples/processing_app/topics/gui/button.rb +16 -16
  104. data/samples/processing_app/topics/gui/rollover.rb +13 -13
  105. data/samples/processing_app/topics/image_processing/blur.rb +2 -2
  106. data/samples/processing_app/topics/image_processing/edge_detection.rb +2 -2
  107. data/samples/processing_app/topics/lsystems/cstest.rb +1 -1
  108. data/samples/processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb +1 -1
  109. data/samples/processing_app/topics/motion/bouncy_bubbles.rb +1 -1
  110. data/samples/processing_app/topics/motion/brownian.rb +2 -2
  111. data/samples/processing_app/topics/motion/circle_collision.rb +1 -1
  112. data/samples/processing_app/topics/motion/cubes_in_cube.rb +1 -1
  113. data/samples/processing_app/topics/motion/library/cube/cube.rb +2 -2
  114. data/samples/processing_app/topics/motion/morph.rb +11 -11
  115. data/samples/processing_app/topics/motion/moving_on_curves.rb +4 -4
  116. data/samples/processing_app/topics/motion/puff.rb +4 -4
  117. data/samples/processing_app/topics/motion/reflection1.rb +3 -3
  118. data/samples/processing_app/topics/motion/reflection2.rb +1 -1
  119. data/samples/processing_app/topics/shaders/bw_shader.rb +1 -1
  120. data/samples/processing_app/topics/shaders/glsl_heightmap_noise.rb +2 -2
  121. data/samples/processing_app/topics/simulate/flocking.rb +6 -6
  122. data/samples/processing_app/topics/simulate/library/flock/flock.rb +33 -41
  123. data/samples/processing_app/topics/simulate/multiple_particle_systems.rb +34 -60
  124. data/samples/processing_app/topics/simulate/simple_particle_system.rb +20 -32
  125. data/samples/processing_app/topics/simulate/smoke_particle_system.rb +45 -57
  126. data/samples/processing_app/topics/simulate/springs.rb +40 -44
  127. metadata +4 -5
  128. data/samples/processing_app/library/vecmath/vec2d/multiple_particle_systems.rb +0 -141
  129. data/samples/processing_app/library/vecmath/vec2d/smoke_particle_system.rb +0 -133
@@ -108,13 +108,13 @@ def train
108
108
  end
109
109
 
110
110
  def result_label(result)
111
- if result.inject(0, :+).between?(1.9, 2.1)
111
+ if result.reduce(0, :+).between?(1.9, 2.1)
112
112
  if result[0] < 0.01 && result[1].between?(0.99, 1.0) && result[2].between?(0.99, 1.0)
113
113
  return "CIRCLE"
114
114
  else
115
115
  return "UNKNOWN"
116
116
  end
117
- elsif result.inject(0, :+).between?(0.95, 1.1)
117
+ elsif result.reduce(0, :+).between?(0.95, 1.1)
118
118
  if result[0].between?(0.95, 1.0) && (result[1] + result[2]) < 0.01
119
119
  return "TRIANGLE"
120
120
  elsif result[1].between?(0.95, 1.0) && (result[0] + result[2]) < 0.01
@@ -87,8 +87,8 @@ def tick! # When the clock ticks
87
87
  (0 ... column).each do |y|
88
88
  # And visit all the neighbours of each cell
89
89
  neighbours = 0 # We'll count the neighbours
90
- (x - 1 .. x + 1).each do |xx|
91
- (y - 1 .. y + 1).each do |yy|
90
+ (x - 1..x + 1).each do |xx|
91
+ (y - 1..y + 1).each do |yy|
92
92
  # Make sure you are not out of bounds
93
93
  if [(xx>=0), (xx<row), (yy>=0), (yy<column)].all? {|in_bounds| in_bounds == true}
94
94
  # Make sure to check against self
@@ -101,7 +101,7 @@ def tick! # When the clock ticks
101
101
  end # End of yy loop
102
102
  end #End of xx loop
103
103
  # We've checked the neighbours: apply rules in one line (only in ruby)!
104
- cells.set([x, y], (cells_buffer.get([x, y]))? ((2 .. 3) === neighbours) : (neighbours == 3))
104
+ cells.set([x, y], (cells_buffer.get([x, y]))? ((2..3) === neighbours) : (neighbours == 3))
105
105
  end # End of y loop
106
106
  end # End of x loop
107
107
  end # End of function
@@ -12,7 +12,7 @@ def setup
12
12
  @mods = []
13
13
  wide_count.times do |i|
14
14
  height_count.times do |j|
15
- mods << CustomObject.new(j * UNIT, i * UNIT, UNIT/2, UNIT/2, rand(0.05 .. 0.8))
15
+ mods << CustomObject.new(j * UNIT, i * UNIT, UNIT/2, UNIT/2, rand(0.05..0.8))
16
16
  end
17
17
  end
18
18
  no_stroke
@@ -41,7 +41,7 @@ class CustomObject
41
41
 
42
42
  def update
43
43
  @x += @speed * @xdir
44
- unless (0 .. size).cover? x
44
+ unless (0..size).cover? x
45
45
  @xdir *= -1
46
46
  @x += @xdir
47
47
  @y += @ydir
@@ -15,7 +15,7 @@ end
15
15
  def draw
16
16
  (width/@bar_width).times do |i|
17
17
  n = i * @bar_width
18
- range = (n .. n + @bar_width)
18
+ range = (n..n + @bar_width)
19
19
  @hue[i] = mouse_y if range.include?(mouse_x)
20
20
  fill @hue[i], height/1.2, height/1.2
21
21
  rect n, 0, @bar_width, height
@@ -1,14 +1,14 @@
1
- # Conditions are like questions.
2
- # They allow a program to decide to take one action if
1
+ # Conditions are like questions.
2
+ # They allow a program to decide to take one action if
3
3
  # the answer to a question is true or to do another action
4
- # if the answer to the question is false.
4
+ # if the answer to the question is false.
5
5
  # The questions asked within a program are always logical
6
- # or relational statements. For example, if the variable 'i' is
6
+ # or relational statements. For example, if the variable 'i' is
7
7
  # "even" then draw short line, else draw a long one.
8
8
 
9
9
 
10
10
  def setup
11
- size 640, 360
11
+ size 640, 360
12
12
  background 0
13
13
  stroke_weight 8
14
14
  (5 ... width/2).step(5) do |i|
@@ -25,22 +25,3 @@ def draw_long(i)
25
25
  stroke 153
26
26
  line i * 2, 20, i * 2, 180
27
27
  end
28
-
29
-
30
- # Ruby allows us to extend base classes, such as numbers, with
31
- # methods of our choosing. In this case we'll add methods that tell
32
- # you whether a given integer is divisible by 2, which here we declare
33
- # as even or odd.
34
-
35
- class Fixnum
36
-
37
- def even?
38
- self % 2 == 0
39
- end
40
-
41
- def odd?
42
- !even?
43
- end
44
-
45
- end
46
-
@@ -12,7 +12,7 @@ def setup
12
12
  (2 ... width - 2 ).step(2) do |i|
13
13
 
14
14
  # If 'i' divides by 20 with no remainder
15
- # draw the first line ..
15
+ # draw the first line..
16
16
  # else if 'i' divides by 10 with no remainder
17
17
  # draw second line, else draw third line
18
18
 
@@ -24,7 +24,7 @@ end
24
24
  def draw
25
25
  background 145
26
26
  draw_ellipse
27
- set_ellipse rand(3 .. 12), rand(-100 .. 150), rand(-100 .. 150)
27
+ set_ellipse rand(3..12), rand(-100..150), rand(-100..150)
28
28
  end
29
29
 
30
30
  def draw_ellipse
@@ -12,7 +12,7 @@ def setup
12
12
  @brick_layers = 18
13
13
  @brick_width, @brick_height, @brick_depth = 60, 25, 25
14
14
  @radius = 175.0
15
- @angle = 0
15
+ @angle = 0
16
16
  @brick = Cubeish.new(@brick_width, @brick_height, @brick_depth)
17
17
  end
18
18
 
@@ -24,7 +24,7 @@ def draw
24
24
  lights
25
25
  translate(width / 2.0, height * 1.2, -380) # move viewpoint into position
26
26
  rotate_x(-45.radians) # tip tower to see inside
27
- rotate_y(frame_count * PI/600) # slowly rotate tower
27
+ rotate_y(frame_count * PI / 600) # slowly rotate tower
28
28
  brick_layers.times { |i| draw_layer(i) }
29
29
  end
30
30
 
@@ -42,9 +42,8 @@ def draw_bricks(brick_num)
42
42
  translate temp_x, temp_y, temp_z
43
43
  rotate_y(angle.radians)
44
44
  top_layer = layer_num == brick_layers - 1
45
- even_brick = brick_num % 2 == 0
46
45
  brick.create unless top_layer # main tower
47
- brick.create if top_layer && even_brick # add crenelation
46
+ brick.create if top_layer && brick_num.even? # add crenelation
48
47
  pop_matrix
49
48
  @angle += 360.0 / bricks_per_layer
50
49
  end
@@ -65,13 +64,11 @@ class Cubeish
65
64
  top: ['-- ', '---', ' --', ' - '],
66
65
  bottom: ['- ', '- -', ' -', ' ']}
67
66
 
68
- SIGNS = {'-' => -1,
69
- ' ' => 1}
67
+ SIGNS = {'-' => -1, ' ' => 1}
70
68
 
71
69
  def initialize(width, height, depth)
72
70
  @vertices = {}
73
71
  @w, @h, @d = width, height, depth
74
-
75
72
  SIDES.each do |side, signs|
76
73
  vertices[side] = signs.map do |s|
77
74
  s = s.split('').map { |el| SIGNS[el] }
@@ -87,7 +84,6 @@ class Cubeish
87
84
  end_shape
88
85
  end
89
86
  end
90
-
91
87
  end
92
88
 
93
89
  Vect = Struct.new(:x, :y, :z)
@@ -37,7 +37,7 @@ end
37
37
  def polygon(x, y, radius, npoints)
38
38
  angle = TAU / npoints
39
39
  begin_shape
40
- (0 .. TAU).step(angle) do |a|
40
+ (0..TAU).step(angle) do |a|
41
41
  sx = x + cos(a) * radius
42
42
  sy = y + sin(a) * radius
43
43
  vertex(sx, sy)
@@ -36,7 +36,7 @@ def star(x, y, radius1, radius2, npoints)
36
36
  angle = TAU / npoints
37
37
  half_angle = angle/2.0
38
38
  begin_shape
39
- (0 .. TAU).step(angle) do |a|
39
+ (0..TAU).step(angle) do |a|
40
40
  sx = x + cos(a) * radius2
41
41
  sy = y + sin(a) * radius2
42
42
  vertex(sx, sy)
@@ -24,7 +24,7 @@ def draw
24
24
  step = 180.0/pts # degrees
25
25
 
26
26
  begin_shape TRIANGLE_STRIP
27
- (0 .. pts).each do
27
+ (0..pts).each do
28
28
  px = x + cos(angle.radians)*outer_radius
29
29
  py = y + sin(angle.radians)*outer_radius
30
30
  angle += step
@@ -30,7 +30,7 @@ def draw
30
30
  which = frame_count % NUM
31
31
  pos[which] = Vec.new(mouse_x, mouse_y)
32
32
 
33
- (1 .. NUM).each do |i|
33
+ (1..NUM).each do |i|
34
34
  # which + 1 is the smallest (the oldest in the array)
35
35
  idx = (which + i) % NUM
36
36
  ellipse(pos[idx].x, pos[idx].y, i, i)
@@ -9,7 +9,7 @@ def setup
9
9
 
10
10
  size 640, 360, P3D
11
11
 
12
- @concentration = 600 # try values between 1 <-> 10000
12
+ @concentration = 600 # try values between 1 <-> 10_000
13
13
 
14
14
  no_stroke
15
15
  fill 204
@@ -16,8 +16,8 @@ def setup
16
16
  @dx = [] # Value for incrementing X, to be calculated as a function of period and x_spacing
17
17
 
18
18
  @max_waves.times do |i|
19
- amplitude << rand(10 .. 30)
20
- period = rand(100 .. 300) # How many pixels before the wave repeats
19
+ amplitude << rand(10..30)
20
+ period = rand(100..300) # How many pixels before the wave repeats
21
21
  dx << (TAU / period) * @x_spacing
22
22
  end
23
23
 
@@ -22,9 +22,9 @@ def draw
22
22
  background 0
23
23
  rand_y = 0.0
24
24
  (1 ... steps).each do |i|
25
- noise_y = (rand_y > 0)? rand(-rand_y .. rand_y) : rand(rand_y .. -rand_y)
25
+ noise_y = (rand_y > 0)? rand(-rand_y..rand_y) : rand(rand_y..-rand_y)
26
26
  point( (width/steps) * i, (height/2) + noise_y )
27
- rand_y += rand(-5 .. 5)
27
+ rand_y += rand(-5..5)
28
28
  end
29
29
  end
30
30
 
@@ -23,7 +23,7 @@ def draw
23
23
  # xoff = yoff # Option #2: 1D Noise
24
24
 
25
25
  # Iterate over horizontal pixels
26
- (0 .. width).step(10) do |x|
26
+ (0..width).step(10) do |x|
27
27
  # Calculate a y value according to noise, map to
28
28
  y = map(noise(xoff, yoff), 0, 1, 200,300) # Option #1: 2D Noise
29
29
  # y = map(noise(xoff), 0, 1, 200,300) # Option #2: 1D Noise
@@ -14,7 +14,7 @@ def draw
14
14
  background 0
15
15
  (0...width).each do |i|
16
16
  r = rand(255)
17
- x = rand(0 .. width)
17
+ x = rand(0..width)
18
18
  stroke(r, 100)
19
19
  line(i, 0, x, height)
20
20
  end
@@ -62,7 +62,7 @@ class Particle
62
62
  attr_reader :loc, :vel, :acc, :lifespan
63
63
  def initialize(loc)
64
64
  @acc = Vec2D.new(0, 0.05)
65
- @vel = Vec2D.new(rand(-1.0 .. 1), rand(-2.0 .. 0))
65
+ @vel = Vec2D.new(rand(-1.0..1), rand(-2.0..0))
66
66
  @loc = loc # loc.clone is unecessary in ruby
67
67
  @lifespan = 255.0
68
68
  end
@@ -30,7 +30,7 @@ def draw
30
30
  which = frame_count % NUM
31
31
  pos[which] = Vec.new(mouse_x, mouse_y)
32
32
 
33
- (1 .. NUM).each do |i|
33
+ (1..NUM).each do |i|
34
34
  # which + 1 is the smallest (the oldest in the array)
35
35
  idx = (which + i) % NUM
36
36
  ellipse(pos[idx].x, pos[idx].y, i, i)
@@ -1,25 +1,30 @@
1
- # No Loop.
2
- #
1
+ # No Loop.
2
+ #
3
3
  # The noLoop() function causes draw() to only
4
4
  # execute once. Without calling noLoop(), draw()
5
- # executed continually.
6
- attr_reader :y
5
+ # executed continually.
6
+ attr_reader :y, :clicked
7
7
 
8
- def setup
9
- size 640, 360
10
- @y = height / 2
8
+ def setup
9
+ size 640, 360
10
+ @y = height / 2
11
11
  stroke 255
12
- frame_rate 30
13
- no_loop
12
+ frame_rate 30
13
+ @clicked = true
14
14
  end
15
15
 
16
- def draw
17
- background 0
16
+ def draw
17
+ background 0
18
18
  @y = y - 1
19
- @y = height if y < 0
19
+ @y = height if y < 0
20
20
  line 0, y, width, y
21
- end
21
+ end
22
22
 
23
23
  def mouse_pressed
24
- loop
24
+ unless clicked
25
+ no_loop
26
+ else
27
+ loop
28
+ end
29
+ @clicked = !clicked
25
30
  end
@@ -12,9 +12,9 @@ def draw_circle (x, y, radius, level)
12
12
  ellipse x, y, radius * 2, radius * 2
13
13
  if level > 1
14
14
  level = level - 1
15
- num = rand(2 .. 6)
15
+ num = rand(2..6)
16
16
  0.upto(num-1) do |i|
17
- a = rand(0 .. TAU)
17
+ a = rand(0..TAU)
18
18
  nx = x + cos(a) * 8.0 * level
19
19
  ny = y + sin(a) * 6.0 * level
20
20
  draw_circle nx, ny, radius / 2, level
@@ -1,64 +1,44 @@
1
- # Texture 3.
2
- #
3
- # Load an image and draw it onto a cylinder and a quad.
1
+ # Texture 3.
2
+ #
3
+ # Load an image and draw it onto a cylinder and a quad.
4
4
 
5
5
  attr_reader :tube_res, :tube_x, :tube_y, :img
6
6
 
7
7
  def setup
8
-
9
8
  size 640, 360, P3D
10
-
11
9
  @tube_res = 32
12
10
  @tube_x = []
13
11
  @tube_y = []
14
-
15
- @img = load_image "berlin-1.jpg"
16
-
12
+ @img = load_image 'berlin-1.jpg'
17
13
  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 ) )
14
+ (0 ... tube_res).each { |i|
15
+ tube_x.push cos((i * angle).radians)
16
+ tube_y.push sin((i * angle).radians)
22
17
  }
23
-
24
18
  no_stroke
25
-
26
19
  end
27
20
 
28
21
  def draw
29
-
30
22
  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
-
23
+ translate width / 2, height / 2
24
+ rotate_x map1d(mouse_y, (0..height), (-PI..PI))
25
+ rotate_y map1d(mouse_x, (0..width), (-PI..PI))
36
26
  begin_shape QUAD_STRIP
37
-
38
27
  texture img
39
-
40
- (0...tube_res).each { |i|
41
-
28
+ (0 ... tube_res).each { |i|
42
29
  x = tube_x[i] * 100
43
30
  z = tube_y[i] * 100
44
31
  u = img.width / tube_res * i
45
-
46
32
  vertex x, -100, z, u, 0
47
33
  vertex x, 100, z, u, img.height
48
-
49
34
  }
50
-
51
35
  end_shape
52
-
53
36
  begin_shape QUADS
54
-
55
37
  texture img
56
-
57
38
  vertex 0, -100, 0, 0, 0
58
39
  vertex 100, -100, 0, 100, 0
59
40
  vertex 100, 100, 0, 100, 100
60
41
  vertex 0, 100, 0, 0, 100
61
-
62
42
  end_shape
63
-
64
- end
43
+
44
+ end
@@ -13,11 +13,11 @@ def setup
13
13
  size 640, 360, P3D
14
14
  no_stroke
15
15
  lights
16
- @birds = (0 .. BIRD_COUNT).map {
17
- Bird.new(rand(-300 .. 300), rand(-300 .. 300), rand(-2500 .. -500), rand(5 .. 30), rand(5 .. 30))
18
- .set_flight(rand(20 .. 340), rand(30 .. 350), rand( 1000 .. 4800 ), rand(-160 .. 160), rand(-55 .. 55), rand(-20 .. 20))
19
- .set_wing_speed(rand(0.1 .. 3.75))
20
- .set_rot_speed(rand(0.025 .. 0.15))
16
+ @birds = (0..BIRD_COUNT).map {
17
+ Bird.new(rand(-300..300), rand(-300..300), rand(-2500..-500), rand(5..30), rand(5..30))
18
+ .set_flight(rand(20..340), rand(30..350), rand( 1000..4800 ), rand(-160..160), rand(-55..55), rand(-20..20))
19
+ .set_wing_speed(rand(0.1..3.75))
20
+ .set_rot_speed(rand(0.025..0.15))
21
21
  }
22
22
  end
23
23
 
@@ -20,11 +20,11 @@ def setup
20
20
  @cubes = []
21
21
 
22
22
  0.upto( @cube_count ) do |i|
23
- cube_size = rand(5 .. 15)
23
+ cube_size = rand(5..15)
24
24
  c = Cube.new(cube_size)
25
25
  c.position = Vec3D.new(0.0, 0.0, 0.0)
26
- c.speed = Vec3D.new(rand(-1.0 .. 1), rand(-1.0 .. 1), rand(-1.0 .. 1))
27
- c.rotation = Vec3D.new(rand(40 .. 100), rand(40 .. 100), rand(40 .. 100))
26
+ c.speed = Vec3D.new(rand(-1.0..1), rand(-1.0..1), rand(-1.0..1))
27
+ c.rotation = Vec3D.new(rand(40..100), rand(40..100), rand(40..100))
28
28
  @cubes << c
29
29
  end
30
30