Skip to content

Commit d27dbb0

Browse files
committed
rubocop fixes
1 parent 4290632 commit d27dbb0

File tree

22 files changed

+107
-93
lines changed

22 files changed

+107
-93
lines changed

processing_app/topics/lsystems/Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Simple demo Rakefile to autorun samples in current directory
24
# adjust path to k9 executable, and or opts as required
35

@@ -8,7 +10,7 @@ task default: [:demo]
810

911
desc 'demo'
1012
task :demo do
11-
samples_list.shuffle.each{ |sample| run_sample sample }
13+
samples_list.shuffle.each { |sample| run_sample sample }
1214
end
1315

1416
def samples_list

processing_app/topics/lsystems/chequer.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
########################################################
24
# Chequer implemented using a grammar library
35
# Lindenmayer System in JRubyArt by Martin Prout
@@ -30,7 +32,7 @@ class Chequer
3032
def initialize(xpos, ypos)
3133
@xpos = xpos
3234
@ypos = ypos
33-
@axiom = 'F-F-F-F' # Axiom
35+
@axiom = 'F-F-F-F' # Axiom
3436
@grammar = Grammar.new(axiom, 'F' => 'FF-F-F-F-FF')
3537
@draw_length = 500
3638
stroke 0, 255, 0
@@ -67,6 +69,3 @@ def create_grammar(gen)
6769
@production = @grammar.generate gen
6870
end
6971
end
70-
71-
72-

processing_app/topics/lsystems/csplant.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
########################################################
24
# csplant.rb
35
# A 3D Plant implemented using a Context Sensitive
@@ -54,7 +56,7 @@ def render
5456
specular(255, 255, 255)
5557
shininess(1.0)
5658
repeat = 1
57-
production.each_char do |ch|
59+
production.scan(/./) do |ch|
5860
case ch
5961
when 'F'
6062
translate(0, len / -2, 0)
@@ -98,4 +100,3 @@ def create_grammar(gen)
98100
def settings
99101
size 800, 800, P3D
100102
end
101-

processing_app/topics/lsystems/cstest.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
###########################
24
# cstest.rb (use rp5 run ..
35
# test of cs_grammar library
@@ -17,15 +19,13 @@ def draw
1719
(0..7).each do |i|
1820
grammar = Grammar.new(
1921
'baaaaaa',
20-
'b<a' => 'b', # context sensitive rule replace a when preceded by b
22+
'b<a' => 'b', # context sensitive rule replace a when preceded by b
2123
'b' => 'a'
2224
)
2325
text grammar.generate(i), 30, i * 25
2426
end
2527
end
2628

27-
2829
def settings
2930
size 125, 250, P2D
3031
end
31-

processing_app/topics/lsystems/david_tour.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
# frozen_string_literal: true
2+
13
load_library :grammar
24

35
########################################################
46
# A David Tour fractal implemented using a
57
# Lindenmayer System in JRubyArt by Martin Prout
68
########################################################
7-
class DavidTour
9+
class DavidTour
810
attr_reader :draw_length, :xpos, :ypos, :theta, :axiom, :grammar
911
DELTA = Math::PI / 3 # 60 degrees
1012

1113
def initialize(xpos, ypos)
1214
@axiom = 'FX-XFX-XFX-XFX-XFX-XF' # Axiom
13-
@theta = 0
15+
@theta = 0
1416
@grammar = Grammar.new(
1517
axiom,
1618
'F' => '!F!-F-!F!', # Rules
@@ -29,7 +31,7 @@ def create_grammar(gen)
2931
def translate_rules(prod)
3032
swap = false
3133
[].tap do |points| # An array to store lines as a flat array of points
32-
prod.each do |ch|
34+
prod.scan(/./) do |ch|
3335
case ch
3436
when 'F'
3537
points << xpos << ypos << (@xpos += draw_length * Math.cos(theta)) << (@ypos -= draw_length * Math.sin(theta))
@@ -69,4 +71,3 @@ def draw
6971
def settings
7072
size(800, 900, P2D)
7173
end
72-

processing_app/topics/lsystems/doily.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
########################################################
24
# A Doily fractal implemented using a
35
# Lindenmayer System in JRubyArt by Martin Prout
@@ -27,7 +29,7 @@ def translate_rules(prod)
2729
coss = ->(orig, alpha, len) { orig + len * DegLut.cos(alpha) }
2830
sinn = ->(orig, alpha, len) { orig - len * DegLut.sin(alpha) }
2931
[].tap do |pts| # An array to store line vertices as Vec2D
30-
prod.each do |ch|
32+
prod.scan(/./) do |ch|
3133
case ch
3234
when 'F'
3335
pts << vec.copy
@@ -76,7 +78,7 @@ def render(points)
7678
end
7779

7880
def renderer
79-
@renderer ||= GfxRender.new(self.g)
81+
@renderer ||= GfxRender.new(g)
8082
end
8183

8284
def settings

processing_app/topics/lsystems/koch_fractal.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# frozen_string_literal: true
2+
13
load_library :koch
24

35
def setup
46
sketch_title 'Koch'
57
background(255)
6-
frame_rate(1) # Animate slowly
8+
frame_rate(1) # Animate slowly
79
@k = KochFractal.new(width, height)
810
end
911

@@ -21,4 +23,3 @@ def settings
2123
size(800, 250)
2224
smooth 8
2325
end
24-

processing_app/topics/lsystems/library/cs_grammar/cs_grammar.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
##################################
24
# The grammar class stores rules
35
# in two Hashes, one for cs rules,
@@ -39,7 +41,7 @@ def generate(repeat = 0) # repeat iteration grammar rules
3941
prod
4042
end
4143

42-
def new_production(prod) # single iteration grammar rules
44+
def new_production(prod) # single iteration grammar rules
4345
@idx = -1
4446
prod.gsub!(/./) do |ch|
4547
get_rule(prod, ch)

processing_app/topics/lsystems/library/grammar/grammar.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,17 @@ def initialize(axiom, rules)
1010
@rules = rules
1111
end
1212

13-
def expand(production, iterations, &block)
14-
production.each_char do |token|
15-
if rules.key?(token) && iterations.positive?
16-
expand(rules[token], iterations - 1, &block)
17-
else
18-
yield token
19-
end
20-
end
21-
end
22-
23-
def each(gen)
24-
expand(axiom, gen) { |token| yield token }
13+
def apply_rules(prod)
14+
prod.gsub(/./) { |token| rules.fetch(token, token) }
2515
end
2616

2717
def generate(gen)
28-
[].tap do |output|
29-
each(gen) { |token| output << token }
18+
return axiom if gen.zero?
19+
20+
prod = axiom
21+
gen.times do
22+
prod = apply_rules(prod)
3023
end
24+
prod
3125
end
3226
end

processing_app/topics/lsystems/library/koch/koch.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Kochline class
24
class KochLine
35
include Processing::Proxy
@@ -83,7 +85,7 @@ def render
8385
# for the structure. As we do this over and over again, each line gets broken
8486
# into 4 lines, which gets broken into 4 lines, and so on. . .
8587
def iterate(before)
86-
[].tap do |now| # Create empty list
88+
[].tap do |now| # Create empty list
8789
before.each do |l|
8890
# Calculate 5 koch vectors (done for us by the line object)
8991
a = l.start

0 commit comments

Comments
 (0)