|
| 1 | +%w[PGS_Morphology PGS_Transformation].each do |klass| |
| 2 | + java_import "micycle.pgs.#{klass}" |
| 3 | +end |
| 4 | + |
| 5 | +class Letter |
| 6 | + include Processing::Proxy |
| 7 | + attr_reader :hue, :l, :xn, :yn, :pos, :letter |
| 8 | + |
| 9 | + def initialize(c) |
| 10 | + @pos = Vec2D.new(rand(width), rand(height)) |
| 11 | + list = Java::ProcessingCore::PFont.list.to_a |
| 12 | + random_font = list.sample |
| 13 | + font = createFont(random_font, 96, true) |
| 14 | + @l = font.get_shape(c.to_java(:char)) |
| 15 | + @hue = rand |
| 16 | + @xn = rand(4096) |
| 17 | + @yn = rand(4096) |
| 18 | + end |
| 19 | + |
| 20 | + def update |
| 21 | + @xn += 0.005 |
| 22 | + @yn += 0.005 |
| 23 | + pos.x = map1d(noise(xn), -1.0..1.0, 0..width) |
| 24 | + pos.y = map1d(noise(yn), -1.0..1.0, 0..height) |
| 25 | + @letter = PGS_Transformation.translate_to(l, 0, 0) |
| 26 | + @letter = PGS_Transformation.shear(letter, |
| 27 | + map1d(@pos.x, 0..width, -TWO_PI..TWO_PI), |
| 28 | + map1d(@pos.y, 0..height, -TWO_PI..TWO_PI) |
| 29 | + ) |
| 30 | + @letter = PGS_Transformation.translate_to(letter, pos.x, pos.y) |
| 31 | + @letter = PGS_Morphology.simplify(letter, 1) # as some fonts have very dense vertices |
| 32 | + letter.setStroke(color(hue, 1, 1)) |
| 33 | + end |
| 34 | + |
| 35 | + def randomise |
| 36 | + @hue = rand |
| 37 | + list = Java::ProcessingCore::PFont.list.to_a |
| 38 | + random_font = list.sample |
| 39 | + font = createFont(random_font, 128, true) |
| 40 | + @l = font.getShape(rand(0..9).to_s.to_java(:char)) |
| 41 | + end |
| 42 | +end |
0 commit comments