Drawing a square with svg

November 18, 2024 · View on GitHub

Here is the codes:

<svg width="400" height="110">
  <rect width="100" height="100" style="fill:rgb(255,255,30,0.0);stroke-width:1;stroke:rgb(255,128,0)" />
</svg>

Is:

  • stroke-width e.g. 1, 2, 10%.
  • stroke (color) e.g. rgb(255,127,63), green

Stroke Example (also a circle example)

Can define a stroke using another element.

<svg width="200" height="200">
  <circle cx="100" cy="100" r="97" fill="none"
      stroke="url(#myGradient)" />
  <defs>
    <linearGradient id="myGradient">
    <stop offset="0%"   stop-color="green" />
    <stop offset="100%" stop-color="white" />
    </linearGradient>
  </defs>
</svg>

A few svg path commands

(in the following rel. means relative and abs. means absolute.

LetterMeaningSampleParamsNote
MMove toM 10 30(X,Y)+set current point to abs. (10,30)
mmove deltam 1 2(dx,dy)+change current point by rel. (1,2)
LLine toL 10 20(dx,dy)+line from current point, to rel. (10,20)
L 10 20 30 40(dx,dy)+line from current point to rel. (10,20) and line from there to rel. (30,40)
HHoriz Line toH 10x+horiz line from current point to abs. x of 10
hHoriz Line deltah 10dx+horiz line from current point to rel. x of x + 10
h -10dx+horiz line from current point to rel. x of x - 10
VVert Line toV 10y+vertical from current point to y of 10
vVert Line deltav 10dy+vertical from current point to rel. y of y + 10
v -10dy+vertical from current point to rel. y of y - 10
CCubic BézierC 30,90 25,10 50,10(x1,y1, x2,y2, x,y)+from current point to end point x,y with control points at x1,y1 and x2,y2
C 30,90 25,10 50,10 10,25 90,30 10,50(x1,y1, x2,y2, x,y)+subsequent triplets of pairs continue the curve
crelative Cubic BézierC 30,90 25,10 50,10(dx1,dy1, dx2,dy2, dx,dy)+from current point to relative end point x,y with relative control points at dx1,dy1 and dx2,dy2
CCubic BézierC 30,90 25,10 50,10(x1,y1, x2,y2, x,y)+from current point to end point x,y with control points at x1,y1 and x2,y2
C 30,90 25,10 50,10 10,25 90,30 10,50(x1,y1, x2,y2, x,y)+subsequent triplets of pairs continue the curve
SSmooth Cubic BézierS 20,50 80,110(x2, y2, x, y)+from current point to end point x,y with end control point x2, y2 and start control point of previous control point or current point if previous curve wasn't a cubic bézier
QQuadratic Bézier
qRelative Quad Béz
TSmooth Quad Béz
tRealitve smooth quad Béz
AArc curve
aRelative Arc curve
ZClose path

(Some ideas for a NimbleText logo redesign.)

On Dark Mode

On Light Mode

Here's a squiggly one

Also consider applying some rounding -- or animating some rounding like this example at stackoverflow









nt.svg

svg

nt.svg

nt.svg