Skip to content

Commit b31363d

Browse files
committed
new processing library example
1 parent 16dbb67 commit b31363d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env jruby --dev
2+
require 'propane'
3+
require_relative './vector_list'
4+
class ContourMap < Propane::App
5+
load_library :pgs
6+
java_import 'micycle.pgs.PGS_Contour'
7+
8+
attr_reader :heights, :max, :min
9+
MAX = -1
10+
MIN = 9999
11+
12+
def setup
13+
sketch_title 'Contour Map'
14+
@max = MAX
15+
@min = MIN
16+
end
17+
18+
def draw
19+
background(0, 0, 40)
20+
populate_height_map
21+
isolines = PGS_Contour.isolines(heights.array_list, 0.08, min, max)
22+
isolines.to_hash.each do |isoline, value|
23+
isoline.set_stroke(
24+
color(
25+
map1d(value, min..max, 50..255),
26+
map1d(isoline.get_vertex(0).x, 0..width, 50..255),
27+
map1d(isoline.get_vertex(0).y, 0..height, 50..255)
28+
)
29+
)
30+
shape(isoline)
31+
end
32+
end
33+
34+
def populate_height_map
35+
@heights = VectorList.new
36+
37+
res = 16
38+
anim_speed = 0.005
39+
40+
grid(width + res, height + res, res, res) do |x, y|
41+
z = norm(noise(x*0.01 + frame_count*anim_speed, y*0.01 + frame_count*anim_speed), -1.0, 1.0)
42+
h = Vec3D.new(x, y, 0)
43+
z += h.dist(Vec3D.new(mouse_x, mouse_y, 0))*0.005
44+
h.z = z
45+
heights << h
46+
@max = [max, z].max
47+
@min = [min, z].min
48+
end
49+
end
50+
51+
def settings
52+
size(800, 800)
53+
end
54+
end
55+
56+
ContourMap.new
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
java_import 'java.util.ArrayList'
2+
java_import 'processing.core.PVector'
3+
4+
class VectorList
5+
attr_reader :array_list
6+
def initialize
7+
@array_list = ArrayList.new
8+
end
9+
10+
def <<(val)
11+
array_list.add(PVector.new(val.x, val.y, val.z))
12+
end
13+
end

0 commit comments

Comments
 (0)