Last active
April 12, 2016 01:10
-
-
Save andymeneely/00ba7eb0aa1d82140503 to your computer and use it in GitHub Desktop.
Squib sample: images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'squib' | |
require 'squib/sample_helpers' | |
Squib::Deck.new(width: 1000, height: 3000) do | |
draw_graph_paper width, height | |
sample "This a PNG.\nNo scaling is done by default." do |x, y| | |
png file: 'angler-fish.png', x: x, y: y | |
end | |
sample 'PNGs can be upscaled, but they will emit an antialias warning (unless you turn it off in the config.yml)' do |x,y| | |
png file: 'angler-fish.png', x: x, y: y, width: 150, height: 150 | |
end | |
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| | |
svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100 | |
svg data: File.read('robot-golem.svg'), width: 100, height: 100, | |
x: x + 200, y: y | |
end | |
sample 'PNG and SVG can be auto-scaled by one side and setting the other to :scale' do |x,y| | |
svg file: 'robot-golem.svg', x: x, y: y, width: 50, height: :scale | |
svg file: 'robot-golem.svg', x: x + 50, y: y, width: :scale, height: 50 | |
png file: 'angler-fish.png', x: x + 200, y: y, width: 50, height: :scale | |
png file: 'angler-fish.png', x: x + 250, y: y, width: :scale, height: 50 | |
end | |
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| | |
png file: 'sprites.png', x: x - 50, y: y - 50 # entire sprite sheet | |
rect x: x - 50, y: y - 50, width: 100, height: 100, # draw the crop line | |
radius: 15, dash: '3 3', stroke_color: 'red', stroke_width: 3 | |
text str: '➜', font: 'Sans Bold 36', x: x + 150, y: y - 35 | |
png file: 'sprites.png', x: x + 200, y: y - 50, # just the robot golem image | |
crop_x: 0, crop_y: 0, crop_corner_radius: 15, | |
crop_width: 100, crop_height: 100 | |
png file: 'sprites.png', x: x - 50, y: y + 50 # entire sprite sheet again | |
rect x: x + 14, y: y + 50, width: 65, height: 65, # highlight the crop | |
radius: 25, dash: '3 3', stroke_color: 'red', stroke_width: 3 | |
text str: '➜', font: 'Sans Bold 36', x: x + 150, y: y + 50 | |
png file: 'sprites.png', x: x + 225, y: y + 50, # just the drakkar ship image, rotated | |
crop_x: 64, crop_y: 0, crop_corner_x_radius: 25, crop_corner_y_radius: 25, | |
crop_width: 64, crop_height: 64, angle: Math::PI / 6 | |
end | |
sample 'SVGs can be cropped too.' do |x,y| | |
svg file: 'robot-golem.svg', x: x, y: y, width: 100, height: 100, | |
crop_x: 40, crop_y: 0, crop_width: 50, crop_height: 50 | |
end | |
sample 'Images can be flipped about their center.' do |x,y| | |
png file: 'angler-fish.png', x: x, y: y, flip_vertical: true, flip_horizontal: true | |
svg file: 'robot-golem.svg', x: x + 200, y: y, width: 100, height: 100, | |
flip_horizontal: true | |
end | |
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| | |
svg file: 'robot-golem.svg', id: 'backdrop', x: x, y: y, width: 100, height: 100 | |
end | |
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| | |
svg file: 'robot-golem.svg', x: x, y: y, | |
force_id: true, id: '' # <-- the important parts | |
end | |
sample 'NOTE! If you render a single object in an SVG, its placement is still relative to the SVG document.' do |x,y| | |
svg file: 'offset.svg', x: x, y: y | |
rect x: x, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3 | |
svg file: 'offset.svg', id: 'thing', x: x + 200, y: y, width: 100, height: 100 | |
rect x: x + 200, y: y, width: 100, height: 100, dash: '3 1', stroke_color: 'red', stroke_width: 3 | |
end | |
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| | |
png file: 'ball.png', x: x, y: y | |
png file: 'grit.png', x: x + 20, y: y + 20, blend: :color_burn, alpha: 0.75 | |
end | |
sample 'Rotation is around the upper-left corner of the image. Unit is radians.' do |x,y| | |
rect x: x, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red | |
png x: x, y: y, width: 100, height: 100, angle: Math::PI / 4, file: 'angler-fish.png' | |
rect x: x + 250, y: y, width: 100, height: 100, stroke_width: 3, dash: '3 3', stroke_color: :red | |
svg x: x + 250, y: y, width: 100, height: 100, file: 'robot-golem.svg', | |
angle: Math::PI / 2 - 0.2 | |
end | |
sample 'SVGs and PNGs can be used as masks for colors instead of being directly rendered.' do |x,y| | |
svg mask: '#00ff00', file: 'glass-heart.svg', x: x - 50, y: y - 50, width: 200, height: 200 | |
svg mask: '(0,0)(0,500) #ccc@0.0 #333@1.0', file: 'glass-heart.svg', x: x + 150, y: y - 50, width: 200, height: 200 | |
end | |
sample 'PNG masks are based on the alpha channel, so this is just a magenta square with rounded corners.' do |x,y| | |
png file: 'angler-fish.png', mask: :magenta, x: x, y: y | |
end | |
save_png prefix: '_images_', dir: '.' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<!-- Created with Inkscape (http://www.inkscape.org/) --> | |
<svg | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:cc="http://creativecommons.org/ns#" | |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:svg="http://www.w3.org/2000/svg" | |
xmlns="http://www.w3.org/2000/svg" | |
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
width="100" | |
height="100" | |
id="svg2" | |
version="1.1" | |
inkscape:version="0.91 r13725" | |
sodipodi:docname="offset.svg"> | |
<defs | |
id="defs4" /> | |
<sodipodi:namedview | |
id="base" | |
pagecolor="#ffffff" | |
bordercolor="#666666" | |
borderopacity="1.0" | |
inkscape:pageopacity="0.0" | |
inkscape:pageshadow="2" | |
inkscape:zoom="6.1011724" | |
inkscape:cx="73.572884" | |
inkscape:cy="47.134619" | |
inkscape:document-units="px" | |
inkscape:current-layer="layer1" | |
showgrid="false" | |
inkscape:window-width="1680" | |
inkscape:window-height="988" | |
inkscape:window-x="1432" | |
inkscape:window-y="109" | |
inkscape:window-maximized="1" | |
fit-margin-top="0" | |
fit-margin-left="0" | |
fit-margin-right="0" | |
fit-margin-bottom="0" /> | |
<metadata | |
id="metadata7"> | |
<rdf:RDF> | |
<cc:Work | |
rdf:about=""> | |
<dc:format>image/svg+xml</dc:format> | |
<dc:type | |
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> | |
<dc:title></dc:title> | |
</cc:Work> | |
</rdf:RDF> | |
</metadata> | |
<g | |
inkscape:label="Layer 1" | |
inkscape:groupmode="layer" | |
id="layer1" | |
transform="translate(5.1573995,-950.1002)"> | |
<circle | |
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.12493663px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
id="thing" | |
inkscape:label="thing" | |
cx="86.79924" | |
cy="1041.9883" | |
r="7.4213605" /> | |
<circle | |
style="opacity:1;fill:#999999;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="path4142" | |
cx="17.988642" | |
cy="973.59332" | |
r="20.5236" /> | |
<circle | |
cy="1004.2076" | |
cx="45.866539" | |
id="circle4144" | |
style="opacity:1;fill:#666666;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
r="17.274031" /> | |
<circle | |
r="12.228644" | |
style="opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="circle4146" | |
cx="69.554207" | |
cy="1027.0402" /> | |
</g> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment