ruby-processing 2.6.2 → 2.6.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -21,7 +21,7 @@ def setup
21
21
  @renderer = AppRender.new(self)
22
22
  frame_rate(15)
23
23
  # Create a circle using vectors pointing from center
24
- (ALPHA .. OMEGA).step(THETA) do |angle|
24
+ (ALPHA..OMEGA).step(THETA) do |angle|
25
25
  # Note we are not starting from 0 in order to match the
26
26
  # path of a circle.
27
27
  circle << Vec2D.from_angle(angle) * 100
@@ -31,11 +31,11 @@ def setup
31
31
 
32
32
  # A square is a bunch of vertices along straight line
33
33
  # Top of square
34
- (-50 .. 50).step(10) do |x|
34
+ (-50..50).step(10) do |x|
35
35
  square << Vec2D.new(x, -50)
36
36
  end
37
37
  # Right side
38
- (-50 .. 50).step(10) do |y|
38
+ (-50..50).step(10) do |y|
39
39
  square << Vec2D.new(50, y)
40
40
  end
41
41
  # Bottom, NB: can't negative step ruby so use your loaf
@@ -12,14 +12,14 @@ attr_reader :ps
12
12
  def setup
13
13
  size(640, 360, P2D)
14
14
  # Load the image
15
- sprite = loadImage('sprite.png')
15
+ sprite = load_image('sprite.png')
16
16
  # A new particle system with 10,000 particles
17
17
  @ps = ParticleSystem.new(width, height, sprite, 10_000)
18
18
  # Writing to the depth buffer is disabled to avoid rendering
19
19
  # artifacts due to the fact that the particles are semi-transparent
20
20
  # but not z-sorted.
21
21
  hint(DISABLE_DEPTH_MASK)
22
- end
22
+ end
23
23
 
24
24
  def draw
25
25
  background(0)
@@ -31,6 +31,6 @@ def draw
31
31
  # Display frame rate
32
32
  fill(255, 0, 255)
33
33
  text_size(16)
34
- text("Frame rate: #{frame_rate.round(1)}", 10, 20)
34
+ text("Frame rate: #{format('%0.1f', frame_rate)}", 10, 20)
35
35
  end
36
36
 
@@ -87,8 +87,8 @@ def draw
87
87
  @position.y = radius
88
88
  @direction.y *= -1
89
89
  # randomize base top
90
- @base1.y = rand(height - 100 .. height)
91
- @base2.y = rand(height - 100 .. height)
90
+ @base1.y = rand(height - 100..height)
91
+ @base2.y = rand(height - 100..height)
92
92
  @coords = create_ground
93
93
  end
94
94
  end
@@ -9,7 +9,7 @@ module SeekingNeural
9
9
  class Perceptron
10
10
  # Perceptron is created with n weights and learning constant
11
11
  def initialize(n, c)
12
- @weights = Array.new(n) { rand(0 .. 1.0) }
12
+ @weights = Array.new(n) { rand(0..1.0) }
13
13
  @c = c
14
14
  end
15
15
 
@@ -25,7 +25,8 @@ module SeekingNeural
25
25
  # Give me a steering result
26
26
  def feedforward(forces)
27
27
  # Sum all values
28
- forces.zip(@weights).map { |a, b| a * b }.inject(Vec2D.new, :+)
28
+ forces.zip(@weights).map { |a, b| a * b }.reduce(Vec2D.new, :+)
29
+ # forces.zip(@weights).map { |a, b| a * b }.reduce(:+)
29
30
  end
30
31
  end
31
32
 
@@ -58,7 +58,7 @@ class Particle
58
58
  attr_reader :loc, :vel, :acc, :lifespan
59
59
  def initialize(loc)
60
60
  @acc = Vec2D.new(0, 0.05)
61
- @vel = Vec2D.new(rand(-1.0 .. 1), rand(-2.0 .. 0))
61
+ @vel = Vec2D.new(rand(-1.0..1), rand(-2.0..0))
62
62
  @loc = loc # loc.clone is unecessary in ruby
63
63
  @lifespan = 255.0
64
64
  end
@@ -20,10 +20,10 @@ def setup
20
20
  FACE_COUNT.times do |i|
21
21
 
22
22
  # calc some random triangles in 3 space
23
- val = Vec3D.new(rand(-width/2 .. width/2), rand(-width/2 .. width/2), rand(-width/2 .. width/2))
24
- v0 = Vec3D.new(rand(-val.x .. -val.x + 100), rand(-val.y .. -val.y + 100), rand(-val.z .. -val.z + 100))
25
- v1 = Vec3D.new(rand(-val.x .. -val.x + 100), rand(-val.y .. -val.y + 100), rand(-val.z .. -val.z + 100))
26
- v2 = Vec3D.new(rand(-val.x .. -val.x + 100), rand(-val.y .. -val.y + 100), rand(-val.z .. -val.z + 100))
23
+ val = Vec3D.new(rand(-width/2..width/2), rand(-width/2..width/2), rand(-width/2..width/2))
24
+ v0 = Vec3D.new(rand(-val.x..-val.x + 100), rand(-val.y..-val.y + 100), rand(-val.z..-val.z + 100))
25
+ v1 = Vec3D.new(rand(-val.x..-val.x + 100), rand(-val.y..-val.y + 100), rand(-val.z..-val.z + 100))
26
+ v2 = Vec3D.new(rand(-val.x..-val.x + 100), rand(-val.y..-val.y + 100), rand(-val.z..-val.z + 100))
27
27
  p << Plane.new([v0, v1, v2])
28
28
 
29
29
  # build some cute little cylinders
@@ -12,7 +12,7 @@ class Word
12
12
  def initialize(s)
13
13
  @width, @height = $app.width, $app.height
14
14
  @count_dracula, @count_franken, @total_count = 0, 0, 0
15
- @position = [rand(width), rand(-height .. height*2)]
15
+ @position = [rand(width), rand(-height..height*2)]
16
16
  @word = s
17
17
  end
18
18
 
@@ -90,7 +90,7 @@ def mouse_pressed
90
90
  # Set the diameter element
91
91
  diameter = bubble.add_child('diameter')
92
92
  # Here for a node's content, we have to convert to a String
93
- diameter.set_content(rand(40.0 .. 80).to_s)
93
+ diameter.set_content(rand(40.0..80).to_s)
94
94
 
95
95
  # Set a label
96
96
  label = bubble.add_child('label')
@@ -47,7 +47,7 @@ class BubbleData
47
47
  end
48
48
 
49
49
  def create_new_bubble x, y
50
- self.add Bubble.new(x, y, rand(40 .. 80), 'new label')
50
+ self.add Bubble.new(x, y, rand(40..80), 'new label')
51
51
  save_data
52
52
  load_data path
53
53
  end
@@ -42,7 +42,7 @@ class BubbleData
42
42
  end
43
43
 
44
44
  def create_new_bubble x, y
45
- self.add Bubble.new(x, y, rand(40 .. 80), 'new label')
45
+ self.add Bubble.new(x, y, rand(40..80), 'new label')
46
46
  save_data
47
47
  load_data path
48
48
  end
@@ -41,7 +41,7 @@ class BubbleData
41
41
  end
42
42
 
43
43
  def create_new_bubble x, y
44
- self.add Bubble.new(x, y, rand(40 .. 80), 'new label')
44
+ self.add Bubble.new(x, y, rand(40..80), 'new label')
45
45
  save_data
46
46
  load_data path
47
47
  end
@@ -16,8 +16,7 @@ def setup
16
16
  @curr = 0
17
17
  thread do # supply a block in ruby-processing rather than use reflection
18
18
  FRAMES.times do |i|
19
- frames << load_image("a#{i.to_s.rjust(3, "0")} copy.jpg") # ruby syntax
20
- #frames << load_image("a#{nf(i, 3)} copy.jpg") # processing function nf
19
+ frames << load_image("a#{i.to_s.rjust(3, '0')} copy.jpg") # ruby syntax
21
20
  @curr = i
22
21
  delay(75) #just slows down this thread - the main draw cycle is unaffected...
23
22
  end
@@ -82,8 +82,8 @@ def tick! # When the clock ticks
82
82
  column.times do |y|
83
83
  # And visit all the neighbours of each cell
84
84
  neighbours = 0 # We'll count the neighbours
85
- (x - 1 .. x + 1).each do |xx|
86
- (y - 1 .. y + 1).each do |yy|
85
+ (x - 1..x + 1).each do |xx|
86
+ (y - 1..y + 1).each do |yy|
87
87
  # Make sure you are not out of bounds
88
88
  if [(xx>=0), (xx<row), (yy>=0), (yy<column)].all? {|in_bounds| in_bounds == true}
89
89
  # Make sure to check against self
@@ -96,7 +96,7 @@ def tick! # When the clock ticks
96
96
  end # End of yy loop
97
97
  end #End of xx loop
98
98
  # We've checked the neighbours: apply rules in one line (only in ruby)!
99
- cells[x][y] = (cells_buffer[x][y])? ((2 .. 3) === neighbours) : (neighbours == 3)
99
+ cells[x][y] = (cells_buffer[x][y])? ((2..3) === neighbours) : (neighbours == 3)
100
100
  end # End of y loop
101
101
  end # End of x loop
102
102
  end # End of function
@@ -23,7 +23,7 @@ class CA
23
23
 
24
24
  # Return a random ruleset
25
25
  def randomize
26
- @rules = Array.new(8) {rand(0 .. 1)}
26
+ @rules = Array.new(8) {rand(0..1)}
27
27
  end
28
28
 
29
29
  # Reset to generation 0
@@ -46,7 +46,7 @@ class CA
46
46
  nextgen[i] = execute_rules(left, me, right) # Compute next generation state based on ruleset
47
47
  end
48
48
  # Copy the array into current value
49
- (1 .. cells.length - 1).each do |i|
49
+ (1..cells.length - 1).each do |i|
50
50
  cells[i] = nextgen[i]
51
51
  end
52
52
  @generation += 1
@@ -38,7 +38,7 @@ class Cell
38
38
  elsif (outer.getpix(x + 1, y) == spore1 && outer.getpix(x + 1, y - 1) == black)
39
39
  move(1, -1)
40
40
  else
41
- move(rand(1 .. 2), 0)
41
+ move(rand(1..2), 0)
42
42
  end
43
43
  elsif (my_color == spore2)
44
44
  if (outer.getpix(x - 1, y + 1) == black && outer.getpix(x + 1, y + 1) == black && outer.getpix(x, y + 1) == black)
@@ -52,7 +52,7 @@ class Cell
52
52
  elsif (outer.getpix(x - 1, y) == spore2 && outer.getpix(x - 1, y - 1) == black)
53
53
  move(-1, -1)
54
54
  else
55
- move(rand(1 .. 2), 0)
55
+ move(rand(1..2), 0)
56
56
  end
57
57
  elsif (my_color == spore3)
58
58
  if (outer.getpix(x - 1, y - 1) == black && outer.getpix(x + 1, y - 1) == black && outer.getpix(x, y - 1) == black)
@@ -66,7 +66,7 @@ class Cell
66
66
  elsif (outer.getpix(x + 1, y) == spore3 && outer.getpix(x + 1, y + 1) == black)
67
67
  move(1, 1)
68
68
  else
69
- move(rand(1 .. 2), 0)
69
+ move(rand(1..2), 0)
70
70
  end
71
71
  elsif (my_color == spore4)
72
72
  if (outer.getpix(x - 1, y - 1) == black && outer.getpix(x + 1, y - 1) == black && outer.getpix(x, y - 1) == black)
@@ -80,7 +80,7 @@ class Cell
80
80
  elsif (outer.getpix(x - 1, y) == spore4 && outer.getpix(x - 1, y + 1) == black)
81
81
  move(-1, 1)
82
82
  else
83
- move(rand(1 .. 2), 0)
83
+ move(rand(1..2), 0)
84
84
  end
85
85
  end
86
86
  end
@@ -28,7 +28,7 @@ class Cell
28
28
  if (outer.getpix(x + 1, y) == black)
29
29
  move(0, 1)
30
30
  elsif (outer.getpix(x, y - 1) != black && outer.getpix(x - 1, y - 1) != black)
31
- move(rand(-4 .. 4), rand(-4 .. 4))
31
+ move(rand(-4..4), rand(-4..4))
32
32
  end
33
33
  end
34
34
 
@@ -15,7 +15,7 @@ attr_reader :cells, :black, :spore_colour
15
15
  MAX_CELLS = 6700
16
16
 
17
17
  # set lower for smoother animation, higher for faster simulation
18
- RUNS_PER_LOOP = 10000
18
+ RUNS_PER_LOOP = 10_000
19
19
 
20
20
  def setup
21
21
  size(640, 360)
@@ -15,7 +15,7 @@ attr_reader :cells, :black, :colours, :spore1, :spore2, :spore3, :spore4
15
15
  MAX_CELLS = 8000
16
16
 
17
17
  # set lower for smoother animation, higher for faster simulation
18
- RUNS_PER_LOOP = 10000
18
+ RUNS_PER_LOOP = 10_000
19
19
 
20
20
  def setup
21
21
  size(640, 360)
@@ -36,8 +36,8 @@ def setup
36
36
  path.begin_shape
37
37
  path.no_fill
38
38
  path.stroke(255)
39
- (-PI .. 0).step(0.1) do |theta|
40
- r = rand(60 .. 70)
39
+ (-PI..0).step(0.1) do |theta|
40
+ r = rand(60..70)
41
41
  path.vertex(r*cos(theta), r*sin(theta))
42
42
  end
43
43
  path.end_shape
@@ -50,7 +50,7 @@ class Particle
50
50
 
51
51
  def initialize width, height, sprite
52
52
  @width, @height, @sprite = width, height, sprite
53
- part_size = rand(10 .. 60)
53
+ part_size = rand(10..60)
54
54
  # The particle is a textured quad
55
55
  @s_shape = create_shape
56
56
  s_shape.begin_shape(QUAD)
@@ -71,8 +71,8 @@ class Particle
71
71
  end
72
72
 
73
73
  def rebirth(x, y)
74
- theta = rand(-PI .. PI)
75
- speed = rand(0.5 .. 4)
74
+ theta = rand(-PI..PI)
75
+ speed = rand(0.5..4)
76
76
  # A velocity with random angle and magnitude
77
77
  @velocity = Vec2D.from_angle(theta)
78
78
  @velocity *= speed
@@ -7,9 +7,9 @@ class Polygon
7
7
 
8
8
  def initialize(s_, width, height)
9
9
  @x = rand(width)
10
- @y = rand(-500 .. -100)
10
+ @y = rand(-500..-100)
11
11
  @s = s_
12
- @speed = rand(2 .. 6)
12
+ @speed = rand(2..6)
13
13
  @height = height
14
14
  end
15
15
 
@@ -6,9 +6,9 @@ class Star
6
6
  def initialize(width, height)
7
7
  @width = width
8
8
  @height = height
9
- @x = rand(100 .. width-100)
10
- @y = rand(100 .. height-100)
11
- @speed = rand(0.5 .. 3)
9
+ @x = rand(100..width-100)
10
+ @y = rand(100..height-100)
11
+ @speed = rand(0.5..3)
12
12
  # First create the shape
13
13
  @s = createShape
14
14
  s.beginShape
@@ -14,7 +14,7 @@ def setup
14
14
  # Load the image
15
15
  sprite = loadImage('sprite.png')
16
16
  # A new particle system with 10,000 particles
17
- @ps = ParticleSystem.new(width, height, sprite, 10000)
17
+ @ps = ParticleSystem.new(width, height, sprite, 10_000)
18
18
  # Writing to the depth buffer is disabled to avoid rendering
19
19
  # artifacts due to the fact that the particles are semi-transparent
20
20
  # but not z-sorted.
@@ -20,7 +20,7 @@ def setup
20
20
 
21
21
  x = 0
22
22
  # Calculate the path as a sine wave
23
- (0 .. TAU).step(0.1) do |theta|
23
+ (0..TAU).step(0.1) do |theta|
24
24
  path.vertex(x,sin(theta)*100)
25
25
  x += 5
26
26
  end
@@ -64,13 +64,13 @@ def scribble(x1, y1, x2, y2, steps, scrib_val, style)
64
64
  (0 ... steps).each do |i|
65
65
  if(style == SCRIBBLE)
66
66
  if (i < steps-1)
67
- line(x1, y1, x1 += x_step+rand(-scrib_val .. scrib_val), y1 += y_step + rand(-scrib_val .. scrib_val))
67
+ line(x1, y1, x1 += x_step+rand(-scrib_val..scrib_val), y1 += y_step + rand(-scrib_val..scrib_val))
68
68
  else
69
69
  # extra line needed to attach line back to point- not necessary in HATCHING style
70
70
  line(x1, y1, x2, y2)
71
71
  end
72
72
  elsif (style == HATCHING)
73
- line(x1, y1, (x1 += x_step)+rand(-scrib_val .. scrib_val), (y1 += y_step) + rand(-scrib_val .. scrib_val))
73
+ line(x1, y1, (x1 += x_step)+rand(-scrib_val..scrib_val), (y1 += y_step) + rand(-scrib_val..scrib_val))
74
74
  end
75
75
  end
76
76
  end
@@ -1,8 +1,8 @@
1
1
  #
2
- # Button.
3
- #
4
- # Hover on one of the colored objects in the
5
- # center of the image to change their color
2
+ # Button.
3
+ #
4
+ # Hover on one of the colored objects in the
5
+ # center of the image to change their color
6
6
  #
7
7
 
8
8
  RECT_SIZE = 90 # Diameter of rect
@@ -21,16 +21,16 @@ def setup
21
21
  @base_color = color(102)
22
22
  @current_color = base_color
23
23
  @circle_x = (width + CIRCLE_SIZE) / 2 + 10
24
- @circle_y = height/2
25
- @rect_x = width/2 - RECT_SIZE - 10
26
- @rect_y = height/2 - RECT_SIZE / 2
24
+ @circle_y = height / 2
25
+ @rect_x = width / 2 - RECT_SIZE - 10
26
+ @rect_y = height / 2 - RECT_SIZE / 2
27
27
  ellipse_mode(CENTER)
28
28
  end
29
29
 
30
30
  def draw
31
31
  update(mouse_x, mouse_y)
32
32
  background(current_color)
33
-
33
+
34
34
  if (rect_over)
35
35
  fill(rect_highlight)
36
36
  else
@@ -38,7 +38,7 @@ def draw
38
38
  end
39
39
  stroke(255)
40
40
  rect(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
41
-
41
+
42
42
  if (circle_over)
43
43
  fill(circle_highlight)
44
44
  else
@@ -49,26 +49,26 @@ def draw
49
49
  end
50
50
 
51
51
  def update(x, y)
52
- if over_circle?(circle_x, circle_y, CIRCLE_SIZE)
52
+ if over_circle?(circle_x, circle_y, CIRCLE_SIZE)
53
53
  @circle_over, @rect_over = true, false
54
- elsif over_rect?(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
54
+ elsif over_rect?(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
55
55
  @circle_over, @rect_over = false, true
56
56
  else
57
57
  @circle_over, @rect_over = false, false
58
58
  end
59
59
  end
60
60
 
61
- def mouse_pressed
62
- @current_color = (circle_over)? circle_color : (rect_over)?
63
- rect_color : current_color
61
+ def mouse_pressed
62
+ @current_color = (circle_over)? circle_color : (rect_over)?
63
+ rect_color : current_color
64
64
  end
65
65
 
66
66
  def over_rect?(x, y, width, height)
67
- (mouse_x >= x && mouse_x <= x + width && mouse_y >= y && mouse_y <= y + height)
67
+ (x..width + x).include?(mouse_x) && (y..height + y).include?(mouse_y)
68
68
  end
69
69
 
70
70
  def over_circle?(x, y, diameter)
71
71
  dis_x = x - mouse_x
72
72
  dis_y = y - mouse_y
73
- (sqrt(sq(dis_x) + sq(dis_y)) < diameter/2 )
73
+ hypot(dis_x, dis_y) < diameter / 2
74
74
  end
@@ -1,9 +1,9 @@
1
1
  #
2
- # Button.
3
- #
4
- # Click on one of the colored squares in the
5
- # center of the image to change the color of
6
- # the background.
2
+ # Button.
3
+ #
4
+ # Click on one of the colored squares in the
5
+ # center of the image to change the color of
6
+ # the background.
7
7
  #
8
8
 
9
9
  RECT_SIZE = 90 # Diameter of rect
@@ -26,26 +26,26 @@ def setup
26
26
  end
27
27
 
28
28
  def draw
29
- update(mouse_x, mouse_y)
30
- if (rect_over)
29
+ update(mouse_x, mouse_y)
30
+ if (rect_over)
31
31
  background(rect_color)
32
- elsif (circle_over)
32
+ elsif (circle_over)
33
33
  background(circle_color)
34
- else
34
+ else
35
35
  background(base_color)
36
36
  end
37
37
  stroke(255)
38
38
  fill(rect_color)
39
- rect(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
39
+ rect(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
40
40
  stroke(0)
41
41
  fill(circle_color)
42
42
  ellipse(circle_x, circle_y, CIRCLE_SIZE, CIRCLE_SIZE)
43
43
  end
44
44
 
45
45
  def update(x, y)
46
- if over_circle?(circle_x, circle_y, CIRCLE_SIZE)
46
+ if over_circle?(circle_x, circle_y, CIRCLE_SIZE)
47
47
  @circle_over, @rect_over = true, false
48
- elsif over_rect?(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
48
+ elsif over_rect?(rect_x, rect_y, RECT_SIZE, RECT_SIZE)
49
49
  @circle_over, @rect_over = false, true
50
50
  else
51
51
  @circle_over, @rect_over = false, false
@@ -59,5 +59,5 @@ end
59
59
  def over_circle?(x, y, diameter)
60
60
  dis_x = x - mouse_x
61
61
  dis_y = y - mouse_y
62
- (sqrt(sq(dis_x) + sq(dis_y)) < diameter/2 )
62
+ (hypot(dis_x, dis_y) < diameter/2 )
63
63
  end