Skip to content

Commit 26e6b9f

Browse files
committed
fix povmesh sketch
1 parent a3c96a5 commit 26e6b9f

File tree

2 files changed

+64
-57
lines changed

2 files changed

+64
-57
lines changed
2.76 KB
Loading
Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,78 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
13
require 'toxiclibs'
4+
require 'arcball'
25

36
# A 3D Tentacle by Nikolaus Gradwohl http://www.local-guru.net
47
# Adapted for JRubyArt and mesh to PShape, and mesh2 export by Martin Prout
8+
class Tentacle < Propane::App
59

6-
attr_reader :mesh, :gfx, :tentacle, :tex
10+
attr_reader :mesh, :gfx, :tentacle, :tex
711

8-
def settings
9-
size(500, 500, P3D)
10-
end
11-
12-
def setup
13-
sketch_title 'Tentacle'
14-
@tex = load_image(data_path('mask.jpg'))
15-
ArcBall.init(self)
16-
@gfx = Gfx::MeshToVBO.new(self)
17-
volume = VolumetricSpaceArray.new(TVec3D.new(100, 200, 100), 100, 100, 100)
18-
surface = ArrayIsoSurface.new(volume)
19-
@mesh = TriangleMesh.new
20-
brush = RoundBrush.new(volume, 10)
21-
20.times do |i|
22-
brush.set_size(i * 1.2 + 6)
23-
x = cos(i * TWO_PI / 20) * 10
24-
y = sin(i * TWO_PI / 20) * 10
25-
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
12+
def settings
13+
size(500, 500, P3D)
2614
end
27-
(4..20).step(4) do |i|
28-
brush.set_size(i / 1.5 + 4)
29-
x = cos(i * TWO_PI / 20) * (i * 1.2 + 16)
30-
y = sin(i * TWO_PI / 20) * (i * 1.2 + 16)
31-
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
32-
brush.set_size(i / 2 + 2)
33-
x2 = cos(i * TWO_PI / 20) * (i * 1.2 + 18)
34-
y2 = sin(i * TWO_PI / 20) * (i * 1.2 + 18)
35-
brush.draw_at_absolute_pos(TVec3D.new(x2, -25 + i * 7, y2), -1.4)
15+
16+
def setup
17+
sketch_title 'Tentacle'
18+
@tex = load_image(data_path('mask.jpg'))
19+
Processing::ArcBall.init(self)
20+
@gfx = Gfx::MeshToVBO.new(self)
21+
volume = VolumetricSpaceArray.new(TVec3D.new(100, 200, 100), 100, 100, 100)
22+
surface = ArrayIsoSurface.new(volume)
23+
@mesh = TriangleMesh.new
24+
brush = RoundBrush.new(volume, 10)
25+
20.times do |i|
26+
brush.set_size(i * 1.2 + 6)
27+
x = cos(i * TWO_PI / 20) * 10
28+
y = sin(i * TWO_PI / 20) * 10
29+
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
30+
end
31+
(4..20).step(4) do |i|
32+
brush.set_size(i / 1.5 + 4)
33+
x = cos(i * TWO_PI / 20) * (i * 1.2 + 16)
34+
y = sin(i * TWO_PI / 20) * (i * 1.2 + 16)
35+
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
36+
brush.set_size(i / 2 + 2)
37+
x2 = cos(i * TWO_PI / 20) * (i * 1.2 + 18)
38+
y2 = sin(i * TWO_PI / 20) * (i * 1.2 + 18)
39+
brush.draw_at_absolute_pos(TVec3D.new(x2, -25 + i * 7, y2), -1.4)
40+
end
41+
volume.close_sides
42+
surface.reset
43+
surface.compute_surface_mesh(mesh, 0.5)
44+
no_stroke
45+
@tentacle = gfx.mesh_to_textured_shape(mesh, tex)
3646
end
37-
volume.close_sides
38-
surface.reset
39-
surface.compute_surface_mesh(mesh, 0.5)
40-
no_stroke
41-
@tentacle = gfx.mesh_to_textured_shape(mesh, tex)
42-
end
4347

44-
def draw
45-
background(150)
46-
define_lights
47-
shape(tentacle)
48-
end
48+
def draw
49+
background(150)
50+
define_lights
51+
shape(tentacle)
52+
end
4953

50-
def define_lights
51-
lights
52-
ambient_light(40, 40, 40)
53-
directional_light(10, 30, 40, 1, 1, 0)
54-
directional_light(10, 30, 40, 1, 1, -1)
55-
end
54+
def define_lights
55+
lights
56+
ambient_light(40, 40, 40)
57+
directional_light(10, 30, 40, 1, 1, 0)
58+
directional_light(10, 30, 40, 1, 1, -1)
59+
end
5660

5761

58-
def key_pressed
59-
case key
60-
when 'p', 'P'
61-
fileID = 'Tentacle'
62-
pm = Gfx::POVMesh.new(self)
63-
pm.begin_save(java.io.File.new(fileID + '.inc'))
64-
pm.set_texture(Gfx::Textures::RED) # red with Phong texture
65-
pm.saveAsPOV(mesh, true)
66-
pm.end_save
67-
exit
68-
when 's', 'S'
69-
save_frame('Tentacle.png')
62+
def key_pressed
63+
case key
64+
when 'p', 'P'
65+
fileID = 'Tentacle'
66+
pm = Gfx::POVMesh.new(self)
67+
pm.begin_save(java.io.File.new(fileID + '.inc'))
68+
pm.set_texture(Gfx::Textures::RED) # red with Phong texture
69+
pm.saveAsPOV(mesh, true)
70+
pm.end_save
71+
exit
72+
when 's', 'S'
73+
save_frame('Tentacle.png')
74+
end
7075
end
7176
end
77+
78+
Tentacle.new

0 commit comments

Comments
 (0)