|
4 | 4 | ].each do |klass|
|
5 | 5 | java_import "micycle.pgs.#{klass}"
|
6 | 6 | end
|
7 |
| -require_relative 'letter' |
| 7 | + |
| 8 | +class Letter |
| 9 | + include Processing::Proxy |
| 10 | + |
| 11 | + attr_reader :hue, :l, :xn, :yn, :pos, :letter, :serif |
| 12 | + |
| 13 | + def initialize(c) |
| 14 | + @pos = Vec2D.new(rand(width), rand(height)) |
| 15 | + list = Java::ProcessingCore::PFont.list.to_a |
| 16 | + @serif = list.select { |fon| fon =~ /Serif/i } |
| 17 | + random_font = list.sample |
| 18 | + font = createFont(random_font, 96, true) |
| 19 | + @l = font.get_shape(c.to_java(:char)) |
| 20 | + @hue = rand |
| 21 | + @xn = rand(4096) |
| 22 | + @yn = rand(4096) |
| 23 | + end |
| 24 | + |
| 25 | + def update |
| 26 | + @xn += 0.005 |
| 27 | + @yn += 0.005 |
| 28 | + pos.x = map1d(noise(xn), -1.0..1.0, 0..width) |
| 29 | + pos.y = map1d(noise(yn), -1.0..1.0, 0..height) |
| 30 | + @letter = PGS_Transformation.translate_to(l, 0, 0) |
| 31 | + @letter = PGS_Transformation.shear(letter, |
| 32 | + map1d(@pos.x, 0..width, -TWO_PI..TWO_PI), |
| 33 | + map1d(@pos.y, 0..height, -TWO_PI..TWO_PI) |
| 34 | + ) |
| 35 | + @letter = PGS_Transformation.translate_to(letter, pos.x, pos.y) |
| 36 | + @letter = PGS_Morphology.simplify(letter, 1) # as some fonts have very dense vertices |
| 37 | + letter.setStroke(color(hue, 1, 1)) |
| 38 | + end |
| 39 | + |
| 40 | + def randomise |
| 41 | + @hue = rand |
| 42 | + list = Java::ProcessingCore::PFont.list.to_a |
| 43 | + random_font = serif.sample |
| 44 | + font = createFont(random_font, 128, true) |
| 45 | + @l = font.getShape(rand(0..9).to_s.to_java(:char)) |
| 46 | + end |
| 47 | +end |
| 48 | + |
8 | 49 |
|
9 | 50 | attr_reader :l1, :l2
|
10 | 51 |
|
@@ -34,7 +75,7 @@ def draw
|
34 | 75 | PGS_Conversion.setAllFillColor(intersect, color(0, 0.5))
|
35 | 76 | shape(intersect)
|
36 | 77 | rescue Java::JavaLang::Exception => e
|
37 |
| - puts e.to_s |
| 78 | + # puts e.to_s |
38 | 79 | end
|
39 | 80 | if (frame_count % 120).zero?
|
40 | 81 | l1.randomise
|
|
0 commit comments