Skip to content

Commit a0edce7

Browse files
committed
3D example
1 parent 5f621b8 commit a0edce7

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
load_library :handy, :gicentreUtils
2+
3+
java_import 'org.gicentre.handy.HandyPresets'
4+
java_import 'org.gicentre.handy.HandyRenderer'
5+
java_import 'org.gicentre.utils.FrameTimer'
6+
##****************************************************************************************
7+
# Simple sketch to test handy 3d shape building. 'H' toggles sketchiness on or off. 'A'
8+
# changes hachure angle. Left and right arrow keys change vertex overshoot. Up and down
9+
# arrows change degree of sketchiness.
10+
# @author Jo Wood, giCentre, City University London.
11+
# @version JRubyArt translation by Martin Prout, now uses ArcBall
12+
##****************************************************************************************
13+
14+
# this file is part of Handy sketchy drawing library. Handy is free software: you can
15+
# redistribute it and/or modify it under the terms of the GNU Lesser General Public License
16+
# as published by the Free Software Foundation, either version 3 of the License, or (at your
17+
# option) any later version.
18+
#
19+
# Handy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
20+
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21+
# See the GNU Lesser General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU Lesser General Public License along with self
24+
# source code (see COPYING.LESSER included with self source code). If not, see
25+
# http://www.gnu.org/licenses/.
26+
#
27+
28+
# ----------------------------- Object variables ------------------------------
29+
attr_reader :h, :is_handy, :roughness, :timer, :overshoot, :angle
30+
attr_reader :xmag, :ymag, :newXmag, :newYmag, :diff
31+
# ---------------------------- Processing methods -----------------------------
32+
def settings
33+
size(640, 360, P3D)
34+
pixelDensity(displayDensity) # Use platform's maximum display density.
35+
end
36+
37+
def setup
38+
sketch_title 'Vertex 3D Test'
39+
ArcBall.init(self)
40+
@xmag = @ymag = @newXmag = @newYmag = 0
41+
@timer = FrameTimer.new
42+
@roughness = 1.5
43+
@overshoot = 1.1
44+
@angle = 45
45+
@h = HandyPresets.createMarker(self)
46+
@is_handy = true
47+
h.setRoughness(roughness)
48+
h.setHachureAngle(angle)
49+
h.setHachurePerturbationAngle(0)
50+
fill(180,80,80)
51+
end
52+
53+
def draw
54+
background(235, 215, 182)
55+
timer.displayFrameRate
56+
h.setSeed(1969)
57+
h.setStrokeWeight(4)
58+
h.setStrokeColour(color(0))
59+
lengthA = 100
60+
lengthB = 60
61+
h.beginShape(QUADS)
62+
h.vertex(-lengthA, lengthA, lengthB)
63+
h.vertex( lengthA, lengthA, lengthB)
64+
h.vertex( lengthA, -lengthA, lengthB)
65+
h.vertex(-lengthA, -lengthA, lengthB)
66+
67+
h.vertex( lengthA, lengthA, lengthB)
68+
h.vertex( lengthA, lengthA, -lengthB)
69+
h.vertex( lengthA, -lengthA, -lengthB)
70+
h.vertex( lengthA, -lengthA, lengthB)
71+
72+
h.vertex( lengthA, lengthA, -lengthB)
73+
h.vertex(-lengthA, lengthA, -lengthB)
74+
h.vertex(-lengthA, -lengthA, -lengthB)
75+
h.vertex( lengthA, -lengthA, -lengthB)
76+
77+
h.vertex(-lengthA, lengthA, -lengthB)
78+
h.vertex(-lengthA, lengthA, lengthB)
79+
h.vertex(-lengthA, -lengthA, lengthB)
80+
h.vertex(-lengthA, -lengthA, -lengthB)
81+
82+
h.vertex(-lengthA, lengthA, -lengthB)
83+
h.vertex( lengthA, lengthA, -lengthB)
84+
h.vertex( lengthA, lengthA, lengthB)
85+
h.vertex(-lengthA, lengthA, lengthB)
86+
87+
h.vertex(-lengthA, -lengthA, -lengthB)
88+
h.vertex( lengthA, -lengthA, -lengthB)
89+
h.vertex( lengthA, -lengthA, lengthB)
90+
h.vertex(-lengthA, -lengthA, lengthB)
91+
h.endShape
92+
93+
# Pencil guide lines.
94+
h.setStrokeWeight(2)
95+
h.setStrokeColour(color(0,100))
96+
h.line(-lengthA*overshoot,lengthA,lengthB, lengthA*overshoot,lengthA,lengthB)
97+
h.line( lengthA,lengthA*overshoot, lengthB, lengthA, -lengthA*overshoot, lengthB)
98+
h.line( lengthA*overshoot, -lengthA, lengthB,-lengthA*overshoot, -lengthA, lengthB)
99+
h.line(-lengthA, -lengthA*overshoot, lengthB,-lengthA, lengthA*overshoot, lengthB)
100+
101+
h.line( lengthA, lengthA, lengthB*overshoot, lengthA, lengthA, -lengthB*overshoot)
102+
h.line( lengthA, lengthA*overshoot, -lengthB, lengthA, -lengthA*overshoot, -lengthB)
103+
h.line( lengthA, -lengthA, -lengthB*overshoot, lengthA, -lengthA, lengthB*overshoot)
104+
105+
h.line( lengthA*overshoot, lengthA, -lengthB,-lengthA*overshoot, lengthA, -lengthB)
106+
h.line(-lengthA, lengthA*overshoot, -lengthB,-lengthA, -lengthA*overshoot, -lengthB)
107+
h.line(-lengthA*overshoot, -lengthA, -lengthB, lengthA*overshoot, -lengthA, -lengthB)
108+
109+
h.line(-lengthA, lengthA, -lengthB*overshoot,-lengthA, lengthA, lengthB*overshoot)
110+
h.line(-lengthA, -lengthA, lengthB*overshoot,-lengthA, -lengthA, -lengthB*overshoot)
111+
end
112+
113+
def key_pressed
114+
case key
115+
when 'h', 'H'
116+
@is_handy = !is_handy
117+
h.set_is_handy(is_handy)
118+
when 'a', 'A'
119+
@angle += 1
120+
h.setHachureAngle(angle)
121+
else
122+
return unless key == CODED
123+
end
124+
case key_code
125+
when UP
126+
@roughness *= 1.1
127+
h.setRoughness(roughness)
128+
when DOWN
129+
@roughness *= 0.9
130+
h.setRoughness(roughness)
131+
when LEFT
132+
@overshoot *= 0.99 if overshoot > 1.0
133+
when RIGHT
134+
@overshoot *= 1.01
135+
end
136+
end

0 commit comments

Comments
 (0)