Skip to content

Commit 0c2736d

Browse files
committed
no need for toxiclibs library
1 parent e3eadfb commit 0c2736d

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

external_library/gem/toxiclibs/library/branch/branch.rb renamed to contributed/library/branch/branch.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'forwardable'
22

3-
# Here we use our own Vec2D class, until we create a path as an array of TVec2D
4-
# toxis Vec2D. Required to use the ToxicLibsSupport lineStrip2D method.
5-
# further we can and should use power of ruby to make Branch enumerable and
6-
# Forwardable to define which enumerable methods we want to use
3+
# Here we use the JRubyArt Vec2D class, and not toxis Vec2D. We avoid using
4+
# ToxicLibsSupport, by using our own AppRender to translate Vec2D to vertices.
5+
# Further we use the power of ruby (metaprogramming) to make Branch enumerable
6+
# and use Forwardable to define which enumerable methods we want to use.
77
class Branch
88
include Enumerable
99
extend Forwardable
@@ -29,7 +29,7 @@ def initialize(app, pos, dir, speed)
2929
@children = []
3030
@xbound = Boundary.new(0, app.width)
3131
@ybound = Boundary.new(0, app.height)
32-
path << TVec2D.new(pos.x, pos.y)
32+
path << pos
3333
end
3434

3535
def run
@@ -39,12 +39,12 @@ def run
3939

4040
private
4141

42-
# Note use of both rotate! (changes original) rotate (returns a copy) of Vec2D
42+
# NB: use of both rotate! (changes original) rotate (returns a copy) of Vec2D
4343
def grow
4444
check_bounds(position + (dir * speed)) if path.length < MAX_LEN
4545
@position += (dir * speed)
4646
dir.rotate!(rand(-0.5..0.5) * THETA)
47-
path << TVec2D.new(position.x, position.y)
47+
path << position
4848
if (length < MAX_GEN) && (rand < BRANCH_CHANCE)
4949
branch_dir = dir.rotate(rand(-0.5..0.5) * BRANCH_THETA)
5050
self << Branch.new(app, position.copy, branch_dir, speed * 0.99)
@@ -53,7 +53,11 @@ def grow
5353
end
5454

5555
def display
56-
app.gfx.lineStrip2D(path)
56+
app.begin_shape
57+
app.stroke(255)
58+
app.no_fill
59+
path.each { |vec| vec.to_vertex(app.renderer) }
60+
app.end_shape
5761
each(&:display)
5862
end
5963

@@ -66,6 +70,6 @@ def check_bounds(pos)
6670
# we are looking for excluded values
6771
Boundary = Struct.new(:lower, :upper) do
6872
def exclude?(val)
69-
true unless (lower...upper).cover? val
73+
!(lower...upper).cover? val
7074
end
7175
end

external_library/gem/toxiclibs/mycelium.rb renamed to contributed/mycelium.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
require 'toxiclibs'
2-
31
# Simple recursive branching system inspired by mycelium growth
4-
#
5-
# The vanilla processing sketch was part of the SAC 2013 workshop project
6-
# (c) 2013 Karsten Schmidt
7-
# LGPLv3 licensed
2+
# After an original sketch by Karsten Schmidt
3+
# https://github.com/learn-postspectacular/sac-workshop-2013/blob/master/Mycelium/Mycelium.pde
84
# translated to JRubyArt by Martin Prout 2018
95

106
load_library :branch
117

12-
attr_reader :gfx, :root
8+
attr_reader :renderer, :root
139

1410
def setup
15-
@gfx = Gfx::ToxiclibsSupport.new(self)
11+
@renderer = AppRender.new(self)
1612
@root = Branch.new(
1713
self,
1814
Vec2D.new(0, height / 2),
@@ -23,8 +19,6 @@ def setup
2319

2420
def draw
2521
background(0)
26-
stroke(255)
27-
no_fill
2822
root.run
2923
end
3024

0 commit comments

Comments
 (0)