Calculating SVG Gradient Coordinates for Angled Repeating Lines -
i'm trying generate parallelogram in svg repeating lines along same angle left , right sides of polygon. this:
i got repeating gradient work, can't angle of lines right. they're skewed angle of bounding parallelogram:
i know can manipulate angle based on (x1, y1) / (x2, y2) attributes of gradient, playing numbers isn't doing me. how can calculate values use these attributes given known angle?
here's svg code have right now:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 1680 550" preserveaspectratio="xmidymin"> <defs> <lineargradient id="stripedgradient" spreadmethod="repeat" x1="0%" x2="1%" y1="0%" y2="1%"> <stop stop-color="yellow" offset="0%" /> <stop stop-color="yellow" offset="15%" /> <stop stop-color="transparent" offset="15%" /> <stop stop-color="transparent" offset="100%" /> </lineargradient> </defs> <polygon fill="url(#stripedgradient)" points="0 550, 415 145, 610 145, 195 550" /> </svg>
this angle works out under 45deg (44.301...), value change @ discretion of designer, so...
(i'm new svg, in knew existed, had never written inline svg hand until today.)
one simple approach define gradient horizontal stripe. if use gradientunits="userspaceonuse"
, can use gradienttransform
set angle.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 750 550" preserveaspectratio="xmidymin"> <defs> <lineargradient id="stripedgradient" spreadmethod="repeat" gradientunits="userspaceonuse" x1="0" y1="0" x2="0" y2="20" gradienttransform="rotate(-44.301)"> <stop stop-color="red" offset="0%" /> <stop stop-color="red" offset="15%" /> <stop stop-color="transparent" offset="15%" /> <stop stop-color="transparent" offset="100%" /> </lineargradient> </defs> <polygon fill="url(#stripedgradient)" points="0 550, 415 145, 610 145, 195 550" /> </svg>
Comments
Post a Comment