Skip to content

Commit 8061de3

Browse files
committed
first crack
1 parent 92b99a2 commit 8061de3

File tree

3 files changed

+102
-47
lines changed

3 files changed

+102
-47
lines changed

docs/_config.yml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
# Welcome to Jekyll!
2-
#
3-
# This config file is meant for settings that affect your whole blog, values
4-
# which you are expected to set up once and rarely edit after that. If you find
5-
# yourself editing this file very often, consider using Jekyll's data files
6-
# feature for the data you need to update frequently.
7-
#
8-
# For technical reasons, this file is *NOT* reloaded automatically when you use
9-
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.
10-
11-
# Site settings
12-
# These are used to personalize your new site. If you look in the HTML files,
13-
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
14-
# You can create any custom variable you would like, and they will be accessible
15-
# in the templates via {{ site.myvariable }}.
16-
title: Your awesome title
17-
1+
title: Vecmath gem for Visor etc.
2+
183
description: >- # this means to ignore newlines until "baseurl:"
19-
Write an awesome description for your new site here. You can edit this
20-
line in _config.yml. It will appear in your document head meta (for
21-
Google search results) and in your feed.xml site description.
4+
Her we describe how to use some cool JRubyArt features in Visor
225
baseurl: "" # the subpath of your site, e.g. /blog
236
url: "" # the base hostname & protocol for your site, e.g. http://example.com
24-
twitter_username: jekyllrb
25-
github_username: jekyll
7+
twitter_username: monkstoneT
8+
github_username: monkstone
269

2710
# Build settings
2811
markdown: kramdown

docs/_posts/2019-03-01-welcome-to-jekyll.markdown

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
layout: post
3+
title: "Welcome to Vecmath Gem for Visor"
4+
date: 2019-03-01 10:58:08 +0000
5+
categories: vecmath update
6+
---
7+
```ruby
8+
# ===== Default : Default
9+
GEM_HOME = '/home/tux/.gem/ruby/2.6.0'
10+
require 'vecmath'
11+
require 'forwardable'
12+
13+
# Here we use the JRubyArt Vec2D class, and AppRender class (for vec.to_vertex)
14+
# Further we use the power of ruby (metaprogramming) to make Branch enumerable
15+
# and use Forwardable to define which enumerable methods we want to use.
16+
visor_class :Branch do
17+
include Enumerable
18+
extend Forwardable
19+
def_delegators(:@children, :<<, :each, :length)
20+
# variance angle for growth direction per time step
21+
THETA = Math::PI / 6
22+
# max segments per branch
23+
MAX_LEN = 100
24+
# max recursion limit
25+
MAX_GEN = 3
26+
# branch chance per time step
27+
BRANCH_CHANCE = 0.05
28+
# branch angle variance
29+
BRANCH_THETA = Math::PI / 3
30+
attr_reader :position, :dir, :path, :children, :xbound, :speed, :ybound, :app
31+
32+
def initialize(pos, dir, speed)
33+
@renderer ||= AppRender.new(graphics)
34+
@position = pos
35+
@dir = dir
36+
@speed = speed
37+
@path = []
38+
@children = []
39+
@xbound = Boundary.new(0, width)
40+
@ybound = Boundary.new(0, height)
41+
path << pos
42+
end
43+
44+
def run
45+
grow
46+
display
47+
end
48+
49+
private
50+
51+
# NB: use of both rotate! (changes original) rotate (returns a copy) of Vec2D
52+
def grow
53+
check_bounds(position + (dir * speed)) if path.length < MAX_LEN
54+
@position += (dir * speed)
55+
dir.rotate!(rand(-0.5..0.5) * THETA)
56+
path << position
57+
if (length < MAX_GEN) && (rand < BRANCH_CHANCE)
58+
branch_dir = dir.rotate(rand(-0.5..0.5) * BRANCH_THETA)
59+
self << Branch.new(position.copy, branch_dir, speed * 0.99)
60+
end
61+
each(&:grow)
62+
end
63+
64+
def display
65+
begin_shape
66+
stroke(255)
67+
no_fill
68+
path.each { |vec| vec.to_vertex(@renderer) }
69+
end_shape
70+
each(&:display)
71+
end
72+
73+
def check_bounds(pos)
74+
dir.x *= -1 if xbound.exclude? pos.x
75+
dir.y *= -1 if ybound.exclude? pos.y
76+
end
77+
end
78+
79+
# we are looking for excluded values
80+
Boundary = Struct.new(:lower, :upper) do
81+
def exclude?(val)
82+
!(lower...upper).cover? val
83+
end
84+
end
85+
86+
@root = Branch.new(
87+
Vec2D.new(0, height / 2),
88+
Vec2D.new(1, 0),
89+
10.0
90+
)
91+
92+
def draw
93+
background(0)
94+
root.run
95+
end
96+
97+
```

0 commit comments

Comments
 (0)