Skip to content

Commit 9b075b7

Browse files
committed
pdf and svg library examples
1 parent a3506d2 commit 9b075b7

File tree

9 files changed

+210
-6
lines changed

9 files changed

+210
-6
lines changed
Loading

external_library/gem/ruby_wordcram/render_to_pdf.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup
2828
end
2929

3030
def settings
31-
size(700, 700, PDF, 'usconst.pdf')
31+
size(700, 700, PDF, data_path('usconst.pdf'))
3232
end
3333
end
3434
RenderToPDF.new

external_library/gem/ruby_wordcram/render_to_svg.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env jruby
22
require 'propane'
33
require 'ruby_wordcram'
4-
# US Constitution text from http://www.usconstitution.net/const.txt
5-
# Liberation Serif font from RedHat: https://www.redhat.com/promo/fonts/
4+
65
WEB = %w(#0033ff #0055ff #0088ff #00bbff #00ffdd).freeze
76
LETTERS = ('A'..'Z').to_a
87

processing_app/basics/math/noise4_tap.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
class ForD < Propane::App
77
attr_reader :half_w, :half_h, :radius, :spin_x, :spin, :coords
88

9+
PHI = ((1.0 + Math.sqrt(5)) / 2.0 - 1) * TWO_PI # Fibonacci distribution
10+
911
def settings
1012
size(480, 480, P3D)
1113
end
@@ -21,11 +23,9 @@ def setup
2123
@radius = height * 0.4
2224
@spin_x = 0.0
2325
@spin = 0.0
24-
25-
angle = ((1.0 + Math.sqrt(5)) / 2.0 - 1) * TWO_PI # Fibonacci distribution
2626
@coords = (0..2_000).map do |i|
2727
inc = Math.asin(i / 1_000.0 - 1.0) # inclination
28-
az = angle * i # azimuth
28+
az = PHI * i # azimuth
2929
# Too lazy to do this the right way... precalculating both the angles and the coordinates
3030
Coord.new.tap do |coord|
3131
push_matrix
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
# After a sketch by Marc Edwards at Bjango
4+
# https:#github.com/bjango/Processing-SVG-experiments
5+
class CircleRectangle < Propane::App
6+
load_library :svg
7+
8+
def settings
9+
size(250, 250) # Set up a 250×250 canvas.
10+
end
11+
12+
def setup
13+
sketch_title 'Simple Example'
14+
begin_record(SVG, data_path('simple.svg')) # Start recording drawing operations to this file.
15+
no_loop # Only run draw once.
16+
end
17+
18+
def draw
19+
no_stroke # Turn off the border on objects we’re about to draw.
20+
fill(color('#4bbcf6')) # Set the fill colour to light blue.
21+
rect(50, 50, 100, 100) # Draw a rectangle on the canvas and to the SVG file.
22+
fill(color('#5721a5')) # Set the fill colour to purple.
23+
ellipse(150, 150, 100, 100) # Draw a circle on the canvas and to the SVG file.
24+
end_record # Save and close the SVG file recording.
25+
end
26+
end
27+
28+
CircleRectangle.new

processing_app/library/svg/direct.rb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
4+
class SVGExample < Propane::App
5+
load_library :svg
6+
7+
8+
9+
def settings
10+
size(400, 400, SVG, data_path('filename.svg'))
11+
end
12+
13+
def draw
14+
# Draw something good here
15+
line(0, 0, width/2, height)
16+
17+
# Exit the program
18+
puts 'Finished.'
19+
exit
20+
end
21+
end
22+
23+
SVGExample.new
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
4+
class SVGDisplay < Propane::App
5+
load_library :svg
6+
7+
def settings
8+
size(400, 400)
9+
end
10+
11+
def setup
12+
sketch_title 'Display First'
13+
no_loop
14+
begin_record(SVG, data_path('filename.svg'))
15+
end
16+
17+
def draw
18+
# Draw something good here
19+
background 0, 0, 200
20+
fill 200, 0, 0
21+
ellipse(width / 2, height / 2, width * 0.9, height * 0.5)
22+
end_record
23+
end
24+
end
25+
26+
SVGDisplay.new
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env jruby
2+
require 'propane'
3+
# After a sketch by Marc Edwards at Bjango
4+
# https://github.com/bjango/Processing-SVG-experiments
5+
class SunflowerPattern < Propane::App
6+
load_library :svg
7+
8+
STEPS = 50.0
9+
WEB = %w(#191030 #5ee4ff #764aed).freeze
10+
11+
attr_reader :distance, :angle, :palette
12+
13+
def setup
14+
sketch_title 'Sunflower Pattern'
15+
@palette = web_to_color_array(WEB)
16+
begin_record(SVG, data_path('output.svg'))
17+
no_stroke
18+
no_loop
19+
end
20+
21+
def draw
22+
background(palette[0])
23+
grid(STEPS, STEPS) do |i, j|
24+
@angle = j / STEPS * TAU + (i % 2 * TAU / STEPS / 2)
25+
@distance = ease_sine(i / STEPS) * 180
26+
fill(
27+
lerp_color(
28+
color(palette[1]),
29+
color(palette[2]),
30+
ease_steps(i / STEPS, 2 + rand(10))
31+
)
32+
)
33+
circle(
34+
width / 2 + (cos(angle) * distance),
35+
height / 2 + (sin(angle) * distance),
36+
1 + ease_sine(i / STEPS) * 8
37+
)
38+
end
39+
end_record
40+
end
41+
42+
def ease_sine(t)
43+
1 + sin(PI / 2 * t - PI / 2)
44+
end
45+
46+
def ease_steps(t, pow)
47+
t**pow
48+
end
49+
50+
def settings
51+
size(400,400)
52+
end
53+
end
54+
55+
SunflowerPattern.new

0 commit comments

Comments
 (0)