Skip to content

Commit bfb504d

Browse files
committed
tidy up
1 parent 287ae01 commit bfb504d

File tree

12 files changed

+74
-69
lines changed

12 files changed

+74
-69
lines changed

contributed/arc_tesselation.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# press mouse to generate new pattern
77
# use `c` key to toggle colored / greyscale
88
# use 's' to save
9-
109
class ArcTesselation < Propane::App
1110
attr_reader :cols, :coloured
1211

contributed/fire.rb

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# jruby fire.rb
1414
class Fire < Propane::App
1515
load_library :palette
16-
16+
1717
def settings
1818
size 320, 240
1919
end
20-
20+
2121
def setup
2222
sketch_title 'Fire'
2323
frame_rate 30
@@ -28,50 +28,47 @@ def setup
2828
@height = height / @scale
2929
@intensity = 2
3030
end
31-
31+
3232
def draw
3333
background 0
3434
update_fire
3535
end
36-
36+
3737
def update_fire
3838
random_line @height - 1
39-
(0..@height - 2).each do |y|
40-
(0..@width).each do |x|
41-
# Wrap
42-
left = x.zero? ? fire_data(@width - 1, y) : fire_data(x - 1, y)
43-
right = (x == @width - 1) ? fire_data(0, y) : fire_data(x + 1, y)
44-
below = fire_data(x, y + 1)
45-
# Get the average pixel value
46-
average = (left.to_i + right.to_i + (below.to_i * 2)) / 4
47-
# Fade the flames
48-
average -= @intensity if average > @intensity
49-
set_fire_data x, y, average
50-
fill @palette[average]
51-
stroke @palette[average]
52-
rect x * @scale, (y + 1) * @scale, @scale, @scale
53-
end
39+
grid(@height, @width) do |y, x|
40+
left = x.zero? ? fire_data(@width - 1, y) : fire_data(x - 1, y)
41+
right = (x == @width - 1) ? fire_data(0, y) : fire_data(x + 1, y)
42+
below = fire_data(x, y + 1)
43+
# Get the average pixel value
44+
average = (left.to_i + right.to_i + (below.to_i * 2)) / 4
45+
# Fade the flames
46+
average -= @intensity if average > @intensity
47+
set_fire_data x, y, average
48+
fill @palette[average]
49+
stroke @palette[average]
50+
rect x * @scale, (y + 1) * @scale, @scale, @scale
5451
end
5552
end
56-
53+
5754
def fire_data(x, y)
5855
@fire[offset(x, y)]
5956
end
60-
57+
6158
def set_fire_data(x, y, value)
6259
@fire[offset(x, y)] = value.to_i
6360
end
64-
61+
6562
def random_offset
6663
rand(0..@palette.size)
6764
end
68-
65+
6966
def random_line(y)
7067
(0...@width).each do |x|
7168
@fire[offset(x, y)] = random_offset
7269
end
7370
end
74-
71+
7572
def offset(x, y)
7673
(y * @width) + x
7774
end

contributed/library/curve/curve.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
module Olap
34
def self.overlaps(x, y, point_x, point_y)
45
Math.hypot(x - point_x, y - point_y) < RADIUS

contributed/terrain.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def eql?(key)
88
key.x == x
99
end
1010
end
11-
11+
# The propane sketch
1212
class Terrain < Propane::App
1313
WIDTH = 1400
1414
HEIGHT = 1100
@@ -43,7 +43,7 @@ def draw
4343
stroke 235, 69, 129
4444
translate width / 2, height / 2
4545
rotate_x PI / 3
46-
translate(-WIDTH / 2, -HEIGHT / 2)
46+
translate(-WIDTH / 2, -HEIGHT / 2)
4747
(0...rows).each do |y|
4848
begin_shape(TRIANGLE_STRIP)
4949
(0..columns).each do |x|

examples/forwardable_module_examples/pbox2d/distance_joint/distance_joint.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env jruby -v -W2
2-
require 'propane'
3-
require 'pbox2d'
2+
require 'propane' # A ruby-processing gem
3+
require 'pbox2d' # A ruby-processing gem
44
require 'forwardable'
55

66
# The Nature of Code

examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%w[box boundary spring dummy_spring].each do |lib|
2+
require_relative File.join('lib',"#{lib}")
3+
end

examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint.rb renamed to examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint_sketch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
require 'propane'
33
require 'pbox2d'
44

5-
65
# The Nature of Code
76
# Daniel Shiffman
87
# http://natureofcode.com
98

109
# Basic example of controlling an object with the mouse (by attaching a spring)
1110
class MouseJoint < Propane::App
11+
load_library :mouse_joint
1212
# A reference to our box2d world
1313
attr_reader :box2d, :boundaries, :box, :spring
1414
def settings

nature-of-code/xor/.mvn/extensions.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

nature-of-code/xor/landscape.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The Nature of Code
22
# Daniel Shiffman
3-
# https://natureofcode.com
3+
# http://natureofcode.com
44

55
# "Landscape" example
66
class Landscape
@@ -31,25 +31,27 @@ def calculate(nn)
3131
# Render landscape as grid of quads
3232
def render
3333
# Every cell is an individual quad
34-
# using the propane grid convenience function instead of a nested loop
35-
grid(z.size - 1, z[0].size - 1) do |x, y|
36-
# one quad at a time
37-
# each quad's color is determined by the height value at each vertex
38-
# (clean this part up)
39-
no_stroke
40-
push_matrix
41-
begin_shape(Processing::QUADS)
42-
translate(x * scl - w * 0.5, y * scl - h * 0.5, 0)
43-
fill(z[x][y] + 127, 220)
44-
vertex(0, 0, z[x][y])
45-
fill(z[x + 1][y] + 127, 220)
46-
vertex(scl, 0, z[x + 1][y])
47-
fill(z[x + 1][y + 1] + 127, 220)
48-
vertex(scl, scl, z[x + 1][y + 1])
49-
fill(z[x][y + 1] + 127, 220)
50-
vertex(0, scl, z[x][y + 1])
51-
end_shape
52-
pop_matrix
34+
# (could use quad_strip here, but produces funny results, investigate this)
35+
(0...z.size - 1).each do |x|
36+
(0...z[0].size - 1).each do |y|
37+
# one quad at a time
38+
# each quad's color is determined by the height value at each vertex
39+
# (clean this part up)
40+
no_stroke
41+
push_matrix
42+
begin_shape(QUADS)
43+
translate(x * scl - w * 0.5, y * scl - h * 0.5, 0)
44+
fill(z[x][y] + 127, 220)
45+
vertex(0, 0, z[x][y])
46+
fill(z[x + 1][y] + 127, 220)
47+
vertex(scl, 0, z[x + 1][y])
48+
fill(z[x + 1][y + 1] + 127, 220)
49+
vertex(scl, scl, z[x + 1][y + 1])
50+
fill(z[x][y + 1] + 127, 220)
51+
vertex(0, scl, z[x][y + 1])
52+
end_shape
53+
pop_matrix
54+
end
5355
end
5456
end
5557
end

0 commit comments

Comments
 (0)