Skip to content

Commit 35b5a86

Browse files
committed
refactor hype examples
1 parent c98c5ea commit 35b5a86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+816
-252
lines changed

basics/color/colors_two.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def settings
1414

1515
def setup
1616
sketch_title 'Homage to Albers'
17-
# palette = web_to_color_array(['#CC6600', '#CC9900', '#993300'].to_java(:string))
18-
palette = web_to_color_array(['#CC6600', '#CC9900', '#993300'])
17+
# palette = from_web_array(['#CC6600', '#CC9900', '#993300'].to_java(:string))
18+
palette = from_web_array(['#CC6600', '#CC9900', '#993300'])
1919
# @redder = color 204, 102, 0
2020
# @yellower = color 204, 153, 0
2121
# @orangish = color 153, 51, 0

basics/color/creating_colors.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def settings
1515

1616
def setup
1717
sketch_title 'Homage to Albers'
18-
palette = web_to_color_array(WEB)
18+
palette = from_web_array(WEB)
1919
@redder = palette[0]
2020
@yellower = palette[1]
2121
@orangish = palette[2]

data/wovns.png

60.2 KB
Loading

demo/arc_tesselation.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def setup
2121
background 0
2222
sketch_title 'Arc Tesselation'
2323
# create a java primitive array of signed int
24-
# @cols = web_to_color_array(PALETTE)
25-
@group = ColorGroup.from_web_array(PALETTE)
24+
# @cols = from_web_array(PALETTE)
25+
@group = ColorGroup.from_web_array(PALETTE.to_java(:string)
2626
@cols = group.colors
2727
stroke_weight 1.5
2828
stroke_cap SQUARE

demo/fading.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Fading < Processing::App
1010

1111
def setup
1212
sketch_title 'Fading Arcs'
13-
@group = ColorGroup.from_web_array(PALETTE)
13+
@group = ColorGroup.from_web_array(PALETTE.to_java(:string)
1414
colors = group.colors
1515
background(group.last)
1616
no_stroke

external_library/gems/ruby_wordcram/fruits.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'ruby_wordcram'
44

55
# Literate colors from picrate
6-
# uses `web_to_color_array` to create a hash of fruity colors
6+
# uses `from_web_array` to create a hash of fruity colors
77
# to join two words as `cherry\ red` use back slash
88
class Fruits < Processing::App
99

@@ -17,7 +17,7 @@ def settings
1717
def setup
1818
sketch_title 'Fruity Colors'
1919
background(255)
20-
colors = FRUITS.zip(web_to_color_array(PALETTE)).to_h
20+
colors = FRUITS.zip(from_web_array(PALETTE)).to_h
2121
longest = FRUITS.max { |a, b| a.length <=> b.length }
2222
shortest = FRUITS.min { |a, b| a.length <=> b.length }
2323
words = FRUITS.map do |fruit|

external_library/java/handy/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The Handy Library by Jo Wood et al giCentre
2+
3+
The Handy library allows you to produce graphics with a hand-drawn appearance in Processing sketches. This can be customised to produce a variety of styles including pencil, watercolour and ink and marker pen appearance.
4+
5+
### Obtaining Library
6+
7+
Get it [here][web] install in `~/.picrate/libraries` or local to sketch
8+
9+
[web]:https://www.gicentre.net/handy

library/hype/Rakefile renamed to external_library/java/handy/Rakefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ end
2222

2323
def run_sample(sample_name)
2424
puts "Running #{sample_name}...quit to run next sample"
25-
open("|k9 -r #{sample_name}", "r") do |io|
25+
open("|jruby #{sample_name}", "r") do |io|
2626
while l = io.gets
27-
puts(l.chop)
28-
end
27+
puts(l.chop)
28+
end
2929
end
3030
end
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
# Displays 4 sketchy rectangles with different hachuring styles.
4+
# Version for propane by Martin Prout
5+
# Author Jo Wood.
6+
class HachureStyles < Processing::App
7+
load_library :handy
8+
java_import 'org.gicentre.handy.HandyRenderer'
9+
10+
attr_reader :handy
11+
12+
def settings
13+
size(300, 200)
14+
end
15+
16+
def setup
17+
sketch_title 'Simple Hachure Styles'
18+
@handy = HandyRenderer.new(self)
19+
fill(206,76,52)
20+
handy.set_hachure_perturbation_angle(15)
21+
end
22+
23+
def draw
24+
background(247,230,197)
25+
handy.set_roughness(1)
26+
handy.set_fill_gap(0.5)
27+
handy.set_fill_weight(0.1)
28+
handy.rect(50, 30, 80, 50)
29+
handy.set_fill_gap(3)
30+
handy.set_fill_weight(2)
31+
handy.rect(170, 30, 80, 50)
32+
handy.set_fill_gap(5)
33+
handy.set_is_alternating(true)
34+
handy.rect(50, 120, 80, 50)
35+
handy.set_roughness(3)
36+
handy.set_fill_weight(1)
37+
handy.set_is_alternating(false)
38+
handy.rect(170, 120, 80, 50)
39+
no_loop # No need to redraw.
40+
end
41+
end
42+
43+
HachureStyles.new
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
# After a processing.rb example by kitao.
4+
class HandyBallCollision < Processing::App
5+
load_libraries :handy, :balls
6+
java_import 'org.gicentre.handy.HandyRenderer'
7+
BALL_NUM = 6
8+
BALL_COLORS = [[255, 0, 0], [255, 255, 0], [64, 64, 255]].freeze
9+
10+
attr_reader :handy, :balls
11+
12+
def settings
13+
size(400, 400)
14+
end
15+
16+
def setup
17+
sketch_title 'Handy Ball Collision'
18+
@handy = HandyRenderer.new(self)
19+
@balls = (0...BALL_NUM).map { |idx| Ball.new(self, idx) }
20+
end
21+
22+
def draw
23+
background(234, 215, 182)
24+
fill(0, 255, 0)
25+
draw_borders(handy)
26+
balls.each(&:draw)
27+
end
28+
29+
def draw_borders(renderer)
30+
renderer.rect(20, 20, 360, 20)
31+
renderer.rect(20, 360, 360, 20)
32+
renderer.rect(20, 40, 20, 320)
33+
renderer.rect(360, 40, 20, 320)
34+
end
35+
end
36+
37+
HandyBallCollision.new
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
BALL_COLORS = [[255, 0, 0], [255, 255, 0], [64, 64, 255]].freeze
2+
3+
# Bouncing ball
4+
class Ball
5+
attr_reader :sketch, :position, :delta, :bounds
6+
7+
def initialize(sketch, id)
8+
@sketch = sketch
9+
@position = Vec2D.new rand(100..300), rand(100..300)
10+
@delta = Vec2D.new rand(-6..6), rand(-6..6)
11+
@size = rand(60..100)
12+
radius = @size / 2.0
13+
@color = BALL_COLORS[id % BALL_COLORS.size]
14+
@bounds = Boundary.new(40 + radius, 360 - radius)
15+
end
16+
17+
def draw
18+
@position += delta
19+
if bounds.exclude? position.x
20+
position.x = position.x > bounds.upper ? bounds.upper : bounds.lower
21+
delta.x *= -1
22+
end
23+
if bounds.exclude? position.y
24+
position.y = position.y > bounds.upper ? bounds.upper : bounds.lower
25+
delta.y *= -1
26+
end
27+
sketch.fill(*@color)
28+
sketch.handy.ellipse(position.x, position.y, @size, @size)
29+
end
30+
end
31+
32+
# Useful helper class
33+
Boundary = Struct.new(:lower, :upper) do
34+
def exclude?(val)
35+
!(lower..upper).cover? val
36+
end
37+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/usr/bin/env jruby
2+
require 'picrate'
3+
# Displays 4 sketchy rectangles with different hachuring styles.
4+
# Version for propane by Martin Prout
5+
# Author Jo Wood.
6+
class PresetStyleDemo < Processing::App
7+
load_libraries :handy, :gicentre_utils
8+
java_import 'org.gicentre.handy.HandyPresets'
9+
java_import 'org.gicentre.handy.HandyRenderer'
10+
java_import 'org.gicentre.utils.move.ZoomPan'
11+
#*****************************************************************************************
12+
# Simple sketch to show handy shape drawing in four different present styles. H key toggles
13+
# sketchy rendering on or off. Left and right arrows change the hachure angle. Image zoomed
14+
# and panned with mouse drag.
15+
# @author Jo Wood, giCentre, City University London.
16+
# @version JRubyArt translated by Martin Prout
17+
#
18+
# *****************************************************************************************
19+
20+
# self file is part of Handy sketchy drawing library. Handy is free software: you can
21+
# redistribute it and/or modify it under the terms of the GNU Lesser General Public License
22+
# as published by the Free Software Foundation, either version 3 of the License, or (at your
23+
# option) any later version.
24+
#
25+
# Handy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
26+
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27+
# See the GNU Lesser General Public License for more details.
28+
#
29+
# You should have received a copy of the GNU Lesser General Public License along with self
30+
# source code (see COPYING.LESSER included with self source code). If not, see
31+
# http://www.gnu.org/licenses/.
32+
#
33+
34+
# ----------------------------- Object variables ------------------------------
35+
36+
attr_reader :pencil, :marker, :water, :cPencil, :border, :zoomer, :angle
37+
attr_reader :isHandy, :sketchyFont, :normalFont
38+
39+
# ---------------------------- Processing methods -----------------------------
40+
def settings
41+
size(1200, 800)
42+
# Should work with all Processing 3 renderers.
43+
# size(1200, 800, P2D)
44+
# size(1200, 800, P3D)
45+
# size(1200, 800, FX2D)
46+
pixelDensity(displayDensity) # Use platform's maximum display density.
47+
end
48+
49+
def setup
50+
sketch_title 'Preset Styles Demo'
51+
@zoomer = ZoomPan.new(self)
52+
@angle = -42
53+
@isHandy = true
54+
@pencil = HandyPresets.create_pencil(self)
55+
@water = HandyPresets.create_water_and_ink(self)
56+
@marker = HandyPresets.create_marker(self)
57+
@cPencil = HandyPresets.create_coloured_pencil(self)
58+
@border = HandyRenderer.new(self)
59+
pencil.set_hachure_angle(angle)
60+
water.set_hachure_angle(angle)
61+
marker.set_hachure_angle(angle)
62+
cPencil.set_hachure_angle(angle)
63+
@sketchyFont = load_font(data_path('HumorSans-32.vlw'))
64+
@normalFont = create_font('sans-serif', 32)
65+
end
66+
67+
def draw
68+
background(255)
69+
zoomer.transform
70+
pencil.set_seed(1234)
71+
water.set_seed(1234)
72+
marker.set_seed(1234)
73+
cPencil.set_seed(1234)
74+
stroke(0)
75+
stroke_weight(1)
76+
textAlign(RIGHT,BOTTOM)
77+
if isHandy
78+
text_font(sketchyFont)
79+
else
80+
text_font(normalFont)
81+
end
82+
srand(10)
83+
no_fill
84+
border.rect(10, 10, width / 2 - 20, height / 2 - 20)
85+
draw_shapes(pencil, 0, 0, width / 2, height / 2)
86+
fill(60)
87+
text('Pencil', width / 2 - 20, height / 2-15)
88+
no_fill
89+
border.rect(width / 2 + 10, 10,width / 2 - 20, height / 2 - 20)
90+
draw_shapes(water, width / 2, 0, width / 2, height / 2)
91+
fill(60)
92+
text('Ink and watercolour', width - 20,height / 2-15)
93+
no_fill
94+
border.rect(10, height / 2 + 10, width / 2 - 20, height / 2 - 20)
95+
draw_shapes(marker, 0, height / 2, width / 2, height / 2)
96+
fill(60)
97+
text('Marker pen', width / 2 - 20, height - 15)
98+
no_fill
99+
border.rect(width / 2 + 10, height / 2 + 10, width / 2 - 20, height / 2 - 20)
100+
draw_shapes(cPencil,width/2,height / 2,width/2,height / 2)
101+
fill(60)
102+
text('Coloured pencil', width - 20,height - 15)
103+
no_loop
104+
end
105+
106+
def key_pressed
107+
case key
108+
when 'h', 'H'
109+
@isHandy = !isHandy
110+
pencil.setIsHandy(isHandy)
111+
water.setIsHandy(isHandy)
112+
marker.setIsHandy(isHandy)
113+
cPencil.setIsHandy(isHandy)
114+
loop
115+
when 'r', 'R'
116+
zoomer.reset
117+
loop
118+
else
119+
return unless key == CODED
120+
end
121+
case key_code
122+
when LEFT
123+
@angle -= 1
124+
pencil.set_hachure_angle(angle)
125+
water.set_hachure_angle(angle)
126+
marker.set_hachure_angle(angle)
127+
cPencil.set_hachure_angle(angle)
128+
loop
129+
when RIGHT
130+
@angle += 1
131+
pencil.set_hachure_angle(angle)
132+
water.set_hachure_angle(angle)
133+
marker.set_hachure_angle(angle)
134+
cPencil.set_hachure_angle(angle)
135+
loop
136+
end
137+
end
138+
139+
def mouse_dragged
140+
loop
141+
end
142+
143+
private
144+
145+
def draw_shapes(handy, x, y, w, h)
146+
minSize = w / 10
147+
maxSize = min(w, h) / 4
148+
30.times do
149+
colour = color(rand(100..200), rand(60..200), rand(100..200), 120)
150+
fill(colour)
151+
shape_choice = rand
152+
if (shape_choice < 0.33)
153+
handy.rect(x + rand(minSize..w - maxSize),y + rand(minSize..h - maxSize),rand(minSize..maxSize), rand(minSize..maxSize))
154+
elsif shape_choice < 0.66
155+
x1 = x + rand(minSize..w - maxSize)
156+
y1 = y + rand(minSize..h - maxSize)
157+
x2 = x1 + rand(50..maxSize)
158+
y2 = y1 + rand(-10..10)
159+
x3 = (x1 + x2) / 2
160+
y3 = y1 - rand(minSize..maxSize)
161+
handy.triangle(x1, y1, x2, y2, x3, y3)
162+
else
163+
handy.ellipse(x + rand(minSize..w - maxSize), y + rand(minSize..h - maxSize),rand(minSize..maxSize), rand(minSize..maxSize))
164+
end
165+
end
166+
end
167+
end
168+
169+
PresetStyleDemo.new

0 commit comments

Comments
 (0)