|
| 1 | +#!/usr/bin/env jruby |
1 | 2 | ####################### |
2 | 3 | # --------- GEOMERATIVE EXAMPLES --------------- |
3 | 4 | ####################### |
|
24 | 25 | # |
25 | 26 | # Adapted for JRubyArt by Martin Prout |
26 | 27 | ####################### |
| 28 | +require 'propane' |
27 | 29 | require 'geomerative' |
28 | 30 |
|
29 | | -attr_reader :my_font, :stop, :xoff, :yoff, :x_inc, :y_inc |
| 31 | +class RubyMerge < Propane::App |
30 | 32 |
|
31 | | -TEXT = %w(RubyArt Processing).freeze |
| 33 | + attr_reader :my_font, :stop, :xoff, :yoff, :x_inc, :y_inc |
32 | 34 |
|
33 | | -def settings |
34 | | - size(960, 640) |
35 | | -end |
| 35 | + TEXT = %w(RubyArt Processing).freeze |
36 | 36 |
|
37 | | -def setup |
38 | | - sketch_title TEXT.join ' ' |
39 | | - RG.init(self) |
40 | | - @my_font = RFont.new(data_path('FreeSans.ttf'), 200, CENTER) |
41 | | - @stop = false |
42 | | - no_fill |
43 | | - stroke(255) |
44 | | - stroke_weight(0.5) |
45 | | - rect_mode(CENTER) |
46 | | - @xoff = 0.0 |
47 | | - @yoff = 0.0 |
48 | | - @x_inc = 0.01 |
49 | | - @y_inc = 0.015 |
50 | | -end |
| 37 | + def settings |
| 38 | + size(960, 640) |
| 39 | + end |
51 | 40 |
|
52 | | -def draw |
53 | | - background(0, 50) |
54 | | - displace_x = noise(xoff) * width |
55 | | - displace_y = noise(yoff) * height |
56 | | - @xoff += x_inc |
57 | | - @yoff += y_inc |
58 | | - translate(width / 2, height / 1.7) |
59 | | - frequency = map1d(displace_x, (300..500), (3..200)) |
60 | | - RCommand.set_segment_length(frequency) |
61 | | - my_points = my_font.to_group(TEXT[0]).get_points |
62 | | - begin_shape |
63 | | - my_points.each do |point| |
64 | | - vertex(point.x, point.y) |
65 | | - rotation = map1d(displace_y, (0..height), (0..TWO_PI)) |
66 | | - push_matrix |
67 | | - translate(point.x, point.y) |
68 | | - rotate(rotation) |
69 | | - size = frequency / 6 |
70 | | - rect(0, 0, size, size) |
71 | | - pop_matrix |
| 41 | + def setup |
| 42 | + sketch_title TEXT.join ' ' |
| 43 | + RG.init(self) |
| 44 | + @my_font = RFont.new(data_path('FreeSans.ttf'), 200, CENTER) |
| 45 | + @stop = false |
| 46 | + no_fill |
| 47 | + stroke(255) |
| 48 | + stroke_weight(0.5) |
| 49 | + rect_mode(CENTER) |
| 50 | + @xoff = 0.0 |
| 51 | + @yoff = 0.0 |
| 52 | + @x_inc = 0.01 |
| 53 | + @y_inc = 0.015 |
72 | 54 | end |
73 | | - end_shape |
74 | | - frequency2 = map1d(displace_x, (300..500), (200..3)) |
75 | | - RCommand.set_segment_length(frequency2) |
76 | | - my_points = my_font.to_group(TEXT[1]).get_points |
77 | | - begin_shape |
78 | | - my_points.each do |point| |
79 | | - vertex(point.x, point.y) |
80 | | - size = frequency2 / 7 |
81 | | - ellipse(point.x, point.y, size, size) |
| 55 | + |
| 56 | + def draw |
| 57 | + background(0, 50) |
| 58 | + displace_x = (noise(xoff) + 1) * width / 2 |
| 59 | + displace_y = (noise(yoff) + 1) * height / 2 |
| 60 | + @xoff += x_inc |
| 61 | + @yoff += y_inc |
| 62 | + translate(width / 2, height / 1.7) |
| 63 | + frequency = map1d(displace_x, (300..500), (3..200)) |
| 64 | + RCommand.set_segment_length(frequency) |
| 65 | + my_points = my_font.to_group(TEXT[0]).get_points |
| 66 | + begin_shape |
| 67 | + my_points.each do |point| |
| 68 | + vertex(point.x, point.y) |
| 69 | + rotation = map1d(displace_y, (0..height), (0..TWO_PI)) |
| 70 | + push_matrix |
| 71 | + translate(point.x, point.y) |
| 72 | + rotate(rotation) |
| 73 | + size = frequency / 6 |
| 74 | + rect(0, 0, size, size) |
| 75 | + pop_matrix |
| 76 | + end |
| 77 | + end_shape |
| 78 | + frequency2 = map1d(displace_x, (300..500), (200..3)) |
| 79 | + RCommand.set_segment_length(frequency2) |
| 80 | + my_points = my_font.to_group(TEXT[1]).get_points |
| 81 | + begin_shape |
| 82 | + my_points.each do |point| |
| 83 | + vertex(point.x, point.y) |
| 84 | + size = frequency2 / 7 |
| 85 | + ellipse(point.x, point.y, size, size) |
| 86 | + end |
| 87 | + end_shape |
82 | 88 | end |
83 | | - end_shape |
84 | | -end |
85 | 89 |
|
86 | | -def key_pressed |
87 | | - case key |
88 | | - when 'f', 'F' |
89 | | - @stop = !stop |
90 | | - stop ? no_loop : loop |
91 | | - when 's', 'S' |
92 | | - save_frame(data_path('000_###.png')) |
| 90 | + def key_pressed |
| 91 | + case key |
| 92 | + when 'f', 'F' |
| 93 | + @stop = !stop |
| 94 | + stop ? no_loop : loop |
| 95 | + when 's', 'S' |
| 96 | + save_frame(data_path('000_###.png')) |
| 97 | + end |
93 | 98 | end |
94 | 99 | end |
| 100 | + |
| 101 | +RubyMerge.new |
0 commit comments