Skip to content

Commit 877d592

Browse files
committed
rubocop fixes
1 parent 9888c93 commit 877d592

19 files changed

+169
-142
lines changed

processing_app/topics/lsystems/Rakefile

+2
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

35
desc 'run demo'

processing_app/topics/lsystems/chequer.rb

100644100755
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
24
require 'propane'
35

46
class ChequerSketch < Propane::App
@@ -35,7 +37,7 @@ class Chequer
3537
def initialize(xpos, ypos)
3638
@xpos = xpos
3739
@ypos = ypos
38-
@axiom = 'F-F-F-F' # Axiom
40+
@axiom = 'F-F-F-F' # Axiom
3941
@grammar = Grammar.new(axiom, 'F' => 'FF-F-F-F-FF')
4042
@draw_length = 500
4143
stroke 0, 255, 0
@@ -73,5 +75,4 @@ def create_grammar(gen)
7375
end
7476
end
7577

76-
7778
ChequerSketch.new

processing_app/topics/lsystems/csplant.rb

100644100755
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
24
require 'propane'
35
require 'arcball'
46

@@ -42,7 +44,7 @@ class CSPlant
4244

4345
IGNORE = '[]+-^&3'
4446
attr_reader :grammar, :axiom, :production, :premis, :rule,
45-
:theta, :scale_factor, :len, :phi, :len
47+
:theta, :scale_factor, :len, :phi, :len
4648

4749
def initialize(len)
4850
@axiom = 'F'

processing_app/topics/lsystems/cstest.rb

100644100755
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
24
require 'propane'
35

46
class CSTest < Propane::App
@@ -20,17 +22,17 @@ def setup
2022
def draw
2123
(0..7).each do |i|
2224
grammar = Grammar.new(
23-
'baaaaaa',
24-
'b<a' => 'b', # context sensitive rule replace a when preceded by b
25-
'b' => 'a'
25+
'baaaaaa',
26+
'b<a' => 'b', # context sensitive rule replace a when preceded by b
27+
'b' => 'a'
2628
)
2729
text grammar.generate(i), 30, i * 25
2830
end
2931
end
3032

3133
def settings
3234
size 125, 250
33-
end
35+
end
3436
end
3537

3638
CSTest.new

processing_app/topics/lsystems/david_tour.rb

100644100755
+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
24
require 'propane'
35

46
class DavidTourSketch < Propane::App
57
load_library :grammar
68

7-
8-
99
attr_reader :points
1010

1111
def setup
@@ -27,7 +27,6 @@ def draw
2727
def settings
2828
size(800, 900, P2D)
2929
end
30-
3130
end
3231

3332
########################################################
@@ -39,12 +38,12 @@ class DavidTour
3938
DELTA = Math::PI / 3 # 60 degrees
4039

4140
def initialize(xpos, ypos)
42-
@axiom = 'FX-XFX-XFX-XFX-XFX-XF' # Axiom
43-
@theta = 0
41+
@axiom = 'FX-XFX-XFX-XFX-XFX-XF' # Axiom
42+
@theta = 0
4443
@grammar = Grammar.new(
45-
axiom,
46-
'F' => '!F!-F-!F!', # Rules
47-
'X' => '!X'
44+
axiom,
45+
'F' => '!F!-F-!F!', # Rules
46+
'X' => '!X'
4847
)
4948
@draw_length = 15
5049
@xpos = xpos

processing_app/topics/lsystems/koch.rb

100644100755
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
24
require 'propane'
35

46
class Koch < Propane::App
@@ -7,7 +9,7 @@ class Koch < Propane::App
79
def setup
810
sketch_title 'Koch'
911
background(255)
10-
frame_rate(1) # Animate slowly
12+
frame_rate(1) # Animate slowly
1113
@k = KochFractal.new(width, height)
1214
end
1315

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

+3-1
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)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
############################
24
# Simple lsystem grammar
35
############################
@@ -22,96 +24,3 @@ def generate(gen)
2224
prod
2325
end
2426
end
25-
26-
Turtle = Struct.new(:x, :y, :angle, :color)
27-
28-
#############################
29-
# PenroseColored class
30-
#############################
31-
class PenroseColored
32-
include Propane::Proxy
33-
34-
attr_reader :axiom, :grammar, :start_length, :theta, :production,
35-
:draw_length, :repeats, :xpos, :ypos
36-
37-
DELTA = 36 # degrees
38-
RED = 70<<24|200<<16|0<<8|0 # using bit operations to set color int
39-
BLUE = 70<<24|0<<16|0<<8|200
40-
41-
def initialize(xpos, ypos) # Note use of abbreviated grammar
42-
@axiom = '[X]2+[X]2+[X]2+[X]2+[X]' # nos, used to indicate repeats
43-
@grammar = Grammar.new(
44-
axiom,
45-
'F' => '', # a so called deletion rule
46-
'W' => 'YBF2+ZRF4-XBF[-YBF4-WRF]2+',
47-
'X' => '+YBF2-ZRF[3-WRF2-XBF]+',
48-
'Y' => '-WRF2+XBF[3+YBF2+ZRF]-',
49-
'Z' => '2-YBF4+WRF[+ZRF4+XBF]2-XBF')
50-
@start_length = 1000.0
51-
@theta = 0
52-
@xpos = xpos
53-
@ypos = ypos
54-
@production = axiom.split('')
55-
@draw_length = start_length
56-
end
57-
58-
##############################################################################
59-
# Not strictly in the spirit of either processing in my render
60-
# function I have ignored the processing translate/rotate functions in favour
61-
# of the direct calculation of the new x and y positions, thus avoiding such
62-
# affine transformations.
63-
##############################################################################
64-
65-
def render
66-
repeats = 1
67-
ignored = %w(W X Y Z)
68-
repeated = %w(1 2 3 4)
69-
pen = Turtle.new(xpos, ypos, theta, :R) # simple Struct for pen, symbol :R = red
70-
stack = [] # simple array for stack
71-
production.scan(/./) do |element|
72-
case element
73-
when 'F'
74-
pen = draw_line(pen, draw_length)
75-
when '+'
76-
pen.angle += DELTA * repeats
77-
repeats = 1
78-
when '-'
79-
pen.angle -= DELTA * repeats
80-
repeats = 1
81-
when '['
82-
stack << pen.dup # push a copy current pen to stack
83-
when ']'
84-
pen = stack.pop # assign current pen to instance off the stack
85-
when 'R', 'B'
86-
pen.color = element.to_sym # set pen color as symbol
87-
when *ignored
88-
when *repeated
89-
repeats = element.to_i
90-
else puts format('Character %s not in grammar', element)
91-
end
92-
end
93-
end
94-
#####################################################
95-
# create grammar from axiom and # rules (adjust scale)
96-
#####################################################
97-
98-
def create_grammar(gen)
99-
@draw_length *= 0.5**gen
100-
@production = grammar.generate gen
101-
end
102-
103-
private
104-
105-
####################################################################
106-
# draws line using current pen position, color and length parameters
107-
# returns a pen corresponding to the new position
108-
###################################################################
109-
110-
def draw_line(pen, length)
111-
stroke(pen.color == :R ? RED : BLUE)
112-
new_xpos = pen.x - length * DegLut.cos(pen.angle)
113-
new_ypos = pen.y - length * DegLut.sin(pen.angle)
114-
line(pen.x, pen.y, new_xpos, new_ypos) # draw line
115-
Turtle.new(new_xpos, new_ypos, pen.angle, pen.color) # return pen @ new pos
116-
end
117-
end

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

+3-1
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 Propane::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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# frozen_string_literal: true
2+
3+
Pen = Struct.new(:x, :y, :angle, :color)
4+
5+
#############################
6+
# PenroseColored class
7+
#############################
8+
class PenroseColored
9+
include Propane::Proxy
10+
11+
attr_reader :axiom, :grammar, :start_length, :theta, :production,
12+
:draw_length, :repeats, :xpos, :ypos
13+
14+
DELTA = 36 # degrees
15+
RED = 70 << 24 | 200 << 16 | 0 << 8 | 0 # using bit operations to set color int
16+
BLUE = 70 << 24 | 0 << 16 | 0 << 8 | 200
17+
18+
def initialize(xpos, ypos) # Note use of abbreviated grammar
19+
@axiom = '[X]2+[X]2+[X]2+[X]2+[X]' # nos, used to indicate repeats
20+
@grammar = Grammar.new(
21+
axiom,
22+
'F' => '', # a so called deletion rule
23+
'W' => 'YBF2+ZRF4-XBF[-YBF4-WRF]2+',
24+
'X' => '+YBF2-ZRF[3-WRF2-XBF]+',
25+
'Y' => '-WRF2+XBF[3+YBF2+ZRF]-',
26+
'Z' => '2-YBF4+WRF[+ZRF4+XBF]2-XBF'
27+
)
28+
@start_length = 1000.0
29+
@theta = 0
30+
@xpos = xpos
31+
@ypos = ypos
32+
@production = axiom.split('')
33+
@draw_length = start_length
34+
end
35+
36+
##############################################################################
37+
# Not strictly in the spirit of either processing in my render
38+
# function I have ignored the processing translate/rotate functions in favour
39+
# of the direct calculation of the new x and y positions, thus avoiding such
40+
# affine transformations.
41+
##############################################################################
42+
43+
def render
44+
repeats = 1
45+
ignored = %w[W X Y Z]
46+
repeated = %w[1 2 3 4]
47+
pen = Pen.new(xpos, ypos, theta, :R) # simple Struct for pen, symbol :R = red
48+
stack = [] # simple array for stack
49+
production.scan(/./) do |element|
50+
case element
51+
when 'F'
52+
pen = draw_line(pen, draw_length)
53+
when '+'
54+
pen.angle += DELTA * repeats
55+
repeats = 1
56+
when '-'
57+
pen.angle -= DELTA * repeats
58+
repeats = 1
59+
when '['
60+
stack << pen.dup # push a copy current pen to stack
61+
when ']'
62+
pen = stack.pop # assign current pen to instance off the stack
63+
when 'R', 'B'
64+
pen.color = element.to_sym # set pen color as symbol
65+
when *ignored
66+
when *repeated
67+
repeats = element.to_i
68+
else puts format('Character %<ch>s not in grammar', ch: element)
69+
end
70+
end
71+
end
72+
#####################################################
73+
# create grammar from axiom and # rules (adjust scale)
74+
#####################################################
75+
76+
def create_grammar(gen)
77+
@draw_length *= 0.5**gen
78+
@production = grammar.generate gen
79+
end
80+
81+
private
82+
83+
####################################################################
84+
# draws line using current pen position, color and length parameters
85+
# returns a pen corresponding to the new position
86+
###################################################################
87+
88+
def draw_line(pen, length)
89+
stroke(pen.color == :R ? RED : BLUE)
90+
new_xpos = pen.x - length * DegLut.cos(pen.angle)
91+
new_ypos = pen.y - length * DegLut.sin(pen.angle)
92+
line(pen.x, pen.y, new_xpos, new_ypos) # draw line
93+
Pen.new(new_xpos, new_ypos, pen.angle, pen.color) # return pen @ new pos
94+
end
95+
end

processing_app/topics/lsystems/library/stochastic_grammar/stochastic_grammar.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
########################
24
# stochastic_grammar.rb
35
# unweighted rules accepted
@@ -22,6 +24,7 @@ def stochastic_rule(rules)
2224
chance = rand(0..total)
2325
rules.each do |item, weight|
2426
return item unless chance > weight
27+
2528
chance -= weight
2629
end
2730
end
@@ -39,7 +42,7 @@ def add_rule(pre, rule, weight = 1.0) # default weighting 1
3942
end
4043
end
4144

42-
def new_production(prod) # note the use of gsub!
45+
def new_production(prod) # note the use of gsub!
4346
prod.gsub!(/./) do |ch|
4447
rule?(ch) ? stochastic_rule(srules[ch]) : ch
4548
end

0 commit comments

Comments
 (0)