|
| 1 | + |
| 2 | +# |
| 3 | +# PixelFlow | Copyright (C) 2016 Thomas Diewald - http://thomasdiewald.com |
| 4 | +# |
| 5 | +# A Processing/Java library for high performance GPU-Computing (GLSL). |
| 6 | +# MIT License: https://opensource.org/licenses/MIT |
| 7 | +# |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + load_library :PixelFlow |
| 12 | + java_import 'com.thomasdiewald.pixelflow.java.sampling.PoissonSample' |
| 13 | + java_import 'com.thomasdiewald.pixelflow.java.sampling.PoissonDiscSamping2D' |
| 14 | + attr_reader :samples, :display_radius |
| 15 | + |
| 16 | + def settings |
| 17 | + size(1280, 720, P2D) |
| 18 | + smooth(16) |
| 19 | + end |
| 20 | + |
| 21 | + def setup |
| 22 | + sketch_title 'Poisson Sampling 2D' |
| 23 | + @display_radius = true |
| 24 | + generate_poisson_sampling2d |
| 25 | + end |
| 26 | + |
| 27 | + |
| 28 | + def generate_poisson_sampling2d |
| 29 | + pds = RealDiscSamping2D.new |
| 30 | + bounds = [0, 0, 0, width, height, 0] |
| 31 | + rmin = 2 |
| 32 | + rmax = 25 |
| 33 | + roff = 0.5 |
| 34 | + new_points = 100 |
| 35 | + start = Time.now |
| 36 | + pds.setRandomSeed(rand(0..10_0000)) |
| 37 | + pds.generatePoissonSampling2D(bounds, rmin, rmax, roff, new_points) |
| 38 | + time = Time.now - start |
| 39 | + puts("poisson samples 2D generated") |
| 40 | + puts(" time: #{(time * 1000).floor}ms") |
| 41 | + puts(" count: #{pds.samples.size}") |
| 42 | + @samples = pds.samples |
| 43 | + end |
| 44 | + |
| 45 | + def draw |
| 46 | + background(64) |
| 47 | + samples.each do |sample| |
| 48 | + px = sample.x |
| 49 | + py = sample.y |
| 50 | + pr = sample.rad |
| 51 | + if display_radius |
| 52 | + stroke(255) |
| 53 | + stroke_weight(0.5) |
| 54 | + fill(255) |
| 55 | + no_stroke |
| 56 | + ellipse(px, py, pr * 2, pr * 2) |
| 57 | + else |
| 58 | + stroke(255) |
| 59 | + stroke_weight(2) |
| 60 | + point(px, py) |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + def key_released |
| 66 | + case key |
| 67 | + when ' ' |
| 68 | + @display_radius = !display_radius |
| 69 | + when 'r' |
| 70 | + generate_poisson_sampling2d |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + class RealDiscSamping2D < PoissonDiscSamping2D |
| 75 | + def newInstance(x, y, r, rcollision) |
| 76 | + PoissonSample.new(x, y, r, rcollision) |
| 77 | + end |
| 78 | + end |
0 commit comments