|
| 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