15 changed files with 258 additions and 25 deletions
@ -0,0 +1,39 @@ |
|||||||
|
require_relative 'color_validator' |
||||||
|
|
||||||
|
module Squib::Args |
||||||
|
module_function def extract_drop_shadow(opts, deck) |
||||||
|
DropShadow.new(deck.custom_colors).extract! opts, deck |
||||||
|
end |
||||||
|
|
||||||
|
class DropShadow |
||||||
|
include ArgLoader |
||||||
|
include ColorValidator |
||||||
|
|
||||||
|
def initialize(custom_colors) |
||||||
|
@custom_colors = custom_colors |
||||||
|
end |
||||||
|
|
||||||
|
def self.parameters |
||||||
|
{ |
||||||
|
shadow_color: :black, |
||||||
|
shadow_offset_x: 3, |
||||||
|
shadow_offset_y: 3, |
||||||
|
shadow_radius: nil, |
||||||
|
shadow_trim: 0, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
def self.expanding_parameters |
||||||
|
self.parameters.keys # all of them |
||||||
|
end |
||||||
|
|
||||||
|
def self.params_with_units |
||||||
|
[:shadow_offset_x, :shadow_offset_y, :shadow_radius, :shadow_trim] |
||||||
|
end |
||||||
|
|
||||||
|
def validate_shadow_color(arg, _i) |
||||||
|
colorify(arg, @custom_colors) |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
require 'squib' |
||||||
|
|
||||||
|
orig = Cairo::ImageSurface.new(100,100) |
||||||
|
orig_cc = Cairo::Context.new(orig) |
||||||
|
orig_cc.circle(50,50, 30) |
||||||
|
orig_cc.set_source_color(:red) |
||||||
|
orig_cc.fill |
||||||
|
|
||||||
|
orig.write_to_png '_output/blend_orig.png' |
||||||
|
|
||||||
|
new_img = Cairo::ImageSurface.new(120, 120) |
||||||
|
new_cc = Cairo::Context.new(new_img) |
||||||
|
new_cc.set_source_color(:black) |
||||||
|
new_cc.rectangle(0,0,120,120) |
||||||
|
new_cc.fill |
||||||
|
new_cc.set_source orig |
||||||
|
new_cc.operator = :dest_in |
||||||
|
new_cc.paint |
||||||
|
|
||||||
|
new_img.write_to_png '_output/blend_new.png' |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
require_relative '../../lib/squib' |
||||||
|
# require 'squib' |
||||||
|
# The save_png method supports drop shadows on the final save |
||||||
|
# This is useful for when you want to generate images for your rulebook |
||||||
|
|
||||||
|
Squib::Deck.new(width: 100, height: 150) do |
||||||
|
background color: '#abc' |
||||||
|
svg file: '../spanner.svg', |
||||||
|
x: 'middle - 25', y: 'middle - 25', |
||||||
|
width: 50, height: 50 |
||||||
|
|
||||||
|
# Shadows off by default, i.e. shadow_radius is nil |
||||||
|
# So our final dimensions are 100 - 2*15 and 150-2*15 |
||||||
|
save_png prefix: 'no_shadow_', trim: 15, trim_radius: 15 |
||||||
|
|
||||||
|
# Here's a nice-looking drop shadow |
||||||
|
# Defaults are designed to be generally good, so I recommend just |
||||||
|
# trying out a shadow_radius of 3 to 10 and see how it looks first |
||||||
|
save_png prefix: 'with_shadow_', trim: 15, trim_radius: 15, |
||||||
|
shadow_radius: 8, |
||||||
|
shadow_offset_x: 3, shadow_offset_y: 3, # about r / 2.5 looks good |
||||||
|
shadow_trim: 2.5, # about r/ 3 looks good |
||||||
|
shadow_color: '#101010aa' #tip: start the shadow color kinda transparent |
||||||
|
|
||||||
|
# Don't want a blur? Use a radius of 0 |
||||||
|
save_png prefix: 'no_blur_', trim: 15, trim_radius: 15, |
||||||
|
shadow_radius: 0 |
||||||
|
|
||||||
|
# Ok this next stop is crazytown, but it does give you ultimate control |
||||||
|
# Remember that all Squib colors can also be gradients. |
||||||
|
# They can be clunky but they do work here. |
||||||
|
# - x,y's are centered in the card itself |
||||||
|
# - stops go from fully empty to fully black |
||||||
|
# - we need to still turn on radius to get the effect |
||||||
|
# - but, this makes the upper-left corner not have a glowing effect and |
||||||
|
# have a harder edge, which (to my eye at least) feels more realistic |
||||||
|
# since the card would obscure the upper-left shadow at that angle |
||||||
|
# - this also allows you have a larger, softer blur without making it look |
||||||
|
# like it's glowing |
||||||
|
# |
||||||
|
# Oh just because it's easier to write we can use a ruby heredoc |
||||||
|
save_png prefix: 'gradient_blur_', trim: 15, trim_radius: 15, |
||||||
|
shadow_radius: 10, |
||||||
|
shadow_color: <<~EOS |
||||||
|
(25,25) |
||||||
|
(175,175) |
||||||
|
#0000@0.0 |
||||||
|
#000f@1.0 |
||||||
|
EOS |
||||||
|
|
||||||
|
# This one looks weird I know but it's for regression testing |
||||||
|
save_png prefix: 'with_shadow_test_', |
||||||
|
trim: 15, trim_radius: 15, rotate: :clockwise, |
||||||
|
shadow_offset_x: 5, shadow_offset_y: 25, shadow_radius: 10, |
||||||
|
shadow_trim: 10, |
||||||
|
shadow_color: '#123' |
||||||
|
end |
||||||
|
|
||||||
|
Squib::Deck.new(width:50, height: 50) do |
||||||
|
|
||||||
|
# What if we had a transparent card but just some shapes? |
||||||
|
# Like chits or something |
||||||
|
|
||||||
|
# background defaults to fully transparent here |
||||||
|
|
||||||
|
# star x: 50, y: 50, inner_radius: 15, outer_radius: 35, |
||||||
|
# fill_color: :red, stroke_color: :red |
||||||
|
|
||||||
|
png file: 'doodle.png' |
||||||
|
|
||||||
|
# save_png prefix: 'no_bg_shadow_', shadow_radius: 8, shadow_offset_x: 3, shadow_offset_y: 3 |
||||||
|
save_png prefix: 'transparent_bg_shadow_', |
||||||
|
shadow_radius: 2, |
||||||
|
shadow_offset_x: 2, shadow_offset_y: 2, |
||||||
|
shadow_color: :black |
||||||
|
|
||||||
|
end |
||||||
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
Loading…
Reference in new issue