Skip to content

Commit 0733f5c

Browse files
committed
more handy examples
1 parent a0edce7 commit 0733f5c

File tree

5 files changed

+196
-3
lines changed

5 files changed

+196
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Simple demo Rakefile to autorun samples in current directory
2+
# adjust path to k9 executable, and or opts as required
3+
4+
SAMPLES_DIR="./"
5+
6+
desc 'run demo'
7+
task :default => [:demo]
8+
9+
desc 'demo'
10+
task :demo do
11+
samples_list.shuffle.each{|sample| run_sample sample}
12+
end
13+
14+
def samples_list
15+
files = []
16+
Dir.chdir(SAMPLES_DIR)
17+
Dir.glob("*.rb").each do |file|
18+
files << File.join(SAMPLES_DIR, file)
19+
end
20+
return files
21+
end
22+
23+
def run_sample(sample_name)
24+
puts "Running #{sample_name}...quit to run next sample"
25+
open("|k9 -r #{sample_name}", "r") do |io|
26+
while l = io.gets
27+
puts(l.chop)
28+
end
29+
end
30+
end
13.4 KB
Binary file not shown.
31.2 KB
Binary file not shown.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
load_libraries :handy, :gicentreUtils
2+
java_import 'org.gicentre.handy.HandyPresets'
3+
java_import 'org.gicentre.handy.HandyRenderer'
4+
java_import 'org.gicentre.utils.move.ZoomPan'
5+
#*****************************************************************************************
6+
# Simple sketch to show handy shape drawing in four different present styles. H key toggles
7+
# sketchy rendering on or off. Left and right arrows change the hachure angle. Image zoomed
8+
# and panned with mouse drag.
9+
# @author Jo Wood, giCentre, City University London.
10+
# @version JRubyArt translated by Martin Prout
11+
#
12+
# *****************************************************************************************
13+
14+
# self 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+
30+
attr_reader :pencil, :marker, :water, :cPencil, :border, :zoomer, :angle
31+
attr_reader :isHandy, :sketchyFont, :normalFont
32+
33+
# ---------------------------- Processing methods -----------------------------
34+
def settings
35+
size(1200, 800)
36+
# Should work with all Processing 3 renderers.
37+
# size(1200, 800, P2D)
38+
# size(1200, 800, P3D)
39+
# size(1200, 800, FX2D)
40+
pixelDensity(displayDensity) # Use platform's maximum display density.
41+
end
42+
43+
def setup
44+
sketch_title 'Preset Styles Demo'
45+
@zoomer = ZoomPan.new(self)
46+
@angle = -42
47+
@isHandy = true
48+
@pencil = HandyPresets.create_pencil(self)
49+
@water = HandyPresets.create_water_and_ink(self)
50+
@marker = HandyPresets.create_marker(self)
51+
@cPencil = HandyPresets.create_coloured_pencil(self)
52+
@border = HandyRenderer.new(self)
53+
pencil.set_hachure_angle(angle)
54+
water.set_hachure_angle(angle)
55+
marker.set_hachure_angle(angle)
56+
cPencil.set_hachure_angle(angle)
57+
@sketchyFont = load_font(data_path('HumorSans-32.vlw'))
58+
@normalFont = create_font('sans-serif', 32)
59+
end
60+
61+
def draw
62+
background(255)
63+
zoomer.transform
64+
pencil.set_seed(1234)
65+
water.set_seed(1234)
66+
marker.set_seed(1234)
67+
cPencil.set_seed(1234)
68+
stroke(0)
69+
stroke_weight(1)
70+
textAlign(RIGHT,BOTTOM)
71+
if isHandy
72+
text_font(sketchyFont)
73+
else
74+
text_font(normalFont)
75+
end
76+
srand(10)
77+
no_fill
78+
border.rect(10, 10, width / 2 - 20, height / 2 - 20)
79+
draw_shapes(pencil, 0, 0, width / 2, height / 2)
80+
fill(60)
81+
text('Pencil', width / 2 - 20, height / 2-15)
82+
no_fill
83+
border.rect(width / 2 + 10, 10,width / 2 - 20, height / 2 - 20)
84+
draw_shapes(water, width / 2, 0, width / 2, height / 2)
85+
fill(60)
86+
text('Ink and watercolour', width - 20,height / 2-15)
87+
no_fill
88+
border.rect(10, height / 2 + 10, width / 2 - 20, height / 2 - 20)
89+
draw_shapes(marker, 0, height / 2, width / 2, height / 2)
90+
fill(60)
91+
text('Marker pen', width / 2 - 20, height - 15)
92+
no_fill
93+
border.rect(width / 2 + 10, height / 2 + 10, width / 2 - 20, height / 2 - 20)
94+
draw_shapes(cPencil,width/2,height / 2,width/2,height / 2)
95+
fill(60)
96+
text('Coloured pencil', width - 20,height - 15)
97+
no_loop
98+
end
99+
100+
def key_pressed
101+
case key
102+
when 'h', 'H'
103+
@isHandy = !isHandy
104+
pencil.setIsHandy(isHandy)
105+
water.setIsHandy(isHandy)
106+
marker.setIsHandy(isHandy)
107+
cPencil.setIsHandy(isHandy)
108+
loop
109+
when 'r', 'R'
110+
zoomer.reset
111+
loop
112+
else
113+
return unless key == CODED
114+
end
115+
case key_code
116+
when LEFT
117+
@angle -= 1
118+
pencil.set_hachure_angle(angle)
119+
water.set_hachure_angle(angle)
120+
marker.set_hachure_angle(angle)
121+
cPencil.set_hachure_angle(angle)
122+
loop
123+
when RIGHT
124+
@angle += 1
125+
pencil.set_hachure_angle(angle)
126+
water.set_hachure_angle(angle)
127+
marker.set_hachure_angle(angle)
128+
cPencil.set_hachure_angle(angle)
129+
loop
130+
end
131+
end
132+
133+
def mouse_dragged
134+
loop
135+
end
136+
137+
private
138+
139+
def draw_shapes(handy, x, y, w, h)
140+
minSize = w / 10
141+
maxSize = min(w, h) / 4
142+
30.times do
143+
colour = color(rand(100..200), rand(60..200), rand(100..200), 120)
144+
fill(colour)
145+
shape_choice = rand
146+
if (shape_choice < 0.33)
147+
handy.rect(x + rand(minSize..w - maxSize),y + rand(minSize..h - maxSize),rand(minSize..maxSize), rand(minSize..maxSize))
148+
elsif shape_choice < 0.66
149+
x1 = x + rand(minSize..w - maxSize)
150+
y1 = y + rand(minSize..h - maxSize)
151+
x2 = x1 + rand(50..maxSize)
152+
y2 = y1 + rand(-10..10)
153+
x3 = (x1 + x2) / 2
154+
y3 = y1 - rand(minSize..maxSize)
155+
handy.triangle(x1, y1, x2, y2, x3, y3)
156+
else
157+
handy.ellipse(x + rand(minSize..w - maxSize), y + rand(minSize..h - maxSize),rand(minSize..maxSize), rand(minSize..maxSize))
158+
end
159+
end
160+
end

external_library/java/handy/preset_styles.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
# Version 2.0, 4th April, 2016
33
# Author Jo Wood
44

5-
load_libraries :ball, :handy
5+
load_library :handy
66
java_import 'org.gicentre.handy.HandyPresets'
77

88
attr_reader :h1, :h2, :h3, :h4
99
FIVE = 5
1010

1111
def settings
12-
size(610, 200)
12+
size(1200, 800)
13+
# size(1200, 800, P2D)
14+
# size(1200, 800, P3D)
15+
# size(1200, 800, FX2D)
1316
end
1417

1518
def setup
16-
sketch_title 'Simple Preset Styles'
19+
sketch_title 'Preset Styles Test'
1720
@h1 = HandyPresets.create_pencil(self)
1821
@h2 = HandyPresets.create_coloured_pencil(self)
1922
@h3 = HandyPresets.create_water_and_ink(self)

0 commit comments

Comments
 (0)