Skip to content

Commit 889d1e8

Browse files
committed
more samples
1 parent e85c46a commit 889d1e8

20 files changed

+3408
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
require 'arcball'
4+
# Move the mouse left and right to change the field of view (fov).
5+
# Click to modify the aspect ratio. The perspektiv method
6+
# sets a perspective projection applying foreshortening, making
7+
# distant objects appear smaller than closer ones. The parameters
8+
# define a viewing volume with the shape of truncated pyramid.
9+
# while farther objects appear smaller. This projection simulates
10+
# the perspective of the world more accurately than orthographic projection.
11+
# The version of perspektiv without parameters sets the default
12+
# perspective and the version with up to four parameters allows the programmer
13+
# to set the environment more precisely.
14+
class ArcballPerspektiv < Propane::App
15+
attr_reader :aspect
16+
17+
def setup
18+
sketch_title 'Perspektiv Example'
19+
Processing::ArcBall.constrain self
20+
@aspect = width.to_f / height
21+
no_stroke
22+
end
23+
24+
def draw
25+
lights
26+
background 204
27+
camera_y = height / 2.0
28+
fov = mouse_x / width.to_f * PI / 2.0
29+
camera_z = camera_y / Math.tan(fov / 2.0)
30+
perspektiv(
31+
fov: fov,
32+
aspect_ratio: aspect,
33+
near_z: camera_z / 10.0,
34+
far_z: camera_z * 10.0
35+
)
36+
rotate_x -PI / 6
37+
box 45
38+
translate 0, 0, -50
39+
box 30
40+
end
41+
42+
def settings
43+
size 640, 360, P3D
44+
end
45+
46+
def key_pressed
47+
case key
48+
when ' '
49+
@aspect = width * 0.5 / height
50+
when 'n', 'N'
51+
@aspect = width.to_f / height
52+
end
53+
end
54+
end
55+
56+
ArcballPerspektiv.new
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
# Move Eye.
4+
# by Simon Greenwold.
5+
#
6+
# The camera lifts up (controlled by mouseY) while looking at the same point.
7+
class KMoveEye < Propane::App
8+
def setup
9+
sketch_title 'KMove Eye Kamera'
10+
fill 204
11+
end
12+
13+
def draw
14+
lights
15+
background 0
16+
kamera eye: Vec3D.new(30, mouse_y, 220), center: Vec3D.new
17+
no_stroke
18+
box 90
19+
stroke 255
20+
line( -100, 0, 0, 100, 0, 0)
21+
line( 0, -100, 0, 0, 100, 0)
22+
line( 0, 0, -100, 0, 0, 100)
23+
end
24+
25+
def settings
26+
size 640, 360, P3D
27+
end
28+
end
29+
30+
KMoveEye.new
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
# Move Eye.
4+
# by Simon Greenwold.
5+
#
6+
# The camera lifts up (controlled by mouseY) while looking at the same point.
7+
class MoveEye < Propane::App
8+
def setup
9+
sketch_title 'Move Eye'
10+
fill 204
11+
end
12+
13+
def draw
14+
lights
15+
background 0
16+
camera 30, mouse_y, 220, 0, 0, 0, 0, 1, 0
17+
no_stroke
18+
box 90
19+
stroke 255
20+
line( -100, 0, 0, 100, 0, 0)
21+
line( 0, -100, 0, 0, 100, 0)
22+
line( 0, 0, -100, 0, 0, 100)
23+
end
24+
25+
def settings
26+
size 640, 360, P3D
27+
end
28+
end
29+
30+
MoveEye.new
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
# Move the mouse left and right to change the field of view (fov).
4+
# Click to modify the aspect ratio. The perspective method
5+
# sets a perspective projection applying foreshortening, making
6+
# distant objects appear smaller than closer ones. The parameters
7+
# define a viewing volume with the shape of truncated pyramid.
8+
# while farther objects appear smaller. This projection simulates
9+
# the perspective of the world more accurately than orthographic projection.
10+
# The version of perspective without parameters sets the default
11+
# perspective and the version with four parameters allows the programmer
12+
# to set the area precisely.
13+
class Perspective < Propane::App
14+
def setup
15+
sketch_title 'Perspective'
16+
no_stroke
17+
end
18+
19+
def draw
20+
lights
21+
background 204
22+
camera_y = height / 2.0
23+
fov = mouse_x / width.to_f * PI / 2.0
24+
camera_z = camera_y / Math.tan(fov / 2.0)
25+
aspect = width.to_f / height
26+
aspect /= 2.0 if mouse_pressed?
27+
perspective(fov, aspect, camera_z / 10.0, camera_z * 10.0)
28+
translate width / 2.0 + 30, height / 2.0, 0
29+
rotate_x -PI / 6
30+
rotate_y PI / 3 + mouse_y / height.to_f * PI
31+
box 45
32+
translate 0, 0, -50
33+
box 30
34+
end
35+
36+
def settings
37+
size 640, 360, P3D
38+
end
39+
end
40+
41+
Perspective.new
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
# Move the mouse left and right to change the field of view (fov).
4+
# Click to modify the aspect ratio. The perspektiv method
5+
# sets a perspective projection applying foreshortening, making
6+
# distant objects appear smaller than closer ones. The parameters
7+
# define a viewing volume with the shape of truncated pyramid.
8+
# while farther objects appear smaller. This projection simulates
9+
# the perspective of the world more accurately than orthographic projection.
10+
# The version of perspektiv without parameters sets the default
11+
# perspective and the version with up to four parameters allows the programmer
12+
# to set the environment more precisely.
13+
class Perspektiv < Propane::App
14+
def setup
15+
sketch_title 'Perspektiv Example'
16+
no_stroke
17+
end
18+
19+
def draw
20+
lights
21+
background 204
22+
camera_y = height / 2.0
23+
fov = mouse_x / width.to_f * PI / 2.0
24+
camera_z = camera_y / Math.tan(fov / 2.0)
25+
aspect = width.to_f / height
26+
aspect /= 2.0 if mouse_pressed?
27+
perspektiv(
28+
fov: fov,
29+
aspect_ratio: aspect,
30+
near_z: camera_z / 10.0,
31+
far_z: camera_z * 10.0
32+
)
33+
translate width / 2.0 + 30, height / 2.0, 0
34+
rotate_x -PI / 6
35+
rotate_y PI / 3 + mouse_y / height.to_f * PI
36+
box 45
37+
translate 0, 0, -50
38+
box 30
39+
end
40+
41+
def settings
42+
size 640, 360, P3D
43+
end
44+
end
45+
46+
Perspektiv.new
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env jruby -v -W2
2+
require 'propane'
3+
# Move the mouse left and right to change the field of view (fov).
4+
# Click to modify the aspect ratio. The perspektiv method
5+
# sets a perspective projection applying foreshortening, making
6+
# distant objects appear smaller than closer ones. The parameters
7+
# define a viewing volume with the shape of truncated pyramid.
8+
# while farther objects appear smaller. This projection simulates
9+
# the perspective of the world more accurately than orthographic projection.
10+
# The version of perspective without parameters sets the default
11+
# perspective and the version with up to four parameters allows the programmer
12+
# to set the area precisely.
13+
class Perspektiv < Propane::App
14+
def setup
15+
sketch_title 'Perspektiv2 Example'
16+
no_stroke
17+
end
18+
19+
def draw
20+
lights
21+
background 204
22+
camera_y = height / 2.0
23+
fov = mouse_x / width.to_f * PI / 2.0
24+
camera_z = camera_y / Math.tan(fov / 2.0)
25+
aspect = width.to_f / height.to_f
26+
aspect /= 2.0 if mouse_pressed?
27+
# here we omit aspect ratio (defaults to width / height)
28+
perspektiv(
29+
fov: fov,
30+
near_z: camera_z / 10.0,
31+
far_z: camera_z * 10.0
32+
)
33+
translate width / 2.0 + 30, height / 2.0, 0
34+
rotate_x -PI / 6
35+
rotate_y PI / 3 + mouse_y / height.to_f * PI
36+
box 45
37+
translate 0, 0, -50
38+
box 30
39+
end
40+
41+
def settings
42+
size 640, 360, P3D
43+
end
44+
end
45+
46+
Perspektiv.new
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

0 commit comments

Comments
 (0)