squib 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +22 -0
- data/.gitignore +41 -41
- data/CHANGELOG.md +422 -387
- data/CONTRIBUTING.md +40 -40
- data/Dockerfile +27 -25
- data/Gemfile +2 -2
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -22
- data/README.md +139 -121
- data/RELEASE TODO.md +22 -21
- data/Rakefile +51 -48
- data/bin/squib +4 -4
- data/lib/squib.rb +34 -32
- data/lib/squib/api/settings.rb +21 -21
- data/lib/squib/args/arg_loader.rb +129 -126
- data/lib/squib/args/box.rb +59 -55
- data/lib/squib/args/card_range.rb +34 -32
- data/lib/squib/args/color_validator.rb +7 -12
- data/lib/squib/args/coords.rb +49 -35
- data/lib/squib/args/csv_opts.rb +22 -25
- data/lib/squib/args/dir_validator.rb +11 -16
- data/lib/squib/args/draw.rb +93 -92
- data/lib/squib/args/embed_adjust.rb +22 -25
- data/lib/squib/args/embed_key.rb +12 -17
- data/lib/squib/args/hand_special.rb +37 -37
- data/lib/squib/args/import.rb +67 -40
- data/lib/squib/args/input_file.rb +33 -37
- data/lib/squib/args/paint.rb +43 -44
- data/lib/squib/args/paragraph.rb +118 -116
- data/lib/squib/args/save_batch.rb +65 -63
- data/lib/squib/args/scale_box.rb +57 -53
- data/lib/squib/args/sheet.rb +170 -172
- data/lib/squib/args/showcase_special.rb +41 -41
- data/lib/squib/args/sprue_file.rb +44 -44
- data/lib/squib/args/svg_special.rb +37 -37
- data/lib/squib/args/transform.rb +55 -61
- data/lib/squib/args/typographer.rb +115 -119
- data/lib/squib/args/unit_conversion.rb +27 -29
- data/lib/squib/args/xywh_shorthands.rb +51 -0
- data/lib/squib/builtin/layouts/economy.yml +85 -85
- data/lib/squib/builtin/layouts/fantasy.yml +101 -101
- data/lib/squib/builtin/layouts/hand.yml +62 -62
- data/lib/squib/builtin/layouts/party.yml +94 -94
- data/lib/squib/builtin/layouts/playing-card.yml +35 -35
- data/lib/squib/builtin/layouts/tuck_box.yml +46 -46
- data/lib/squib/builtin/projects/advanced/.gitignore +4 -4
- data/lib/squib/builtin/projects/advanced/ABOUT.md +19 -19
- data/lib/squib/builtin/projects/advanced/Gemfile +11 -11
- data/lib/squib/builtin/projects/advanced/Guardfile +21 -21
- data/lib/squib/builtin/projects/advanced/IDEAS.md +22 -22
- data/lib/squib/builtin/projects/advanced/PLAYTESTING.md +26 -26
- data/lib/squib/builtin/projects/advanced/Rakefile +27 -27
- data/lib/squib/builtin/projects/advanced/config.yml +50 -49
- data/lib/squib/builtin/projects/advanced/docs/PNP NOTES.md +3 -3
- data/lib/squib/builtin/projects/advanced/docs/RULES.md +21 -21
- data/lib/squib/builtin/projects/advanced/img/example.svg +60 -60
- data/lib/squib/builtin/projects/advanced/layouts/deck.yml +27 -27
- data/lib/squib/builtin/projects/advanced/src/deck.rb +34 -34
- data/lib/squib/builtin/projects/advanced/src/version.rb +3 -3
- data/lib/squib/builtin/projects/basic/.gitignore +4 -4
- data/lib/squib/builtin/projects/basic/ABOUT.md +19 -19
- data/lib/squib/builtin/projects/basic/Gemfile +3 -3
- data/lib/squib/builtin/projects/basic/IDEAS.md +22 -22
- data/lib/squib/builtin/projects/basic/PLAYTESTING.md +26 -26
- data/lib/squib/builtin/projects/basic/PNP NOTES.md +3 -3
- data/lib/squib/builtin/projects/basic/RULES.md +21 -21
- data/lib/squib/builtin/projects/basic/Rakefile +7 -7
- data/lib/squib/builtin/projects/basic/config.yml +50 -49
- data/lib/squib/builtin/projects/basic/deck.rb +6 -6
- data/lib/squib/builtin/sprues/a4_euro_card.yml +42 -42
- data/lib/squib/builtin/sprues/a4_poker_card_8up.yml +40 -40
- data/lib/squib/builtin/sprues/a4_poker_card_9up.yml +42 -42
- data/lib/squib/builtin/sprues/a4_usa_card.yml +42 -42
- data/lib/squib/builtin/sprues/drivethrucards_1up.yml +10 -10
- data/lib/squib/builtin/sprues/letter_poker_card_9up.yml +25 -25
- data/lib/squib/builtin/sprues/letter_poker_foldable_8up.yml +52 -52
- data/lib/squib/builtin/sprues/printplaygames_18up.yml +68 -68
- data/lib/squib/card.rb +75 -75
- data/lib/squib/commands/cli.rb +39 -39
- data/lib/squib/commands/data/template_option.rb +109 -109
- data/lib/squib/commands/make_sprue.rb +277 -277
- data/lib/squib/commands/new.rb +77 -77
- data/lib/squib/conf.rb +144 -139
- data/lib/squib/constants.rb +17 -17
- data/lib/squib/deck.rb +138 -116
- data/lib/squib/dsl/background.rb +35 -0
- data/lib/squib/dsl/circle.rb +39 -0
- data/lib/squib/dsl/csv.rb +42 -0
- data/lib/squib/dsl/curve.rb +35 -0
- data/lib/squib/dsl/cut_zone.rb +47 -0
- data/lib/squib/dsl/ellipse.rb +37 -0
- data/lib/squib/dsl/grid.rb +35 -0
- data/lib/squib/{api → dsl}/groups.rb +54 -54
- data/lib/squib/dsl/hand.rb +42 -0
- data/lib/squib/dsl/line.rb +35 -0
- data/lib/squib/dsl/png.rb +56 -0
- data/lib/squib/dsl/polygon.rb +36 -0
- data/lib/squib/dsl/rect.rb +37 -0
- data/lib/squib/dsl/safe_zone.rb +48 -0
- data/lib/squib/dsl/save.rb +21 -0
- data/lib/squib/dsl/save_pdf.rb +50 -0
- data/lib/squib/dsl/save_png.rb +44 -0
- data/lib/squib/dsl/save_sheet.rb +53 -0
- data/lib/squib/dsl/showcase.rb +43 -0
- data/lib/squib/dsl/star.rb +37 -0
- data/lib/squib/dsl/svg.rb +62 -0
- data/lib/squib/dsl/text.rb +54 -0
- data/lib/squib/dsl/text_embed.rb +78 -0
- data/lib/squib/dsl/triangle.rb +35 -0
- data/lib/squib/{api → dsl}/units.rb +37 -27
- data/lib/squib/dsl/xlsx.rb +40 -0
- data/lib/squib/dsl/yaml.rb +40 -0
- data/lib/squib/errors_warnings/warn_unexpected_params.rb +14 -0
- data/lib/squib/graphics/background.rb +14 -14
- data/lib/squib/graphics/cairo_context_wrapper.rb +113 -113
- data/lib/squib/graphics/embedding_utils.rb +28 -28
- data/lib/squib/graphics/gradient_regex.rb +47 -47
- data/lib/squib/graphics/hand.rb +42 -42
- data/lib/squib/graphics/image.rb +123 -123
- data/lib/squib/graphics/save_doc.rb +61 -61
- data/lib/squib/graphics/save_images.rb +52 -52
- data/lib/squib/graphics/save_pdf.rb +90 -90
- data/lib/squib/graphics/save_sprue.rb +231 -219
- data/lib/squib/graphics/shapes.rb +143 -143
- data/lib/squib/graphics/showcase.rb +85 -85
- data/lib/squib/graphics/text.rb +202 -174
- data/lib/squib/import/csv_importer.rb +45 -0
- data/lib/squib/import/data_frame.rb +108 -108
- data/lib/squib/import/quantity_exploder.rb +18 -0
- data/lib/squib/import/xlsx_importer.rb +28 -0
- data/lib/squib/import/yaml_importer.rb +30 -0
- data/lib/squib/layout_parser.rb +155 -138
- data/lib/squib/progress.rb +38 -38
- data/lib/squib/sample_helpers.rb +34 -34
- data/lib/squib/sprues/crop_line.rb +28 -28
- data/lib/squib/sprues/crop_line_dash.rb +35 -35
- data/lib/squib/sprues/invalid_sprue_definition.rb +9 -9
- data/lib/squib/sprues/sprue.rb +208 -206
- data/lib/squib/sprues/sprue_schema.rb +50 -50
- data/lib/squib/version.rb +11 -10
- data/samples/autoscale_font/_autoscale_font.rb +98 -29
- data/samples/backend/_backend.rb +26 -26
- data/samples/basic.rb +19 -19
- data/samples/build_groups/build_groups.rb +36 -36
- data/samples/colors/_colors.rb +44 -44
- data/samples/colors/_gradients.rb +34 -34
- data/samples/colors/_switch_color.rb +33 -33
- data/samples/config/config_text_markup.rb +20 -20
- data/samples/config/custom_config.rb +18 -18
- data/samples/data/_csv.rb +33 -33
- data/samples/data/_excel.rb +55 -55
- data/samples/data/_yaml.rb +12 -12
- data/samples/hello_world.rb +6 -6
- data/samples/images/_cairo_access.rb +39 -39
- data/samples/images/_images.rb +104 -104
- data/samples/images/_more_load_images.rb +102 -102
- data/samples/intro/01_hello.rb +8 -8
- data/samples/intro/02_options.rb +14 -14
- data/samples/intro/03_layout.rb +11 -11
- data/samples/intro/04_arrays.rb +15 -15
- data/samples/intro/05_excel.rb +14 -14
- data/samples/layouts/builtin_layouts.rb +97 -97
- data/samples/layouts/layouts.rb +71 -71
- data/samples/project/src/characters.rb +8 -8
- data/samples/project/src/skills.rb +7 -7
- data/samples/proofs/_tgc_proofs.rb +16 -16
- data/samples/ranges/_ranges.rb +64 -64
- data/samples/saves/_hand.rb +23 -23
- data/samples/saves/_portrait_landscape.rb +23 -23
- data/samples/saves/_save_filenames.rb +28 -24
- data/samples/saves/_save_pdf.rb +29 -29
- data/samples/saves/_saves.rb +52 -51
- data/samples/saves/_showcase.rb +25 -25
- data/samples/shapes/_draw_shapes.rb +60 -60
- data/samples/shapes/_proofs.rb +22 -22
- data/samples/sprues/_advanced_sprues.rb +25 -25
- data/samples/sprues/_builtin_sprues.rb +22 -21
- data/samples/sprues/_fold_sheet.rb +30 -27
- data/samples/sprues/_hex_tiles.rb +15 -15
- data/samples/sprues/_mints.rb +11 -11
- data/samples/sprues/_sprue_example.rb +11 -11
- data/samples/text/_embed_text.rb +128 -128
- data/samples/text/_text.rb +52 -47
- data/samples/text/_text_options.rb +103 -102
- data/samples/text/bug134.rb +14 -14
- data/samples/units/_cells.rb +51 -0
- data/samples/units/_shorthands.rb +48 -0
- data/samples/units/_units.rb +39 -32
- data/squib.gemspec +58 -52
- metadata +177 -91
- data/.travis.yml +0 -17
- data/appveyor.yml +0 -25
- data/lib/squib/api/background.rb +0 -15
- data/lib/squib/api/data.rb +0 -137
- data/lib/squib/api/image.rb +0 -49
- data/lib/squib/api/save.rb +0 -83
- data/lib/squib/api/shapes.rb +0 -124
- data/lib/squib/api/text.rb +0 -25
- data/lib/squib/api/text_embed.rb +0 -71
data/samples/images/_images.rb
CHANGED
@@ -1,104 +1,104 @@
|
|
1
|
-
require 'squib'
|
2
|
-
require 'squib/sample_helpers'
|
3
|
-
|
4
|
-
Squib::Deck.new(width: 1000, height: 3000) do
|
5
|
-
draw_graph_paper width, height
|
6
|
-
|
7
|
-
sample "This a PNG.\nNo scaling is done by default." do |x, y|
|
8
|
-
png file: 'angler-fish.png', x: x, y: y
|
9
|
-
end
|
10
|
-
|
11
|
-
sample 'PNGs can be upscaled, but they will emit an antialias warning (unless you turn it off in the config.yml)' do |x,y|
|
12
|
-
png file: 'angler-fish.png', x: x, y: y, width: 150, height: 150
|
13
|
-
end
|
14
|
-
|
15
|
-
sample 'SVGs can be loaded from a file (left) or from straight XML (right). They can also be scaled to any size.' do |x,y|
|
16
|
-
svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100
|
17
|
-
svg data: File.read('robot-golem.svg'), width: 100, height: 100,
|
18
|
-
x: x + 200, y: y
|
19
|
-
end
|
20
|
-
|
21
|
-
sample 'PNG and SVG can be auto-scaled by one side and setting the other to :scale' do |x,y|
|
22
|
-
svg file: 'robot-golem.svg', x: x, y: y, width: 50, height: :scale
|
23
|
-
svg file: 'robot-golem.svg', x: x + 50, y: y, width: :scale, height: 50
|
24
|
-
|
25
|
-
png file: 'angler-fish.png', x: x + 200, y: y, width: 50, height: :scale
|
26
|
-
png file: 'angler-fish.png', x: x + 250, y: y, width: :scale, height: 50
|
27
|
-
end
|
28
|
-
|
29
|
-
sample 'PNGs can be cropped. To work from sprite sheets, you can set crop coordinates to PNG images. Rounded corners supported too.' do |x,y|
|
30
|
-
png file: 'sprites.png', x: x - 50, y: y - 50 # entire sprite sheet
|
31
|
-
rect x: x - 50, y: y - 50, width: 100, height: 100, # draw the crop line
|
32
|
-
radius: 15, dash: '3 3', stroke_color: 'red', stroke_width: 3
|
33
|
-
text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y - 35
|
34
|
-
png file: 'sprites.png', x: x + 200, y: y - 50, # just the robot golem image
|
35
|
-
crop_x: 0, crop_y: 0, crop_corner_radius: 15,
|
36
|
-
crop_width: 100, crop_height: 100
|
37
|
-
|
38
|
-
png file: 'sprites.png', x: x - 50, y: y + 50 # entire sprite sheet again
|
39
|
-
rect x: x + 14, y: y + 50, width: 65, height: 65, # highlight the crop
|
40
|
-
radius: 25, dash: '3 3', stroke_color: 'red', stroke_width: 3
|
41
|
-
text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y + 50
|
42
|
-
png file: 'sprites.png', x: x + 225, y: y + 50, # just the drakkar ship image, rotated
|
43
|
-
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
|
44
|
-
crop_width: 64, crop_height: 64, angle: Math::PI / 6
|
45
|
-
end
|
46
|
-
|
47
|
-
sample 'SVGs can be cropped too.' do |x,y|
|
48
|
-
svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100,
|
49
|
-
crop_x: 40, crop_y: 0, crop_width: 50, crop_height: 50
|
50
|
-
end
|
51
|
-
|
52
|
-
sample 'Images can be flipped about their center.' do |x,y|
|
53
|
-
png file: 'angler-fish.png', x: x, y: y, flip_vertical: true, flip_horizontal: true
|
54
|
-
svg file: 'robot-golem.svg', x: x + 200, y: y, width: 100, height: 100,
|
55
|
-
flip_horizontal: true
|
56
|
-
end
|
57
|
-
|
58
|
-
sample 'SVG can be limited to rendering to a single object if the SVG ID is set. If you look in this SVG file, the black backdrop has ID #backdrop.' do |x,y|
|
59
|
-
svg file: 'robot-golem.svg', id: 'backdrop', x: x, y: y, width: 100, height: 100
|
60
|
-
end
|
61
|
-
|
62
|
-
sample "The SVG force_id option allows use of an ID only when specified, and render nothing if empty. Useful for multiple icons in one SVG file.\nThis should show nothing." do |x,y|
|
63
|
-
svg file: 'robot-golem.svg', x: x, y: y,
|
64
|
-
force_id: true, id: '' # <-- the important parts
|
65
|
-
end
|
66
|
-
|
67
|
-
sample 'NOTE! If you render a single object in an SVG, its placement is still relative to the SVG document.' do |x,y|
|
68
|
-
svg file: 'offset.svg', x: x, y: y
|
69
|
-
rect x: x, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
|
70
|
-
|
71
|
-
svg file: 'offset.svg', id: 'thing', x: x + 200, y: y, width: 100, height: 100
|
72
|
-
rect x: x + 200, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
|
73
|
-
end
|
74
|
-
|
75
|
-
sample 'PNGs can be blended onto each other with 15 different blending operators. Alpha transparency supported too. See http://cairographics.org/operators' do |x,y|
|
76
|
-
png file: 'ball.png', x: x, y: y
|
77
|
-
png file: 'grit.png', x: x + 20, y: y + 20, blend: :color_burn, alpha: 0.75
|
78
|
-
end
|
79
|
-
|
80
|
-
sample 'Rotation is around the upper-left corner of the image. Unit is radians.' do |x,y|
|
81
|
-
rect x: x, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
|
82
|
-
png x: x, y: y, width: 100, height: 100, angle: Math::PI / 4, file: 'angler-fish.png'
|
83
|
-
|
84
|
-
rect x: x + 250, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
|
85
|
-
svg x: x + 250, y: y, width: 100, height: 100, file: 'robot-golem.svg',
|
86
|
-
angle: Math::PI / 2 - 0.2
|
87
|
-
end
|
88
|
-
|
89
|
-
sample 'SVGs and PNGs can be used as masks for colors instead of being directly rendered.' do |x,y|
|
90
|
-
svg mask: '#00ff00', file: 'glass-heart.svg', x: x - 50, y: y - 50, width: 200, height: 200
|
91
|
-
svg mask: '(0,0)(500,0) #eee@0.0 #111@1.0', file: 'glass-heart.svg', x: x + 150, y: y - 50, width: 200, height: 200
|
92
|
-
end
|
93
|
-
|
94
|
-
sample 'PNG masks are based on the alpha channel. Gradient coordinates are relative to the card.' do |x,y|
|
95
|
-
png file: 'with-alpha.png', x: x - 50, y: y
|
96
|
-
png file: 'with-alpha.png', mask: :magenta, x: x + 50, y: y
|
97
|
-
|
98
|
-
mask = "(#{x+150+75}, #{y+75}, 0)(#{x+150+75}, #{y+75}, 100) #f00@0.0 #000@1.0"
|
99
|
-
png file: 'with-alpha.png', mask: mask, x: x + 150, y: y, width: 150, height: :scale
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
save_png prefix: '_images_'
|
104
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
require 'squib/sample_helpers'
|
3
|
+
|
4
|
+
Squib::Deck.new(width: 1000, height: 3000) do
|
5
|
+
draw_graph_paper width, height
|
6
|
+
|
7
|
+
sample "This a PNG.\nNo scaling is done by default." do |x, y|
|
8
|
+
png file: 'angler-fish.png', x: x, y: y
|
9
|
+
end
|
10
|
+
|
11
|
+
sample 'PNGs can be upscaled, but they will emit an antialias warning (unless you turn it off in the config.yml)' do |x,y|
|
12
|
+
png file: 'angler-fish.png', x: x, y: y, width: 150, height: 150
|
13
|
+
end
|
14
|
+
|
15
|
+
sample 'SVGs can be loaded from a file (left) or from straight XML (right). They can also be scaled to any size.' do |x,y|
|
16
|
+
svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100
|
17
|
+
svg data: File.read('robot-golem.svg'), width: 100, height: 100,
|
18
|
+
x: x + 200, y: y
|
19
|
+
end
|
20
|
+
|
21
|
+
sample 'PNG and SVG can be auto-scaled by one side and setting the other to :scale' do |x,y|
|
22
|
+
svg file: 'robot-golem.svg', x: x, y: y, width: 50, height: :scale
|
23
|
+
svg file: 'robot-golem.svg', x: x + 50, y: y, width: :scale, height: 50
|
24
|
+
|
25
|
+
png file: 'angler-fish.png', x: x + 200, y: y, width: 50, height: :scale
|
26
|
+
png file: 'angler-fish.png', x: x + 250, y: y, width: :scale, height: 50
|
27
|
+
end
|
28
|
+
|
29
|
+
sample 'PNGs can be cropped. To work from sprite sheets, you can set crop coordinates to PNG images. Rounded corners supported too.' do |x,y|
|
30
|
+
png file: 'sprites.png', x: x - 50, y: y - 50 # entire sprite sheet
|
31
|
+
rect x: x - 50, y: y - 50, width: 100, height: 100, # draw the crop line
|
32
|
+
radius: 15, dash: '3 3', stroke_color: 'red', stroke_width: 3
|
33
|
+
text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y - 35
|
34
|
+
png file: 'sprites.png', x: x + 200, y: y - 50, # just the robot golem image
|
35
|
+
crop_x: 0, crop_y: 0, crop_corner_radius: 15,
|
36
|
+
crop_width: 100, crop_height: 100
|
37
|
+
|
38
|
+
png file: 'sprites.png', x: x - 50, y: y + 50 # entire sprite sheet again
|
39
|
+
rect x: x + 14, y: y + 50, width: 65, height: 65, # highlight the crop
|
40
|
+
radius: 25, dash: '3 3', stroke_color: 'red', stroke_width: 3
|
41
|
+
text str: '➜', font: 'Sans Bold 12', x: x + 150, y: y + 50
|
42
|
+
png file: 'sprites.png', x: x + 225, y: y + 50, # just the drakkar ship image, rotated
|
43
|
+
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
|
44
|
+
crop_width: 64, crop_height: 64, angle: Math::PI / 6
|
45
|
+
end
|
46
|
+
|
47
|
+
sample 'SVGs can be cropped too.' do |x,y|
|
48
|
+
svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100,
|
49
|
+
crop_x: 40, crop_y: 0, crop_width: 50, crop_height: 50
|
50
|
+
end
|
51
|
+
|
52
|
+
sample 'Images can be flipped about their center.' do |x,y|
|
53
|
+
png file: 'angler-fish.png', x: x, y: y, flip_vertical: true, flip_horizontal: true
|
54
|
+
svg file: 'robot-golem.svg', x: x + 200, y: y, width: 100, height: 100,
|
55
|
+
flip_horizontal: true
|
56
|
+
end
|
57
|
+
|
58
|
+
sample 'SVG can be limited to rendering to a single object if the SVG ID is set. If you look in this SVG file, the black backdrop has ID #backdrop.' do |x,y|
|
59
|
+
svg file: 'robot-golem.svg', id: 'backdrop', x: x, y: y, width: 100, height: 100
|
60
|
+
end
|
61
|
+
|
62
|
+
sample "The SVG force_id option allows use of an ID only when specified, and render nothing if empty. Useful for multiple icons in one SVG file.\nThis should show nothing." do |x,y|
|
63
|
+
svg file: 'robot-golem.svg', x: x, y: y,
|
64
|
+
force_id: true, id: '' # <-- the important parts
|
65
|
+
end
|
66
|
+
|
67
|
+
sample 'NOTE! If you render a single object in an SVG, its placement is still relative to the SVG document.' do |x,y|
|
68
|
+
svg file: 'offset.svg', x: x, y: y
|
69
|
+
rect x: x, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
|
70
|
+
|
71
|
+
svg file: 'offset.svg', id: 'thing', x: x + 200, y: y, width: 100, height: 100
|
72
|
+
rect x: x + 200, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3
|
73
|
+
end
|
74
|
+
|
75
|
+
sample 'PNGs can be blended onto each other with 15 different blending operators. Alpha transparency supported too. See http://cairographics.org/operators' do |x,y|
|
76
|
+
png file: 'ball.png', x: x, y: y
|
77
|
+
png file: 'grit.png', x: x + 20, y: y + 20, blend: :color_burn, alpha: 0.75
|
78
|
+
end
|
79
|
+
|
80
|
+
sample 'Rotation is around the upper-left corner of the image. Unit is radians.' do |x,y|
|
81
|
+
rect x: x, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
|
82
|
+
png x: x, y: y, width: 100, height: 100, angle: Math::PI / 4, file: 'angler-fish.png'
|
83
|
+
|
84
|
+
rect x: x + 250, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red
|
85
|
+
svg x: x + 250, y: y, width: 100, height: 100, file: 'robot-golem.svg',
|
86
|
+
angle: Math::PI / 2 - 0.2
|
87
|
+
end
|
88
|
+
|
89
|
+
sample 'SVGs and PNGs can be used as masks for colors instead of being directly rendered.' do |x,y|
|
90
|
+
svg mask: '#00ff00', file: 'glass-heart.svg', x: x - 50, y: y - 50, width: 200, height: 200
|
91
|
+
svg mask: '(0,0)(500,0) #eee@0.0 #111@1.0', file: 'glass-heart.svg', x: x + 150, y: y - 50, width: 200, height: 200
|
92
|
+
end
|
93
|
+
|
94
|
+
sample 'PNG masks are based on the alpha channel. Gradient coordinates are relative to the card.' do |x,y|
|
95
|
+
png file: 'with-alpha.png', x: x - 50, y: y
|
96
|
+
png file: 'with-alpha.png', mask: :magenta, x: x + 50, y: y
|
97
|
+
|
98
|
+
mask = "(#{x+150+75}, #{y+75}, 0)(#{x+150+75}, #{y+75}, 100) #f00@0.0 #000@1.0"
|
99
|
+
png file: 'with-alpha.png', mask: mask, x: x + 150, y: y, width: 150, height: :scale
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
save_png prefix: '_images_'
|
104
|
+
end
|
@@ -1,102 +1,102 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 1, config: 'load_images_config.yml') do
|
4
|
-
background color: '#0b7c8e'
|
5
|
-
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
6
|
-
|
7
|
-
png file: 'shiny-purse.png', x: 620, y: 75 # no scaling is done by default
|
8
|
-
svg file: 'spanner.svg', x: 620, y: 218
|
9
|
-
|
10
|
-
# Can be scaled if width and height are set
|
11
|
-
svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
|
12
|
-
png file: 'shiny-purse.png', x: 305, y: 50, width: 250, height: 250
|
13
|
-
# ...but PNGs will warn if it's an upscale, unless you disable them in config.yml
|
14
|
-
|
15
|
-
# Can be scaled using just width or height, if one of them is set to :scale
|
16
|
-
svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale
|
17
|
-
svg file: 'spanner.svg', x: 200, y: 390, width: :scale, height: 35
|
18
|
-
png file: 'shiny-purse.png', x: 240, y: 350, width: 35, height: :scale
|
19
|
-
png file: 'shiny-purse.png', x: 240, y: 390, width: :scale, height: 35
|
20
|
-
|
21
|
-
# You can also crop the loaded images, so you can work from a sprite sheet
|
22
|
-
png file: 'sprites.png', x: 300, y: 350 # entire sprite sheet
|
23
|
-
png file: 'sprites.png', x: 300, y: 425, # just the robot golem image
|
24
|
-
crop_x: 0, crop_y: 0, crop_corner_radius: 10,
|
25
|
-
crop_width: 64, crop_height: 64
|
26
|
-
png file: 'sprites.png', x: 400, y: 425, # just the drakkar ship image
|
27
|
-
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
|
28
|
-
crop_width: 64, crop_height: 64
|
29
|
-
png file: 'sprites.png', x: 500, y: 415, # just the drakkar ship image, rotated
|
30
|
-
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
|
31
|
-
crop_width: 64, crop_height: 64, angle: Math::PI / 6
|
32
|
-
|
33
|
-
# Cropping also works on SVGs too
|
34
|
-
svg file: 'spanner.svg', x: 300, y: 500, width: 64, height: 64,
|
35
|
-
crop_x: 32, crop_y: 32, crop_width: 32, crop_height:32
|
36
|
-
|
37
|
-
# We can flip our images too
|
38
|
-
png file: 'sprites.png', x: 300, y: 535, flip_vertical: true, flip_horizontal: true
|
39
|
-
svg file: 'spanner.svg', x: 300, y: 615, width: 64, height: 64,
|
40
|
-
flip_vertical: true, flip_horizontal: true
|
41
|
-
|
42
|
-
# We can also limit our rendering to a single object, if the SVG ID is set
|
43
|
-
svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
|
44
|
-
# Squib prepends a #-sign if one is not specified
|
45
|
-
svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
|
46
|
-
|
47
|
-
# We can also load SVGs as a string of XML
|
48
|
-
svg data: File.read('spanner.svg'), x: 50, y: 600, width: 75, height: 75
|
49
|
-
|
50
|
-
# The svg data field works nicely with modifying the SVG XML on-the-fly.
|
51
|
-
# To run this one, do `gem install game_icons` and uncomment the following
|
52
|
-
#
|
53
|
-
# require 'game_icons'
|
54
|
-
# svg data: GameIcons.get('angler-fish').recolor(fg: '#ccc', bg: '#333').string,
|
55
|
-
# x: 150, y: 600, width: 75, height: 75
|
56
|
-
#
|
57
|
-
# More examples at https://github.com/andymeneely/game_icons
|
58
|
-
# (or `gem install game_icons`) to get & manipulate art from game-icons.net
|
59
|
-
# Nokogiri (already included in Squib) is also great for XML manipulation.
|
60
|
-
|
61
|
-
# WARNING! If you choose to use the SVG ID, the x-y coordinates are still
|
62
|
-
# relative to the SVG page. See this example in an SVG editor
|
63
|
-
svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
|
64
|
-
|
65
|
-
# Over 15 different blending operators are supported.
|
66
|
-
# See http://cairographics.org/operators
|
67
|
-
# Alpha transparency too
|
68
|
-
png file: 'ball.png', x: 50, y: 700
|
69
|
-
png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
|
70
|
-
|
71
|
-
# Images can be rotated around their upper-left corner
|
72
|
-
png file: 'shiny-purse.png', x: 300, y: 700, angle: 0.0 # default (no rotate)
|
73
|
-
png file: 'shiny-purse.png', x: 300, y: 800, angle: Math::PI / 4
|
74
|
-
svg file: 'spanner.svg', x: 300, y: 900, angle: Math::PI / 2 - 0.1
|
75
|
-
|
76
|
-
# Images can also be used as masks instead of being directly painted.
|
77
|
-
# This is particularly useful for switching directly over to black-and-white for printing
|
78
|
-
# Or, if you want the same image to be used but with different colors/gradients
|
79
|
-
svg mask: '#00ff00',
|
80
|
-
file: 'glass-heart.svg',
|
81
|
-
x: 500, y: 600, width: 200, height: 200
|
82
|
-
svg mask: '(0,0)(0,500) #ccc@0.0 #333@1.0',
|
83
|
-
file: 'glass-heart.svg',
|
84
|
-
x: 500, y: 800, width: 200, height: 200
|
85
|
-
|
86
|
-
# Masks are based on the alpha channel, so this is just a magenta square
|
87
|
-
png mask: :magenta, file: 'shiny-purse.png',
|
88
|
-
x: 650, y: 950
|
89
|
-
|
90
|
-
# Note that this method does nothing, even though it would normally fill up
|
91
|
-
# the card. force_id: true looks to the id field to be non-empty to render.
|
92
|
-
# This is useful if you have multiple different icons in one SVG file,
|
93
|
-
# but sometimes want to use none.
|
94
|
-
# e.g. id: [:attack, :defend, nil]
|
95
|
-
svg file: 'spanner.svg', width: :deck, height: :deck,
|
96
|
-
force_id: true, id: nil # <-- the important part
|
97
|
-
|
98
|
-
# Squib can handle incorrectly formatted svg files
|
99
|
-
svg file: 'bad-svg.svg'
|
100
|
-
|
101
|
-
save prefix: 'load_images_', format: :png
|
102
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new(width: 825, height: 1125, cards: 1, config: 'load_images_config.yml') do
|
4
|
+
background color: '#0b7c8e'
|
5
|
+
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
6
|
+
|
7
|
+
png file: 'shiny-purse.png', x: 620, y: 75 # no scaling is done by default
|
8
|
+
svg file: 'spanner.svg', x: 620, y: 218
|
9
|
+
|
10
|
+
# Can be scaled if width and height are set
|
11
|
+
svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
|
12
|
+
png file: 'shiny-purse.png', x: 305, y: 50, width: 250, height: 250
|
13
|
+
# ...but PNGs will warn if it's an upscale, unless you disable them in config.yml
|
14
|
+
|
15
|
+
# Can be scaled using just width or height, if one of them is set to :scale
|
16
|
+
svg file: 'spanner.svg', x: 200, y: 350, width: 35, height: :scale
|
17
|
+
svg file: 'spanner.svg', x: 200, y: 390, width: :scale, height: 35
|
18
|
+
png file: 'shiny-purse.png', x: 240, y: 350, width: 35, height: :scale
|
19
|
+
png file: 'shiny-purse.png', x: 240, y: 390, width: :scale, height: 35
|
20
|
+
|
21
|
+
# You can also crop the loaded images, so you can work from a sprite sheet
|
22
|
+
png file: 'sprites.png', x: 300, y: 350 # entire sprite sheet
|
23
|
+
png file: 'sprites.png', x: 300, y: 425, # just the robot golem image
|
24
|
+
crop_x: 0, crop_y: 0, crop_corner_radius: 10,
|
25
|
+
crop_width: 64, crop_height: 64
|
26
|
+
png file: 'sprites.png', x: 400, y: 425, # just the drakkar ship image
|
27
|
+
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
|
28
|
+
crop_width: 64, crop_height: 64
|
29
|
+
png file: 'sprites.png', x: 500, y: 415, # just the drakkar ship image, rotated
|
30
|
+
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25,
|
31
|
+
crop_width: 64, crop_height: 64, angle: Math::PI / 6
|
32
|
+
|
33
|
+
# Cropping also works on SVGs too
|
34
|
+
svg file: 'spanner.svg', x: 300, y: 500, width: 64, height: 64,
|
35
|
+
crop_x: 32, crop_y: 32, crop_width: 32, crop_height:32
|
36
|
+
|
37
|
+
# We can flip our images too
|
38
|
+
png file: 'sprites.png', x: 300, y: 535, flip_vertical: true, flip_horizontal: true
|
39
|
+
svg file: 'spanner.svg', x: 300, y: 615, width: 64, height: 64,
|
40
|
+
flip_vertical: true, flip_horizontal: true
|
41
|
+
|
42
|
+
# We can also limit our rendering to a single object, if the SVG ID is set
|
43
|
+
svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
|
44
|
+
# Squib prepends a #-sign if one is not specified
|
45
|
+
svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
|
46
|
+
|
47
|
+
# We can also load SVGs as a string of XML
|
48
|
+
svg data: File.read('spanner.svg'), x: 50, y: 600, width: 75, height: 75
|
49
|
+
|
50
|
+
# The svg data field works nicely with modifying the SVG XML on-the-fly.
|
51
|
+
# To run this one, do `gem install game_icons` and uncomment the following
|
52
|
+
#
|
53
|
+
# require 'game_icons'
|
54
|
+
# svg data: GameIcons.get('angler-fish').recolor(fg: '#ccc', bg: '#333').string,
|
55
|
+
# x: 150, y: 600, width: 75, height: 75
|
56
|
+
#
|
57
|
+
# More examples at https://github.com/andymeneely/game_icons
|
58
|
+
# (or `gem install game_icons`) to get & manipulate art from game-icons.net
|
59
|
+
# Nokogiri (already included in Squib) is also great for XML manipulation.
|
60
|
+
|
61
|
+
# WARNING! If you choose to use the SVG ID, the x-y coordinates are still
|
62
|
+
# relative to the SVG page. See this example in an SVG editor
|
63
|
+
svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
|
64
|
+
|
65
|
+
# Over 15 different blending operators are supported.
|
66
|
+
# See http://cairographics.org/operators
|
67
|
+
# Alpha transparency too
|
68
|
+
png file: 'ball.png', x: 50, y: 700
|
69
|
+
png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
|
70
|
+
|
71
|
+
# Images can be rotated around their upper-left corner
|
72
|
+
png file: 'shiny-purse.png', x: 300, y: 700, angle: 0.0 # default (no rotate)
|
73
|
+
png file: 'shiny-purse.png', x: 300, y: 800, angle: Math::PI / 4
|
74
|
+
svg file: 'spanner.svg', x: 300, y: 900, angle: Math::PI / 2 - 0.1
|
75
|
+
|
76
|
+
# Images can also be used as masks instead of being directly painted.
|
77
|
+
# This is particularly useful for switching directly over to black-and-white for printing
|
78
|
+
# Or, if you want the same image to be used but with different colors/gradients
|
79
|
+
svg mask: '#00ff00',
|
80
|
+
file: 'glass-heart.svg',
|
81
|
+
x: 500, y: 600, width: 200, height: 200
|
82
|
+
svg mask: '(0,0)(0,500) #ccc@0.0 #333@1.0',
|
83
|
+
file: 'glass-heart.svg',
|
84
|
+
x: 500, y: 800, width: 200, height: 200
|
85
|
+
|
86
|
+
# Masks are based on the alpha channel, so this is just a magenta square
|
87
|
+
png mask: :magenta, file: 'shiny-purse.png',
|
88
|
+
x: 650, y: 950
|
89
|
+
|
90
|
+
# Note that this method does nothing, even though it would normally fill up
|
91
|
+
# the card. force_id: true looks to the id field to be non-empty to render.
|
92
|
+
# This is useful if you have multiple different icons in one SVG file,
|
93
|
+
# but sometimes want to use none.
|
94
|
+
# e.g. id: [:attack, :defend, nil]
|
95
|
+
svg file: 'spanner.svg', width: :deck, height: :deck,
|
96
|
+
force_id: true, id: nil # <-- the important part
|
97
|
+
|
98
|
+
# Squib can handle incorrectly formatted svg files
|
99
|
+
svg file: 'bad-svg.svg'
|
100
|
+
|
101
|
+
save prefix: 'load_images_', format: :png
|
102
|
+
end
|
data/samples/intro/01_hello.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new cards: 1 do
|
4
|
-
background color: 'pink'
|
5
|
-
rect
|
6
|
-
text str: 'Draw two cards.'
|
7
|
-
save_png prefix: 'part1_'
|
8
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new cards: 1 do
|
4
|
+
background color: 'pink'
|
5
|
+
rect
|
6
|
+
text str: 'Draw two cards.'
|
7
|
+
save_png prefix: 'part1_'
|
8
|
+
end
|
data/samples/intro/02_options.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new cards: 1 do
|
4
|
-
background color: '#252322'
|
5
|
-
rect fill_color: '#0B3736',
|
6
|
-
x: 38, y: 38, width: 750, height: 1050, radius: 38
|
7
|
-
text str: 'Robot Golem', font: 'True Crimes, Sans 24',
|
8
|
-
align: :center, x: 75, width: :deck, color: '#DFDFE1', y: 90
|
9
|
-
svg file: 'auto-repair.svg', x: 75, y: 75, width: 100, height: :scale
|
10
|
-
svg file: 'robot-golem.svg', x: 75, y: 300, width: 675, height: :scale
|
11
|
-
text str: 'Draw two cards', font: 'Serif 12',
|
12
|
-
align: :center, width: :deck, color: '#DFDFE1', y: 1000
|
13
|
-
save_png prefix: 'part2_'
|
14
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new cards: 1 do
|
4
|
+
background color: '#252322'
|
5
|
+
rect fill_color: '#0B3736',
|
6
|
+
x: 38, y: 38, width: 750, height: 1050, radius: 38
|
7
|
+
text str: 'Robot Golem', font: 'True Crimes, Sans 24',
|
8
|
+
align: :center, x: 75, width: :deck, color: '#DFDFE1', y: 90
|
9
|
+
svg file: 'auto-repair.svg', x: 75, y: 75, width: 100, height: :scale
|
10
|
+
svg file: 'robot-golem.svg', x: 75, y: 300, width: 675, height: :scale
|
11
|
+
text str: 'Draw two cards', font: 'Serif 12',
|
12
|
+
align: :center, width: :deck, color: '#DFDFE1', y: 1000
|
13
|
+
save_png prefix: 'part2_'
|
14
|
+
end
|