|
| 1 | +# Louis Christodoulou (louis -at- louisc.co.uk) |
| 2 | +# |
| 3 | +# Very quickly thrown together code whilst learning how the |
| 4 | +# geomerative library ticks. |
| 5 | +# |
| 6 | +# Here we take out previous scripts drawing and placing points along an arc and |
| 7 | +# complete our initial idea of placing text along the arc. |
| 8 | +# |
| 9 | +# Full Writeup on the Blog here: http://louisc.co.uk/?p=2686 |
| 10 | +require 'geomerative' |
| 11 | + |
| 12 | +MESSAGE = 'hello bendy world >>>'.freeze |
| 13 | +SCALE = 3 |
| 14 | +attr_reader :font, :points |
| 15 | + |
| 16 | +def settings |
| 17 | + size(800, 450) |
| 18 | +end |
| 19 | + |
| 20 | +def setup |
| 21 | + # Geomerative |
| 22 | + sketch_title 'Geomerative Text On A Path' |
| 23 | + # From the examples we must always initialise the library using this command |
| 24 | + RG.init(self) |
| 25 | + @points = [] |
| 26 | + background(255) |
| 27 | + # We want a dymo labeller style look, replace this font with your choice |
| 28 | + # see data folder for licence |
| 29 | + @font = RFont.new(data_path('Impact Label Reversed.ttf'), 72, RIGHT) |
| 30 | +end |
| 31 | + |
| 32 | +def draw |
| 33 | + # Blank Background each frame |
| 34 | + background(0) |
| 35 | + # Create a new RShape each frame |
| 36 | + wave = RShape.new |
| 37 | + # At the moment the wave object is empty, so lets add a curve: |
| 38 | + wave.add_move_to(0 * SCALE, 100 * SCALE) |
| 39 | + wave.add_bezier_to( |
| 40 | + 0 * SCALE, |
| 41 | + 100 * SCALE, |
| 42 | + 50 * SCALE, |
| 43 | + 25 * SCALE, |
| 44 | + 100 * SCALE, |
| 45 | + 100 * SCALE |
| 46 | + ) |
| 47 | + wave.add_bezier_to( |
| 48 | + 100 * SCALE, |
| 49 | + 100 * SCALE, |
| 50 | + 150 * SCALE, |
| 51 | + 175 * SCALE, |
| 52 | + 200 * SCALE, |
| 53 | + 100 * SCALE |
| 54 | + ) |
| 55 | + translate(100, -80) |
| 56 | + # draw our wave |
| 57 | + no_fill |
| 58 | + stroke(255, 0, 0) |
| 59 | + stroke_weight(60) |
| 60 | + stroke_cap(PROJECT) |
| 61 | + wave.draw |
| 62 | + stroke_cap(ROUND) |
| 63 | + # Collect some points along the curve |
| 64 | + RG.set_polygonizer(RCommand::UNIFORMLENGTH) |
| 65 | + RG.set_polygonizer_length(35) |
| 66 | + points = wave.get_points |
| 67 | + index = 0 # Letter index within the string message |
| 68 | + # loop through and place a letter at each point |
| 69 | + MESSAGE.each_char do |letter| |
| 70 | + center = RCommand.new(points[index], points[index + 1]).get_center |
| 71 | + fill(255) |
| 72 | + no_stroke |
| 73 | + push_matrix |
| 74 | + translate(center.x, center.y) |
| 75 | + rotate(get_angle(points[index], points[index + 1])) |
| 76 | + translate(5, 20) |
| 77 | + font.draw(letter) |
| 78 | + pop_matrix |
| 79 | + index += 1 |
| 80 | + end |
| 81 | +end |
| 82 | + |
| 83 | +# Simple function to calculate the angle between two points |
| 84 | +def get_angle(p1, p2) |
| 85 | + atan2(p2.y - p1.y, p2.x - p1.x) |
| 86 | +end |
0 commit comments