Skip to content

Commit 9a716e3

Browse files
committed
sampling examples
1 parent 0bad60e commit 9a716e3

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# PixelFlow | Copyright (C) 2016 Thomas Diewald - http://thomasdiewald.com
2+
#
3+
# A Processing/Java library for high performance GPU-Computing (GLSL).
4+
# MIT License: https://opensource.org/licenses/MIT
5+
#
6+
load_library :PixelFlow
7+
java_import 'com.thomasdiewald.pixelflow.java.sampling.DwSampling'
8+
attr_reader :shp_samples, :sample_idx
9+
10+
def settings
11+
size(800, 800, P2D)
12+
smooth(8)
13+
end
14+
15+
def setup
16+
sketch_title 'Sampling Fibonacci'
17+
@sample_idx = 1
18+
@shp_samples = create_shape(GROUP)
19+
frame_rate(1_000)
20+
end
21+
22+
def draw
23+
background(64)
24+
r = 0.01 * sample_idx**0.5
25+
angle = sample_idx * DwSampling::GOLDEN_ANGLE_R
26+
x = r * cos(angle)
27+
y = r * sin(angle)
28+
add_shape(Vec2D.new(x, y), 500)
29+
translate(width / 2, height / 2)
30+
shape(shp_samples)
31+
@sample_idx += 1
32+
end
33+
34+
def add_shape(position, scale)
35+
pos = position * scale
36+
shp_point = create_shape(POINT, pos.x, pos.y)
37+
shp_point.set_stroke(color(255))
38+
shp_point.set_stroke_weight(3)
39+
shp_samples.add_child(shp_point)
40+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# PixelFlow | Copyright (C) 2016 Thomas Diewald - http://thomasdiewald.com
2+
#
3+
# A Processing/Java library for high performance GPU-Computing (GLSL).
4+
# MIT License: https://opensource.org/licenses/MIT
5+
#
6+
load_library :PixelFlow
7+
java_import 'com.thomasdiewald.pixelflow.java.sampling.DwSampling'
8+
attr_reader :shp_samples, :sample_idx, :shp_gizmo
9+
10+
def settings
11+
size(800, 800, P3D)
12+
smooth(8)
13+
end
14+
15+
def setup
16+
sketch_title 'Sampling Halton'
17+
ArcBall.init(self)
18+
@sample_idx = 1
19+
@shp_samples = create_shape(GROUP)
20+
frame_rate(1_000)
21+
end
22+
23+
def draw
24+
background(64)
25+
display_gizmo(500)
26+
sample = DwSampling::uniformSampleHemisphere_Halton(sample_idx)
27+
28+
add_shape(Vec3D.new(*sample), 400)
29+
shape(shp_samples)
30+
@sample_idx += 1
31+
end
32+
33+
def add_shape(position, scale)
34+
pos = position * scale
35+
shp_point = create_shape(POINT, pos.x, pos.y, pos.z)
36+
shp_point.set_stroke(color(255))
37+
shp_point.set_stroke_weight(3)
38+
shp_samples.add_child(shp_point)
39+
end
40+
41+
def display_gizmo(s)
42+
if(shp_gizmo.nil?)
43+
stroke_weight(1)
44+
@shp_gizmo = create_shape
45+
shp_gizmo.begin_shape(LINES)
46+
shp_gizmo.stroke(255,0,0)
47+
shp_gizmo.vertex(0,0,0)
48+
shp_gizmo.vertex(s,0,0)
49+
shp_gizmo.stroke(0,255,0)
50+
shp_gizmo.vertex(0,0,0)
51+
shp_gizmo.vertex(0,s,0)
52+
shp_gizmo.stroke(0,0,255)
53+
shp_gizmo.vertex(0,0,0)
54+
shp_gizmo.vertex(0,0,s)
55+
shp_gizmo.end_shape
56+
end
57+
shape(shp_gizmo)
58+
end

0 commit comments

Comments
 (0)