Skip to content

Commit a755e21

Browse files
committed
Update examples
1 parent 426b6fd commit a755e21

File tree

4 files changed

+73
-71
lines changed

4 files changed

+73
-71
lines changed

contributed/terrain.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Terrain < Propane::App
1313
WIDTH = 1400
1414
HEIGHT = 1100
1515
SCL = 30
16-
attr_reader :terrain, :rows, :columns, :mover
16+
attr_reader :terrain, :rows, :columns, :mover, :smth
1717

1818
def settings
1919
size 800, 800, P3D
@@ -25,6 +25,7 @@ def setup
2525
@rows = HEIGHT / SCL
2626
@terrain = {}
2727
@mover = 0
28+
@smth = false
2829
end
2930

3031
def draw
@@ -34,7 +35,11 @@ def draw
3435
(0..rows).each do |y|
3536
xoff = 0
3637
(0..columns).each do |x|
37-
terrain[Key.new(x, y)] = Vec3D.new(x * SCL, y * SCL, map1d(noise(xoff, yoff), 0..1.0, -65..65))
38+
if smth
39+
terrain[Key.new(x, y)] = Vec3D.new(x * SCL, y * SCL, map1d(SmoothNoise.tnoise(xoff, yoff), -1.0..1.0, -65..65))
40+
else
41+
terrain[Key.new(x, y)] = Vec3D.new(x * SCL, y * SCL, map1d(tnoise(xoff, yoff), -1.0..1.0, -65..65))
42+
end
3843
xoff += 0.2
3944
end
4045
yoff += 0.2
@@ -55,17 +60,9 @@ def draw
5560
end
5661

5762
def mouse_pressed
58-
mode = Propane::SIMPLEX
59-
noise_mode mode
60-
sketch_title "#{mode}"
63+
@smth = !smth
6164
end
62-
63-
def mouse_released
64-
mode = Propane::VALUE
65-
noise_mode(mode)
66-
sketch_title "#{mode}"
67-
end
68-
65+
6966
private
7067

7168
def renderer

examples/grid_method/noise_add.rb

100755100644
File mode changed.
Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env jruby
12
#######################
23
# --------- GEOMERATIVE EXAMPLES ---------------
34
#######################
@@ -24,71 +25,77 @@
2425
#
2526
# Adapted for JRubyArt by Martin Prout
2627
#######################
28+
require 'propane'
2729
require 'geomerative'
2830

29-
attr_reader :my_font, :stop, :xoff, :yoff, :x_inc, :y_inc
31+
class RubyMerge < Propane::App
3032

31-
TEXT = %w(RubyArt Processing).freeze
33+
attr_reader :my_font, :stop, :xoff, :yoff, :x_inc, :y_inc
3234

33-
def settings
34-
size(960, 640)
35-
end
35+
TEXT = %w(RubyArt Processing).freeze
3636

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
5140

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
7254
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
8288
end
83-
end_shape
84-
end
8589

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
9398
end
9499
end
100+
101+
RubyMerge.new

processing_app/basics/math/noise_wave.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def mouse_pressed
4747
@smth = !smth
4848
end
4949

50-
51-
5250
def settings
5351
size(640, 360)
5452
end

0 commit comments

Comments
 (0)