Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Oct 8, 2019
1 parent 287ae01 commit bfb504d
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 69 deletions.
1 change: 0 additions & 1 deletion contributed/arc_tesselation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 21 additions & 24 deletions contributed/fire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions contributed/library/curve/curve.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions contributed/terrain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def eql?(key)
key.x == x
end
end

# The propane sketch
class Terrain < Propane::App
WIDTH = 1400
HEIGHT = 1100
Expand Down Expand Up @@ -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|
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%w[box boundary spring dummy_spring].each do |lib|
require_relative File.join('lib',"#{lib}")
end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions nature-of-code/xor/.mvn/extensions.xml

This file was deleted.

42 changes: 22 additions & 20 deletions nature-of-code/xor/landscape.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The Nature of Code
# Daniel Shiffman
# https://natureofcode.com
# http://natureofcode.com

# "Landscape" example
class Landscape
Expand Down Expand Up @@ -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
22 changes: 22 additions & 0 deletions nature-of-code/xor/pom.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions nature-of-code/xor/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT MODIFIY - GENERATED CODE
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit bfb504d

Please sign in to comment.