Skip to content

Commit e85c46a

Browse files
committed
basics image
1 parent 8c92eb1 commit e85c46a

33 files changed

+444
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to k9 executable, and or opts as required
3+
4+
SAMPLES_DIR="./"
5+
6+
desc 'run demo'
7+
task :default => [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each{|sample| run_sample sample}
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob("*.rb").each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|jruby #{sample_name}", "r") do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end
31+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env jruby -w
2+
require 'propane'
3+
# Loads a "mask" for an image to specify the transparency
4+
# in different parts of the image. The two images are blended
5+
# together using the mask() method of PImage.
6+
class AlphaMask < Propane::App
7+
def setup
8+
sketch_title 'Alpha Mask'
9+
@image = load_image(data_path('test.jpg'))
10+
@image_mask = load_image(data_path('mask.jpg'))
11+
@image.mask @image_mask
12+
end
13+
14+
def draw
15+
background((mouse_x + mouse_y) / 1.5)
16+
image @image, width / 2, height / 2
17+
image @image, mouse_x - @image.width, mouse_y - @image.height
18+
end
19+
20+
def settings
21+
size 640, 360
22+
end
23+
end
24+
25+
AlphaMask.new
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env jruby -w
2+
require 'propane'
3+
# This example presents the fastest way to load a background image
4+
# into Processing. To load an image as the background, it must be
5+
# the same width and height as the program.
6+
class BackgroundImage < Propane::App
7+
def setup
8+
sketch_title 'Background Image'
9+
frame_rate 30
10+
@a = 0
11+
# is 200 x 200 pixels.
12+
@background_image = load_image(data_path('milan_rubbish.jpg'))
13+
end
14+
15+
def draw
16+
background @background_image
17+
@a = (@a + 1) % (width + 32)
18+
stroke 266, 204, 0
19+
line 0, @a, width, @a-26
20+
line 0, @a-6, width, @a-32
21+
end
22+
23+
def settings
24+
size 200, 200
25+
end
26+
end
27+
28+
BackgroundImage.new
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env jruby -w
2+
require 'propane'
3+
# Extrusion.
4+
#
5+
# Move the cursor over the image to alter its position. Click and press
6+
# the mouse to zoom and set the density of the matrix by typing numbers 1-5.
7+
# This program displays a series of lines with their heights corresponding to
8+
# a color value read from an image.
9+
ColoredExtrusion < Propane::App
10+
def setup
11+
sketch_title 'Colored Extrusion'
12+
no_fill
13+
stroke 255
14+
@nmx = 0.0
15+
@nmy = 0.0
16+
@sval = 1.0
17+
@res = 5
18+
@img = load_image(data_path('ystone08.jpg'))
19+
@img_pixels = []
20+
(0...@img.height).each do |y|
21+
@img_pixels << []
22+
(0...@img.width).each do |x|
23+
@img_pixels.last << @img.get(y, x)
24+
end
25+
end
26+
end
27+
28+
def draw
29+
background 0
30+
@nmx += (mouse_x - @nmx) / 20
31+
@nmy += (mouse_y - @nmy) / 20
32+
if mouse_pressed?
33+
@sval += 0.005
34+
else
35+
@sval -= 0.01
36+
end
37+
@sval = constrain @sval, 1.0, 2.5
38+
translate width / 2 + @nmx * @sval - 100, height / 2 + @nmy * @sval - 200, -50
39+
scale @sval
40+
rotate_z PI / 9 - @sval + 1
41+
rotate_x PI / @sval / 8 - 0.125
42+
rotate_y @sval / 8 - 0.125
43+
translate -width / 2, -height / 2
44+
(0...@img.height).step(@res) do |y|
45+
(0...@img.width).step(@res) do |x|
46+
rr = red @img_pixels[y][x]
47+
gg = green @img_pixels[y][x]
48+
bb = blue @img_pixels[y][x]
49+
tt = rr + gg + bb
50+
stroke rr, gg, gg
51+
line y, x, tt / 10 - 20, y, x, tt / 10
52+
end
53+
end
54+
end
55+
56+
def key_pressed
57+
k = key.to_i
58+
@res = k if (1..5).include? k
59+
end
60+
61+
def settings
62+
size 640, 360, P3D
63+
end
64+
end
65+
66+
ColoredExtrusion.new
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env jruby -w
2+
require 'propane'
3+
# The createImage() function provides a fresh buffer of pixels to play with.
4+
# This example creates an image gradient.
5+
class CreateImage < Propane::App
6+
7+
def setup
8+
sketch_title 'Create Image'
9+
@image = create_image 230, 230, ARGB
10+
@image.pixels.length.times do |i|
11+
@image.pixels[i] = color 0, 90, 102, (i % @image.width * 2) # red, green, blue, alpha
12+
end
13+
end
14+
15+
def draw
16+
background 204
17+
image @image, 90, 80
18+
image @image, mouse_x - @image.width, mouse_y - @image.width
19+
end
20+
21+
def settings
22+
size 640, 360
23+
end
24+
end
25+
26+
CreateImage.new
3.75 KB
Loading
3.73 KB
Loading
3.82 KB
Loading
3.66 KB
Loading
3.59 KB
Loading

0 commit comments

Comments
 (0)