|
1 | 1 | #!/usr/bin/env jruby -v -W2 |
2 | 2 | # frozen_string_literal: true |
| 3 | + |
3 | 4 | require 'propane' |
| 5 | +require 'arcball' |
4 | 6 | # DXF DXF Export |
5 | | -# by Simon Greenwold. |
6 | | -# |
| 7 | +# original by Simon Greenwold. |
| 8 | +# Translated to propane by Martin Prout |
| 9 | +# Rotate by dragging mouse, wheel to zoom. |
7 | 10 | # Press the 'R' key to export a DXF file. |
8 | 11 | class DXFExport < Propane::App |
9 | 12 | load_library :dxf |
10 | 13 | attr_reader :recording |
11 | 14 |
|
12 | 15 | def setup |
13 | 16 | sketch_title 'DXF Export' |
14 | | - noStroke |
15 | | - sphereDetail(12) |
| 17 | + Processing::ArcBall.init(self) |
| 18 | + no_stroke |
| 19 | + sphere_detail(15) |
16 | 20 | @recording = false |
17 | 21 | end |
18 | 22 |
|
19 | 23 | def draw |
20 | | - begin_raw(DXF, data_path('output.dxf')) if recording # Start recording to the file |
| 24 | + # Start recording to the file |
| 25 | + begin_raw(DXF, data_path('output.dxf')) if recording |
21 | 26 | lights |
22 | 27 | background(0) |
23 | | - translate(width / 3, height / 3, -200) |
24 | | - rotate_z(map1d(mouse_y, (0..height), (0..PI))) |
25 | | - rotateY(map1d(mouse_x, (0..width), (0..HALF_PI))) |
26 | | - (-2..2).step do |y| |
27 | | - (-2..2).step do |x| |
28 | | - (-2..2).step do |z| |
29 | | - push_matrix |
30 | | - translate(120 * x, 120 * y, -120 * z) |
31 | | - sphere(30) |
32 | | - pop_matrix |
33 | | - end |
34 | | - end |
| 28 | + mesh_grid(400, 400, 400, 80, 80, 80) do |x, y, z| |
| 29 | + push_matrix |
| 30 | + translate(x - 200, y - 200, z - 200) |
| 31 | + sphere(25) |
| 32 | + pop_matrix |
35 | 33 | end |
36 | 34 | end_raw if recording |
37 | | - @recording = false # Stop recording to the file |
| 35 | + # Stop recording to the file |
| 36 | + @recording = false |
38 | 37 | end |
39 | 38 |
|
40 | 39 | def key_pressed |
41 | | - return unless key == 'R' || key == 'r' # Press R to save the file |
| 40 | + # Press R to save the file |
| 41 | + return unless key == 'R' || key == 'r' |
| 42 | + |
42 | 43 | @recording = true |
43 | 44 | end |
44 | 45 |
|
45 | 46 | def settings |
46 | 47 | size(400, 400, P3D) |
| 48 | + smooth(16) |
47 | 49 | end |
48 | 50 | end |
49 | 51 |
|
|
0 commit comments