Skip to content

Commit c7d75ab

Browse files
committed
tidy up a bit
1 parent 6e50cc6 commit c7d75ab

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

nature-of-code/animation/Exercise_10_05_LayeredNetworkAnimation.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env jruby
2-
require 'propane'
32

3+
# The Nature of Code
4+
# Daniel Shiffman
5+
# http://natureofcode.com
6+
require 'propane'
7+
# An animated drawing of a Neural Network
48
class LayeredNetwork < Propane::App
5-
# The Nature of Code
6-
# Daniel Shiffman
7-
# http://natureofcode.com
89

9-
# An animated drawing of a Neural Network
1010
load_libraries :neural_network
1111

1212
attr_reader :network, :output
1313

1414
def setup
15-
sketch_title 'Exercise 10 05 Layered Network Animation'
15+
sketch_title 'Layered Network Animation'
1616
# Create the Network object
1717
@network = Network.new(width / 2, height / 2)
1818
layers = 3
@@ -42,7 +42,7 @@ def draw
4242
network.update
4343
network.display
4444
# Every 30 frames feed in an input
45-
network.feedforward(rand, rand) if (frame_count % 30 == 0)
45+
network.feedforward(rand, rand) if (frame_count % 30).zero?
4646
end
4747

4848
def settings

nature-of-code/animation/library/neural_network/lib/connection.rb

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# http://natureofcode.com
44

55
# An animated drawing of a Neural Network
6-
76
class Connection
87
include Propane::Proxy
98
# Connection is from A to B

nature-of-code/animation/library/neural_network/lib/network.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# The Nature of Code
22
# Daniel Shiffman
33
# http:#natureofcode.com
4-
# An animated drawing of a Neural Network
5-
4+
# The Network has a list of neurons
65
class Network
76
include Propane::Proxy
8-
# The Network has a list of neurons
97
attr_reader :neurons, :connections, :location
108

119
def initialize(x, y)
@@ -38,15 +36,15 @@ def feedforward(input1, input2)
3836

3937
# Update the animation
4038
def update
41-
connections.each { |c| c.update }
39+
connections.each(&:update)
4240
end
4341

4442
# Draw everything
4543
def display
4644
push_matrix
4745
translate(location.x, location.y)
48-
neurons.each { |n| n.display }
49-
connections.each { |c| c.display }
46+
neurons.each(&:display)
47+
connections.each(&:display)
5048
pop_matrix
5149
end
5250
end

nature-of-code/animation/library/neural_network/lib/neuron.rb

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# The Nature of Code
33
# http://natureofcode.com
44
# An animated drawing of a Neural Network
5-
65
class Neuron
76
include Propane::Proxy
87
# Neuron has a location

nature-of-code/animation/library/neural_network/lib/static_network.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The Nature of Code
22
# Daniel Shiffman
33
# http://natureofcode.com
4-
4+
# The static network
55
class StaticNetwork
66
include Propane::Proxy
77
attr_reader :neurons, :location
@@ -32,7 +32,7 @@ def initialize(layers, inputs, _outputs)
3232
def display
3333
push_matrix
3434
translate(location.x, location.y)
35-
neurons.each { |n| n.display }
35+
neurons.each(&:display)
3636
pop_matrix
3737
end
3838
end

0 commit comments

Comments
 (0)