Skip to content

Commit 371e407

Browse files
committed
WOVNS examples
1 parent 533b1b4 commit 371e407

File tree

13 files changed

+436
-0
lines changed

13 files changed

+436
-0
lines changed

examples/WOVNS/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[WOVNS][wovns] is a San Francisco based company that is a textile studio and technology platform, giving designers access to the means of textile production.
2+
David M. Ellis has created a set of vanilla processing examples producing [WOVNS][wovns] compatible designs, see his work on [github][github] and this [tutorial][tutorial] that he has produced for [WOVNS][wovns]. Here we show how you can use the ruby language to achieve the same result, in much more elegant code (certainly if you are rubyist for loops are plain ugly).
3+
4+
[wovns]:http://www.wovns.com/
5+
[github]:https://github.com/damellis/wovns-processing-examples
6+
[tutorial]:http://www.wovns.com/tutorials/designing-computational-textiles-with-processing/

examples/WOVNS/cross_hatch.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# Divan Quality, Landscape 1 Palette
5+
# This draws a cross-hatch pattern, i.e. a grid of cells, each of which contains
6+
# multiple lines. The lines in each cell alternate between horizontal and vertical.
7+
8+
# the number of stripes to draw in each cell of the grid
9+
class CrossHatch < Propane::App
10+
NUM_STRIPES = 5
11+
12+
def settings
13+
size(2400, 6372) # 13.5" x 36", 177 DPI
14+
no_smooth
15+
end
16+
17+
def setup
18+
sketch_title 'Cross Hatch'
19+
background(color('#050406')) # Black Satin
20+
stroke(color('#C2C2BF')) # Pearl
21+
strokeWeight(10) # draw lines 10 pixels thick
22+
# the width and height of each cell of the grid
23+
w = width / 18
24+
h = height / 48
25+
# the distance between stripes
26+
w2 = w / NUM_STRIPES
27+
h2 = h / NUM_STRIPES
28+
grid(w, h) do |col, row|
29+
(0..NUM_STRIPES).each do |i|
30+
if (row + col).even?
31+
# horizontal lines
32+
line(w * col + w2 / 2, h * row + i * h2 + h2 / 2,
33+
w * (col + 1) - w2 / 2, h * row + i * h2 + h2 / 2)
34+
else
35+
# vertical lines
36+
line(w * col + i * w2 + w2 / 2, h * row + h2 / 2,
37+
w * col + i * w2 + w2 / 2, h * (row + 1) - h2 / 2)
38+
end
39+
end
40+
end
41+
save(data_path('hatch.png'))
42+
end
43+
end
44+
45+
CrossHatch.new

examples/WOVNS/data/circles.svg

Lines changed: 15 additions & 0 deletions
Loading

examples/WOVNS/data/java_args.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-XX:InlineSmallCode=500 -Xms1024m -Xmx2048m

examples/WOVNS/gaussian.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
# Talma Quality, Spectrum 19 Palette
4+
5+
class RandomGaussian < Propane::App
6+
GRID = 7 # 1/12"
7+
8+
def settings
9+
size(3984, 3000)
10+
no_smooth
11+
end
12+
13+
def setup
14+
sketch_title 'Random Gaussian'
15+
background(color('#8B8795')) # Suva
16+
no_stroke
17+
fill(color('#302D32')) # Matte Black
18+
0.step(by: GRID, to: width) do |x|
19+
# threshold based on a gaussian function (bell curve) that gives
20+
# a number between 1 in the middle of the screen and 0 at the left
21+
# and right edges. the 8.0 adjusts the width of the bell, i.e.
22+
# how quickly the value drops to 0 as you move towards the edges of
23+
# the screen.
24+
threshold = Math.exp(-8.0 * (0.5 - (x.to_f / width)) * (0.5 - (x.to_f / width)))
25+
0.step(by: GRID, to: height) do |y|
26+
# generate a random number between 0 and 1 and compare it to the
27+
# threshold. if it's less than the threshold, draw a small square.
28+
rect(x, y, GRID, GRID) if (rand < threshold)
29+
end
30+
end
31+
save(data_path('gaussian.png'))
32+
end
33+
end
34+
35+
RandomGaussian.new

examples/WOVNS/geometric_grid4.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# takes a bit of time to render
5+
# Divan Quality, Pastel 2 Palette
6+
class GeometricGrid < Propane::App
7+
PALETTE = %w(#D1D2EA #BFCDE5 #ABC1E5 #EEC3C3 #FFE4F3 #FFEEF8).freeze
8+
STEP = 133
9+
10+
def settings
11+
size(2400, 6372) # 13.5" x 36", 177 DPI
12+
no_smooth
13+
end
14+
15+
attr_reader :couluers
16+
17+
def setup
18+
sketch_title 'Geometric Grid'
19+
@couluers = web_to_color_array(PALETTE)
20+
background(color('#6984B8')) # Buscabulla
21+
no_stroke
22+
w = width / 18
23+
h = height / 48
24+
grid(width, height, STEP, STEP - 1) do |col, row|
25+
fill(couluers[(row * 1 / 132).to_i % couluers.length])
26+
rect(col + w / 8, row + h / 8, w * 3 / 4, h * 3 / 4)
27+
end
28+
save(data_path('grid.png'))
29+
end
30+
end
31+
32+
GeometricGrid.new

examples/WOVNS/plaid.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# Talma Quality, Landscape 18 Palette
5+
class Plaid < Propane::App
6+
INCH = 84
7+
STRPE = INCH * 3
8+
9+
def settings
10+
size(3984, 3000) # 46-48" x 36" at 84 DPI
11+
no_smooth #
12+
end
13+
14+
def setup
15+
sketch_title 'Plaid'
16+
background(color('#000500')) # Black Feather
17+
no_stroke # Draw vertical stripes every three inches.
18+
fill(color('#0D644C')) # Malachite
19+
0.step(by: STRPE, to: width) do |x|
20+
rect(x, 0, INCH, height) # one inch wide, full-height stripes
21+
end
22+
# Draw stripes every three inches along the height.
23+
fill(color('#B9B34B')) # Black & Gold
24+
0.step(by: STRPE, to: height) do |y|
25+
# For each value of y, draw five stripes, at:
26+
# y, y + 21, y + 42, y + 63, and y + 84.
27+
5.times do |i|
28+
rect(0, y + i * 21, width, 10)
29+
end
30+
end
31+
# Combine the two loops (using JRubyArt grid) to draw a different color where
32+
# the horizontal and vertical stripes intersect.
33+
fill(color('#6A8E51')) # Peridot
34+
grid(width, height, STRPE, STRPE) do |x, y|
35+
5.times do |i|
36+
rect(x, y + i * 21, INCH, 10)
37+
end
38+
end
39+
save(data_path('plaid.png'))
40+
end
41+
end
42+
43+
Plaid.new

examples/WOVNS/random_grid.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# takes quite a long time to render
5+
6+
class RandomGrid < Propane::App
7+
PALETTE = %w(#74AED7 #FFE4F3 #FEE597).freeze
8+
COULEURS = %i(ciel pinking yolk).freeze
9+
STEP = 84
10+
attr_reader :shapes, :web
11+
12+
def settings
13+
size 2400, 6372, P2D
14+
end
15+
16+
def setup
17+
sketch_title 'Random Grid'
18+
@web = COULEURS.zip(web_to_color_array(PALETTE)).to_h
19+
no_stroke
20+
shapeOne = createShape(ELLIPSE, 0, 0, 20, 20)
21+
shapeOne.setFill(web[:pinking])
22+
shapeTwo = createShape(GROUP)
23+
one = createShape(ELLIPSE, 42, 42, 20, 20)
24+
one.setFill(web[:pinking])
25+
two = createShape(ELLIPSE, 21, 21, 20, 20)
26+
one.setFill(web[:yolk])
27+
shapeTwo.addChild(one)
28+
shapeTwo.addChild(two)
29+
shapeThree = createShape(GROUP)
30+
base = createShape(ELLIPSE, 0, 0, 20, 20)
31+
base.setFill(web[:pinking])
32+
three = createShape(ELLIPSE, 21, 21, 20, 20)
33+
three.setFill(web[:pinking])
34+
four = createShape(ELLIPSE, 42, 42, 20, 20)
35+
four.setFill(web[:yolk])
36+
shapeThree.addChild(base)
37+
shapeThree.addChild(three)
38+
shapeThree.addChild(four)
39+
shapeFour = createShape(GROUP)
40+
five = createShape(ELLIPSE, 0, 0, 20, 20)
41+
five.setFill(web[:pinking])
42+
six = createShape(ELLIPSE, 21, 21, 20, 20)
43+
six.setFill(web[:pinking])
44+
seven = createShape(ELLIPSE, 42, 42, 20, 20)
45+
seven.setFill(web[:pinking])
46+
eight = createShape(ELLIPSE, 63, 63, 20, 20)
47+
eight.setFill(web[:yolk])
48+
shapeFour.addChild(five)
49+
shapeFour.addChild(six)
50+
shapeFour.addChild(seven)
51+
shapeFour.addChild(eight)
52+
@shapes = [shapeOne, shapeTwo, shapeThree, shapeFour]
53+
end
54+
55+
def draw
56+
background(web[:ciel]) # Sky blue
57+
grid(width, height, STEP, STEP) do |col, row|
58+
push_matrix
59+
translate col, row
60+
rkey = rand(0..6)
61+
shape(shapes[rkey]) if rkey < 4
62+
pop_matrix
63+
end
64+
save(data_path('random.png'))
65+
no_loop
66+
end
67+
end
68+
69+
RandomGrid.new

examples/WOVNS/repeats.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env jruby
2+
# frozen_string_literal: true
3+
require 'propane'
4+
# Divan Quality, Spectrum 19 Palette
5+
# the size of the generated image (should match the WOVNS quality)
6+
class Repeats < Propane::App
7+
WIDTH = 2400
8+
HEIGHT = 6372
9+
PALETTE = %w(#050505 #B83D4E #FFFFFF).freeze
10+
COULEURS = %i(petrol geranium white).freeze
11+
STRPE = 500
12+
13+
# how many repeats of the generated image to show on-screen
14+
X_REPEATS = 4 # match the number of horizontal repeats in the Divan quality
15+
Y_REPEATS = 2 # show two yards vertically
16+
17+
# scale down the on-screen display by this much
18+
SCALE = 18
19+
20+
attr_reader :web
21+
22+
def settings
23+
size(WIDTH / SCALE * X_REPEATS, HEIGHT / SCALE * Y_REPEATS)
24+
no_smooth
25+
end
26+
27+
def setup
28+
sketch_title 'Repeats'
29+
@web = COULEURS.zip(web_to_color_array(PALETTE)).to_h
30+
pg = create_graphics(WIDTH, HEIGHT)
31+
pg.no_smooth
32+
pg.begin_draw
33+
background(web[:petrol])
34+
pg.background(web[:petrol])
35+
# draw to the saved image
36+
draw_one(pg)
37+
stroke(web[:white])
38+
line(width / X_REPEATS, 0, width / X_REPEATS, height / Y_REPEATS)
39+
line(0, height / Y_REPEATS, width / X_REPEATS, height / Y_REPEATS)
40+
grid(X_REPEATS, Y_REPEATS) do |i, j|
41+
push_matrix # save coordinate system
42+
# translate to the current repeat
43+
translate(i * width / X_REPEATS, j * height / Y_REPEATS)
44+
clip(0, 0, width / X_REPEATS + 1, height / Y_REPEATS + 1)
45+
scale(1.0 / SCALE, 1.0 / SCALE)
46+
# draw to the screen
47+
draw_one(g)
48+
pop_matrix # restore coordinate system
49+
end
50+
pg.end_draw
51+
pg.save(data_path('repeat.png'))
52+
end
53+
54+
# Draw one division of one repeat.
55+
def draw_one(graphics)
56+
graphics.stroke_weight(177)
57+
graphics.stroke(web[:geranium])
58+
graphics.line(0, 0, 2400, 6372)
59+
graphics.line(2400, 0, 0, 6372)
60+
end
61+
end
62+
63+
Repeats.new

examples/WOVNS/stripes.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Talma Quality, Spectrum 2 Palette
2+
PALETTE = %w(#D5C9D9 #B83D4E #95577E #A884A1).freeze
3+
COULEURS = %i(pink_pearl geranium orchid lilac).freeze
4+
STRPE = 500
5+
6+
def settings
7+
size(3984, 3000) # dimensions in pixels (corresponds to 46-48" x 36" at 84 DPI)
8+
no_smooth
9+
end
10+
11+
def setup
12+
sketch_title 'Horizontal Stripes'
13+
web = COULEURS.zip(web_to_color_array(PALETTE)).to_h
14+
background(web[:pink_pearl]) # draw the background
15+
no_stroke # don't draw outlines around shapes
16+
17+
# Draw stripes at y = 0, 500, 1000, 1500, 2000, and 2500.
18+
# Note that we're using the special variable "height", which is the height
19+
# of the canvas (3000 pixels as specified in the call to size() above).
20+
0.step(by: STRPE, to: height) do |y|
21+
# Draw the first stripe using the rect() function.
22+
# Note that we're using the special variable "width", the analogue of
23+
# "height". Its value is 3984.
24+
fill(web[:geranium]) # set the color of the first rectangle
25+
rect(0, y, width, 84) # corner at (0, y). full width, 84 pixels high.
26+
# Draw two shorter stripes.
27+
fill(web[:orchid])
28+
rect(0, y + 84 + 21, width, 10) # start 21 pixels (1/4") below the first stripe
29+
fill(web[:lilac])
30+
rect(0, y + 84 + 42, width, 10) # start 42 pixels (1/2") below the first stripe
31+
end
32+
save(data_path('stripes.png')) # save the output to data folder
33+
end

0 commit comments

Comments
 (0)