From bfb504da6ad5136b860d6feb9f9bd2c109e58652 Mon Sep 17 00:00:00 2001 From: monkstone Date: Tue, 8 Oct 2019 15:22:46 +0100 Subject: [PATCH] tidy up --- contributed/arc_tesselation.rb | 1 - contributed/fire.rb | 45 +++++++++---------- contributed/library/curve/curve.rb | 1 + contributed/terrain.rb | 4 +- .../pbox2d/distance_joint/distance_joint.rb | 4 +- .../pbox2d/mouse_joint/library/mouse_joint.rb | 4 -- .../library/mouse_joint/mouse_joint.rb | 3 ++ .../{mouse_joint.rb => mouse_joint_sketch.rb} | 2 +- nature-of-code/xor/.mvn/extensions.xml | 8 ---- nature-of-code/xor/landscape.rb | 42 ++++++++--------- nature-of-code/xor/pom.rb | 22 +++++++++ nature-of-code/xor/pom.xml | 7 --- 12 files changed, 74 insertions(+), 69 deletions(-) delete mode 100644 examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint.rb create mode 100644 examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint/mouse_joint.rb rename examples/forwardable_module_examples/pbox2d/mouse_joint/{mouse_joint.rb => mouse_joint_sketch.rb} (98%) delete mode 100644 nature-of-code/xor/.mvn/extensions.xml create mode 100644 nature-of-code/xor/pom.rb diff --git a/contributed/arc_tesselation.rb b/contributed/arc_tesselation.rb index 2201749..92c1a18 100644 --- a/contributed/arc_tesselation.rb +++ b/contributed/arc_tesselation.rb @@ -6,7 +6,6 @@ # press mouse to generate new pattern # use `c` key to toggle colored / greyscale # use 's' to save - class ArcTesselation < Propane::App attr_reader :cols, :coloured diff --git a/contributed/fire.rb b/contributed/fire.rb index 0098818..0d27bde 100644 --- a/contributed/fire.rb +++ b/contributed/fire.rb @@ -13,11 +13,11 @@ # jruby fire.rb class Fire < Propane::App load_library :palette - + def settings size 320, 240 end - + def setup sketch_title 'Fire' frame_rate 30 @@ -28,50 +28,47 @@ def setup @height = height / @scale @intensity = 2 end - + def draw background 0 update_fire end - + def update_fire random_line @height - 1 - (0..@height - 2).each do |y| - (0..@width).each do |x| - # Wrap - left = x.zero? ? fire_data(@width - 1, y) : fire_data(x - 1, y) - right = (x == @width - 1) ? fire_data(0, y) : fire_data(x + 1, y) - below = fire_data(x, y + 1) - # Get the average pixel value - average = (left.to_i + right.to_i + (below.to_i * 2)) / 4 - # Fade the flames - average -= @intensity if average > @intensity - set_fire_data x, y, average - fill @palette[average] - stroke @palette[average] - rect x * @scale, (y + 1) * @scale, @scale, @scale - end + grid(@height, @width) do |y, x| + left = x.zero? ? fire_data(@width - 1, y) : fire_data(x - 1, y) + right = (x == @width - 1) ? fire_data(0, y) : fire_data(x + 1, y) + below = fire_data(x, y + 1) + # Get the average pixel value + average = (left.to_i + right.to_i + (below.to_i * 2)) / 4 + # Fade the flames + average -= @intensity if average > @intensity + set_fire_data x, y, average + fill @palette[average] + stroke @palette[average] + rect x * @scale, (y + 1) * @scale, @scale, @scale end end - + def fire_data(x, y) @fire[offset(x, y)] end - + def set_fire_data(x, y, value) @fire[offset(x, y)] = value.to_i end - + def random_offset rand(0..@palette.size) end - + def random_line(y) (0...@width).each do |x| @fire[offset(x, y)] = random_offset end end - + def offset(x, y) (y * @width) + x end diff --git a/contributed/library/curve/curve.rb b/contributed/library/curve/curve.rb index 8f234b9..fc9c677 100644 --- a/contributed/library/curve/curve.rb +++ b/contributed/library/curve/curve.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Olap def self.overlaps(x, y, point_x, point_y) Math.hypot(x - point_x, y - point_y) < RADIUS diff --git a/contributed/terrain.rb b/contributed/terrain.rb index cdc1ce0..b33c626 100644 --- a/contributed/terrain.rb +++ b/contributed/terrain.rb @@ -8,7 +8,7 @@ def eql?(key) key.x == x end end - +# The propane sketch class Terrain < Propane::App WIDTH = 1400 HEIGHT = 1100 @@ -43,7 +43,7 @@ def draw stroke 235, 69, 129 translate width / 2, height / 2 rotate_x PI / 3 - translate(-WIDTH / 2, -HEIGHT / 2) + translate(-WIDTH / 2, -HEIGHT / 2) (0...rows).each do |y| begin_shape(TRIANGLE_STRIP) (0..columns).each do |x| diff --git a/examples/forwardable_module_examples/pbox2d/distance_joint/distance_joint.rb b/examples/forwardable_module_examples/pbox2d/distance_joint/distance_joint.rb index 85e3849..1000ec0 100644 --- a/examples/forwardable_module_examples/pbox2d/distance_joint/distance_joint.rb +++ b/examples/forwardable_module_examples/pbox2d/distance_joint/distance_joint.rb @@ -1,6 +1,6 @@ #!/usr/bin/env jruby -v -W2 -require 'propane' -require 'pbox2d' +require 'propane' # A ruby-processing gem +require 'pbox2d' # A ruby-processing gem require 'forwardable' # The Nature of Code diff --git a/examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint.rb b/examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint.rb deleted file mode 100644 index 7e6b53c..0000000 --- a/examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint.rb +++ /dev/null @@ -1,4 +0,0 @@ -require_relative 'lib/box' -require_relative 'lib/boundary' -require_relative 'lib/spring' -require_relative 'lib/dummy_spring' diff --git a/examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint/mouse_joint.rb b/examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint/mouse_joint.rb new file mode 100644 index 0000000..f8b4b1f --- /dev/null +++ b/examples/forwardable_module_examples/pbox2d/mouse_joint/library/mouse_joint/mouse_joint.rb @@ -0,0 +1,3 @@ +%w[box boundary spring dummy_spring].each do |lib| + require_relative File.join('lib',"#{lib}") +end diff --git a/examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint.rb b/examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint_sketch.rb similarity index 98% rename from examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint.rb rename to examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint_sketch.rb index 7b6de89..d40abd5 100644 --- a/examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint.rb +++ b/examples/forwardable_module_examples/pbox2d/mouse_joint/mouse_joint_sketch.rb @@ -2,13 +2,13 @@ require 'propane' require 'pbox2d' - # The Nature of Code # Daniel Shiffman # http://natureofcode.com # Basic example of controlling an object with the mouse (by attaching a spring) class MouseJoint < Propane::App + load_library :mouse_joint # A reference to our box2d world attr_reader :box2d, :boundaries, :box, :spring def settings diff --git a/nature-of-code/xor/.mvn/extensions.xml b/nature-of-code/xor/.mvn/extensions.xml deleted file mode 100644 index 9f3a51a..0000000 --- a/nature-of-code/xor/.mvn/extensions.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - io.takari.polyglot - polyglot-ruby - 0.4.3 - - diff --git a/nature-of-code/xor/landscape.rb b/nature-of-code/xor/landscape.rb index 3e4856a..a12e92a 100644 --- a/nature-of-code/xor/landscape.rb +++ b/nature-of-code/xor/landscape.rb @@ -1,6 +1,6 @@ # The Nature of Code # Daniel Shiffman -# https://natureofcode.com +# http://natureofcode.com # "Landscape" example class Landscape @@ -31,25 +31,27 @@ def calculate(nn) # Render landscape as grid of quads def render # Every cell is an individual quad - # using the propane grid convenience function instead of a nested loop - grid(z.size - 1, z[0].size - 1) do |x, y| - # one quad at a time - # each quad's color is determined by the height value at each vertex - # (clean this part up) - no_stroke - push_matrix - begin_shape(Processing::QUADS) - translate(x * scl - w * 0.5, y * scl - h * 0.5, 0) - fill(z[x][y] + 127, 220) - vertex(0, 0, z[x][y]) - fill(z[x + 1][y] + 127, 220) - vertex(scl, 0, z[x + 1][y]) - fill(z[x + 1][y + 1] + 127, 220) - vertex(scl, scl, z[x + 1][y + 1]) - fill(z[x][y + 1] + 127, 220) - vertex(0, scl, z[x][y + 1]) - end_shape - pop_matrix + # (could use quad_strip here, but produces funny results, investigate this) + (0...z.size - 1).each do |x| + (0...z[0].size - 1).each do |y| + # one quad at a time + # each quad's color is determined by the height value at each vertex + # (clean this part up) + no_stroke + push_matrix + begin_shape(QUADS) + translate(x * scl - w * 0.5, y * scl - h * 0.5, 0) + fill(z[x][y] + 127, 220) + vertex(0, 0, z[x][y]) + fill(z[x + 1][y] + 127, 220) + vertex(scl, 0, z[x + 1][y]) + fill(z[x + 1][y + 1] + 127, 220) + vertex(scl, scl, z[x + 1][y + 1]) + fill(z[x][y + 1] + 127, 220) + vertex(0, scl, z[x][y + 1]) + end_shape + pop_matrix + end end end end diff --git a/nature-of-code/xor/pom.rb b/nature-of-code/xor/pom.rb new file mode 100644 index 0000000..2e1bfe7 --- /dev/null +++ b/nature-of-code/xor/pom.rb @@ -0,0 +1,22 @@ +project 'xor' do + + model_version '4.0.0' + id 'nn:xor:1.0-SNAPSHOT' + packaging 'jar' + + description 'Neural Net Library for xor' + + developer 'shiffman' do + name 'Dan Shiffman' + roles 'developer' + end + + properties( 'maven.compiler.release' => '11', + 'polyglot.dump.pom' => 'pom.xml' ) + + overrides do + plugin( :compiler, '3.8.1', + 'encoding' => 'UTF-8' ) + end + +end diff --git a/nature-of-code/xor/pom.xml b/nature-of-code/xor/pom.xml index 55dd648..340848b 100644 --- a/nature-of-code/xor/pom.xml +++ b/nature-of-code/xor/pom.xml @@ -1,11 +1,4 @@ - 4.0.0