|
| 1 | +require 'toxiclibs' |
| 2 | + |
| 3 | +# A 3D Tentacle by Nikolaus Gradwohl http://www.local-guru.net |
| 4 | +# Adapted for JRubyArt and mesh to PShape, and mesh2 export by Martin Prout |
| 5 | + |
| 6 | +attr_reader :mesh, :gfx, :tentacle |
| 7 | + |
| 8 | +def settings |
| 9 | + size(500, 500, P3D) |
| 10 | +end |
| 11 | + |
| 12 | +def setup |
| 13 | + sketch_title 'Tentacle' |
| 14 | + ArcBall.init(self) |
| 15 | + @gfx = Gfx::MeshToVBO.new(self) |
| 16 | + volume = VolumetricSpaceArray.new(TVec3D.new(100, 200, 100), 100, 100, 100) |
| 17 | + surface = ArrayIsoSurface.new(volume) |
| 18 | + @mesh = TriangleMesh.new |
| 19 | + brush = RoundBrush.new(volume, 10) |
| 20 | + 20.times do |i| |
| 21 | + brush.set_size(i * 1.2 + 6) |
| 22 | + x = cos(i * TWO_PI / 20) * 10 |
| 23 | + y = sin(i * TWO_PI / 20) * 10 |
| 24 | + brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1) |
| 25 | + end |
| 26 | + (4..20).step(4) do |i| |
| 27 | + brush.set_size(i / 1.5 + 4) |
| 28 | + x = cos(i * TWO_PI / 20) * (i * 1.2 + 16) |
| 29 | + y = sin(i * TWO_PI / 20) * (i * 1.2 + 16) |
| 30 | + brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1) |
| 31 | + brush.set_size(i / 2 + 2) |
| 32 | + x2 = cos(i * TWO_PI / 20) * (i * 1.2 + 18) |
| 33 | + y2 = sin(i * TWO_PI / 20) * (i * 1.2 + 18) |
| 34 | + brush.draw_at_absolute_pos(TVec3D.new(x2, -25 + i * 7, y2), -1.4) |
| 35 | + end |
| 36 | + volume.close_sides |
| 37 | + surface.reset |
| 38 | + surface.compute_surface_mesh(mesh, 0.5) |
| 39 | + no_stroke |
| 40 | + @tentacle = gfx.mesh_to_shape(mesh, true) |
| 41 | + tentacle.set_fill(color(200, 10, 10)) |
| 42 | + tentacle.set_ambient(80) |
| 43 | + tentacle.set_specular(80) |
| 44 | +end |
| 45 | + |
| 46 | +def draw |
| 47 | + background(150) |
| 48 | + lights |
| 49 | + setup_lights |
| 50 | + shape(tentacle) |
| 51 | +end |
| 52 | + |
| 53 | +def setup_lights |
| 54 | + lights |
| 55 | + ambient_light(100, 100, 100) |
| 56 | + directional_light(100, 100, 100, -1, -1, 1) |
| 57 | + light_specular(50, 50, 50) |
| 58 | +end |
| 59 | + |
| 60 | +def key_pressed |
| 61 | + case key |
| 62 | + when 'p', 'P' |
| 63 | + fileID = 'Tentacle' |
| 64 | + pm = Gfx::POVMesh.new(self) |
| 65 | + pm.begin_save(java.io.File.new(fileID + '.inc')) |
| 66 | + pm.set_texture(Gfx::Textures::RED) # red with Phong texture |
| 67 | + pm.saveAsPOV(mesh, true) |
| 68 | + pm.end_save |
| 69 | + exit |
| 70 | + when 's', 'S' |
| 71 | + save_frame('Tentacle.png') |
| 72 | + end |
| 73 | +end |
0 commit comments