Skip to content

Commit 8775fcf

Browse files
committed
fix examples
1 parent c7ad2ad commit 8775fcf

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

examples/grid_method/noise_add.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
4+
require 'propane'
5+
6+
# Based on code by Hamoid (Abe Pazos)
7+
8+
class NoiseAdd < Propane::App
9+
attr_reader :img
10+
11+
def settings
12+
size(1280, 640, P2D)
13+
end
14+
15+
def setup
16+
sketch_title 'Noise Add'
17+
blend_mode(ADD)
18+
background(0)
19+
puts('Image takes time to develop be patient...')
20+
end
21+
22+
def draw
23+
sc = 0.01 / (1 + frame_count / 30)
24+
img = create_image(width, height, RGB)
25+
img.load_pixels
26+
grid(width, height) do |x, y|
27+
nse = noise(x * sc, y * sc, frame_count * 0.02)
28+
img.pixels[x + y * width] = nse > 0.6 ? color(4, 2, 1) : color(0)
29+
end
30+
img.update_pixels
31+
image(img, 0, 0)
32+
end
33+
34+
def key_pressed
35+
return unless key == 's'
36+
37+
save_frame
38+
end
39+
end
40+
41+
NoiseAdd.new

processing_app/basics/image/request_parallel.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env jruby -w
2+
# frozen_string_literal: true
3+
24
require 'propane'
35
require 'parallel'
46
# Request Image
@@ -18,10 +20,9 @@ class RequestImage < Propane::App
1820
def setup
1921
sketch_title 'Request Image'
2022
# Load images asynchronously, kind of pointless with this few small images
21-
@imgs = Parallel.map(0...10) do |i|
22-
request_image(
23-
data_path(format('PT_anim%s.gif', i.to_s.rjust(4, '0'))
24-
)
23+
@imgs = (0...12).map do |i|
24+
load_image(
25+
data_path(format('PT_anim%<just>s.gif', just: i.to_s.rjust(4, '0')))
2526
)
2627
end
2728
end
@@ -30,15 +31,15 @@ def draw
3031
background 0
3132
# put pre-load animation here?
3233
# When all images are loaded draw them to the screen
33-
# return unless all_loaded?
34+
return unless all_loaded?
3435
imgs.each_with_index do |img, i|
3536
image(img, width / imgs.length * i, 0, width / imgs.length, height)
3637
end
3738
end
3839

3940
# Return true when all images are loaded
4041
def all_loaded?
41-
imgs.length == 10
42+
imgs.length == 12
4243
end
4344

4445
def settings

processing_app/basics/image/transparency.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env jruby -w
2+
# frozen_string_literal: true
3+
24
require 'propane'
35

4-
Move the pointer left and right across the image to change
6+
# Move(the(pointer(left))) && right(across(the(image(to(change)))))
57
# its position. This program overlays one image over another
68
# by modifying the alpha value of the image with the tint() function.
79
class Transparency < Propane::App
8-
910
def setup
1011
sketch_title 'Transparency'
1112
@a = load_image(data_path('construct.jpg'))
@@ -15,7 +16,7 @@ def setup
1516

1617
def draw
1718
image @a, 0, 0
18-
offset_target = map1d(mouse_x,(0..width), (-@b.width / 2 - width / 2..0))
19+
offset_target = map1d(mouse_x, (0..width), (-@b.width / 2 - width / 2..0))
1920
@offset += (offset_target - @offset) * 0.05
2021
tint 255, 153
2122
image @b, @offset, 20
@@ -26,4 +27,4 @@ def settings
2627
end
2728
end
2829

29-
Transparency
30+
Transparency.new

0 commit comments

Comments
 (0)