03-24-2025, 06:42 PM
(This post was last modified: 03-24-2025, 06:44 PM by James D Jarvis.)
Got to work some more with SVG graphics. I suppose it may eventually become a useful library of routines. The demo goes through a few simple commands.
this one has an embedded SVG image drawn with Adobe Illustartor. It makes used of deflate/inflate and base64 encoding for sharing data via posts.
Code: (Select All)
'a few routines and a demo for drawing with SVGs defined inside the program
'SVG library example
'Requires QB64-PE v4.1 or later to run or compile
'
Screen _NewImage(600, 400, 32)
Randomize Timer
_PrintMode _KeepBackground
_Title "SVGdraw and related routines"
'====================== DEMO =========================================
numcirc = Int(50 + Rnd * 124)
cs$ = ""
For c = 1 To numcirc
SVGcircle cs$, Int(Rnd * _Width), Int(Rnd * _Height), Int(10 + Rnd * 50), Int(1 + Rnd * 12), _RGB32(rand0(255), rand0(255), rand0(255), rand0(255)), _RGB32(rand0(255), rand0(255), rand0(255), rand0(255))
Next c
SVGdraw cs$, 0, 0 'have to call this routine after setting the SVG up with the earleir SVG command to display the SVG
Print "A bunch of filled circles. <press any key>"
Sleep
Cls
ss$ = ""
SVGtriangle ss$, 100, 100, 200, 200, 100, 250, 3, _RGB32(200, 200, 0), _RGB32(100, 100, 100)
SVGtriangle ss$, 150, 100, 250, 200, 150, 250, 3, _RGB32(200, 200, 0), _RGB32(100, 100, 200, 128)
SVGtriangle ss$, 200, 100, 300, 200, 200, 250, 3, _RGB32(200, 0, 200), _RGB32(100, 200, 100, 128)
SVGdraw ss$, 0, 0
Print "A few overlapping triangles. <press any key>"
Sleep
Cls
ss$ = ""
Dim pp(12)
pp(1) = 10: pp(2) = 10
pp(3) = 100: pp(4) = 100
pp(5) = 200: pp(6) = 110
pp(7) = 300: pp(8) = 200
pp(9) = 250: pp(10) = 150
pp(11) = 200: pp(12) = 70
SVGpath ss$, pp(), 8, _RGB32(100, 200, 200, 100)
SVGdraw ss$, 0, 0
Print "A path. <press any key>"; ""
Sleep
Cls
SVGfpath ss$, pp(), 8, _RGB32(100, 100, 200, 100), _RGB32(200, 100, 200, 190)
SVGdraw ss$, 0, 0
Print "Redrew as a filled path. <press any key>"; ""
Sleep
Cls
Dim tshape(8)
tshape(1) = 100: tshape(2) = 30
tshape(3) = 150: tshape(4) = 100
tshape(5) = 50: tshape(6) = 100
tshape(7) = 100: tshape(8) = 30
ts$ = ""
SVGpolyA ts$, tshape(), 3, _RGB32(0, 100, 140, 200), _RGB32(0, 200, 200, 190)
SVGdraw ts$, 0, 0
For x = 600 To 0 Step -10
_Limit 30
Cls
SVGdraw cs$, 0, 0
SVGdraw ts$, x, 20
Print "Animation example using a shape defined as a polygon and the circle background from earlier."
_Display
Next x
_AutoDisplay
Sleep
Cls
SVGellipse es$, 100, 100, 45, 25, Int(1 + Rnd * 12), _RGB32(255, 255, 255, 255), _RGB32(rand0(255), rand0(255), rand0(255), rand0(255))
SVGellipse es$, 200, 100, 12, 45, Int(1 + Rnd * 12), _RGB32(255, 255, 255, 255), _RGB32(rand0(255), rand0(255), rand0(255), rand0(255))
SVGdraw es$, 0, 0
Print "Filled Ellipses. <press any key>"
Sleep
'========================= routines =============================================================
Sub SVGcircle (svgimage$, cx, cy, radius, stroke, strokeK~&, fillK~&)
'converst input data to a svg definition of a circle
'fillK~k& and strokK~& are the 32 biut colors for the fill color and the stroke colors of the circle
'stroke is the thickness of the perimieter fof the circle
'SVGdraw must be used following this routine to display the shape drawn
r& = _Red32(fillK~&): g& = _Green32(fillK~&): b& = _Blue32(fillK~&): a& = _Alpha32(fillK~&)
fk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
fo$ = _Trim$(Str$(a& / 255))
r& = _Red32(strokeK~&): g& = _Green32(strokeK~&): b& = _Blue32(strokeK~&):: a& = _Alpha32(strokeK~&)
sk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
so$ = _Trim$(Str$(a& / 255))
svgimage$ = svgimage$ + "<circle cx='" + Tnum$(cx) + "' cy='" + Tnum$(cy) + "' r='" + Tnum$(radius) + "'fill-opacity='" + fo$ + "' fill='" + _Trim$(fk$) + "'"
svgimage$ = svgimage$ + "'stroke-opacity='" + so$ + "' stroke='" + _Trim$(sk$) + "' stroke-width='" + _Trim$(Str$(stroke)) + "' />"
End Sub
Sub SVGtriangle (svgimage$, x1, y1, x2, y2, x3, y3, stroke, strokeK~&, fillK~&)
'converst input data to a svg definition of a triangle
'fillK~k& and strokK~& are the 32 biut colors for the fill color and the stroke colors of the circle
'stroke is the thickness of the perimeter of the triangle
'SVGdraw must be used following this routine to display the shape drawn
r& = _Red32(fillK~&): g& = _Green32(fillK~&): b& = _Blue32(fillK~&): a& = _Alpha32(fillK~&)
fk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
fo$ = Tnum$(a& / 255)
r& = _Red32(strokeK~&): g& = _Green32(strokeK~&): b& = _Blue32(strokeK~&):: a& = _Alpha32(strokeK~&)
sk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
so$ = _Trim$(Str$(a& / 255)) 'stroke opacity doesn't seem to be supported but i'm still calulating it for now
svgimage$ = svgimage$ + "<polygon points='" + Str$(x1) + "," + Str$(y1) + Str$(x2) + " ," + Str$(y2) + Str$(x3) + "," + Str$(y3) + " '"
svgimage$ = svgimage$ + "fill-opacity='" + fo$ + "' fill='" + _Trim$(fk$) + "'"
svgimage$ = svgimage$ + "'stroke-opacity='" + so$ + "' stroke='" + _Trim$(sk$) + "' stroke-width='" + Tnum$(stroke) + "' />"
End Sub
Sub SVGpath (svgimage$, Pt(), stroke, strokek~&)
'draw a path described in the single dimensionalarray Pt()
'stroke is thickness of path draw
'strokek~& is color of the stroke to be drawn
'SVGdraw must be used following this routine to display the shape drawn
r& = _Red32(strokek~&): g& = _Green32(strokek~&): b& = _Blue32(strokek~&):: a& = _Alpha32(strokek~&)
sk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
so$ = Tnum$(a& / 255)
totp = UBound(Pt): If totp Mod 2 <> 0 Then totp = totp - 1
dpath$ = "M"
For n = 1 To totp
dpath$ = dpath$ + Str$(Pt(n))
Next n
svgimage$ = svgimage$ + "<path d='" + dpath$ + "'fill-opacity='0' stroke ='" + sk$ + "' stroke-width='" + Tnum$(5) + "' />"
End Sub
Sub SVGfpath (svgimage$, Pt(), stroke, strokek~&, fillK~&)
'draws a filled path described in the single dimensionalarray Pt()
'stroke is thickness of path draw
'strokek~& is color of the stroke to be drawn
'fillK~& is the color to fill the contained space withing the drawn path
'SVGdraw must be used following this routine to display the shape drawn
r& = _Red32(strokek~&): g& = _Green32(strokek~&): b& = _Blue32(strokek~&):: a& = _Alpha32(strokek~&)
sk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
so$ = _Trim$(Str$(a& / 255))
r& = _Red32(fillK~&): g& = _Green32(fillK~&): b& = _Blue32(fillK~&): a& = _Alpha32(fillK~&)
fk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
fo$ = _Trim$(Str$(a& / 255))
totp = UBound(Pt): If totp Mod 2 <> 0 Then totp = totp - 1
dpath$ = "M"
For n = 1 To totp
dpath$ = dpath$ + Str$(Pt(n))
Next n
svgimage$ = svgimage$ + "<path d='" + dpath$ + "' fill='" + fk$ + "' fill-opacity='" + fo$ + "' stroke-linejoin='miter' stroke ='" + sk$ + "' stroke-width='" + Tnum$(stroke) + "' />"
End Sub
Sub SVGpolyA (svgimage$, Pt(), stroke, strokek~&, fillK~&)
'draws a filled polygon described in the single dimensionalarray Pt()
'stroke is thickness of path draw
'strokek~& is color of the stroke to be drawn
'fillK~& is the color to fill the contained space withing the drawn path
'SVGdraw must be used following this routine to display the shape drawn
r& = _Red32(strokek~&): g& = _Green32(strokek~&): b& = _Blue32(strokek~&):: a& = _Alpha32(strokek~&)
sk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
so$ = _Trim$(Str$(a& / 255))
r& = _Red32(fillK~&): g& = _Green32(fillK~&): b& = _Blue32(fillK~&): a& = _Alpha32(fillK~&)
fk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
fo$ = _Trim$(Str$(a& / 255))
totp = UBound(Pt): If totp Mod 2 <> 0 Then totp = totp - 1
dpath$ = "M"
For n = 1 To totp Step 2
dpath$ = dpath$ + Str$(Pt(n)) + "," + Str$(Pt(n + 1))
Next n
svgimage$ = svgimage$ + "<polygon points='" + dpath$ + " '"
svgimage$ = svgimage$ + " fill='" + fk$ + "' fill-opacity='" + fo$ + "'stroke-linejoin='miter' stroke ='" + sk$ + "' stroke-width='" + Tnum$(stroke) + "' />"
End Sub
Sub SVGellipse (svgimage$, cx, cy, rx, ry, stroke, strokeK~&, Fillk~&)
'converst input data to a svg definition of a circle
'fillK~k& and strokK~& are the 32 biut colors for the fill color and the stroke colors of the circle
'stroke is the thickness of the perimieter fof the circle
'SVGdraw must be used following this routine to display the shape drawn
r& = _Red32(Fillk~&): g& = _Green32(Fillk~&): b& = _Blue32(Fillk~&): a& = _Alpha32(Fillk~&)
fk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
fo$ = _Trim$(Str$(a& / 255))
r& = _Red32(strokeK~&): g& = _Green32(strokeK~&): b& = _Blue32(strokeK~&):: a& = _Alpha32(strokeK~&)
sk$ = _Trim$("#" + hexpad$(r&) + hexpad$(g&) + hexpad$(b&))
so$ = _Trim$(Str$(a& / 255))
svgimage$ = svgimage$ + "<ellipse cx='" + Tnum$(cx) + "' cy='" + Tnum$(cy) + "' rx='" + Tnum$(rx) + "' ry='" + Tnum$(ry)
svgimage$ = svgimage$ + "' fill-opacity='" + fo$ + "' fill='" + _Trim$(fk$) + "'"
svgimage$ = svgimage$ + "'stroke-opacity='" + so$ + "' stroke='" + _Trim$(sk$) + "' stroke-width='" + _Trim$(Str$(stroke))
svgimage$ = svgimage$ + " transform='rotate(" + Tnum$(erot) + ")' />"
End Sub
Function Tnum$ (num)
'returns a numbers as a trimmed string (I worte this because it is briefer in the strings used to define the SVGs)
Tnum$ = _Trim$(Str$(num))
End Function
Function hexpad$ (k&)
'makes sure a hexidecimal value of a number is returned as 2 characters
If k& < 16 Then
hexpad$ = "0" + Hex$(k&)
Else
hexpad$ = Hex$(k&)
End If
End Function
Sub SVGdraw (svgi$, px, py)
'completes an svg layer perviously defined in svgimage$ and display it starting fron the point px.py
'is meant to fill a screen
Dim simg&
'get the screen size and build the header
svgheader$ = "<svg width='" + _Trim$(Str$(_Width)) + "' height='" + _Trim$(Str$(_Height)) + "' >"
svgfooter$ = "</SVG>"
svgimage$ = unpackSVG$(svgi$)
If svgimage$ = "NOT_A_PACKED_SVG" Then
SVGdrawing$ = svgheader$ + svgi$ + svgfooter$ 'attacjing the header,mains svg definiton string and the footer
simg& = _LoadImage(SVGdrawing$, 32, "memory") 'loads the completed SVgdrawing described in the string
_PutImage (px, py), simg& 'put the drawing on the screen
_FreeImage simg& 'free up the memory
Else
SVGdrawing$ = svgheader$ + svgimage$ + svgfooter$ 'attacjing the header,mains svg definiton string and the footer
simg& = _LoadImage(SVGdrawing$, 32, "memory") 'loads the completed SVgdrawing described in the string
_PutImage (px, py), simg& 'put the drawing on the screen
_FreeImage simg& 'free up the memory
End If
End Sub
Function SVGpack$ (svg$)
dc$ = _Deflate$(svg$, 10)
SVGpack$ = "SVG64" + _Base64Encode$(dc$)
End Function
Function unpackSVG$ (packed$)
unp$ = "NOT_A_PACKED_SVG"
If Left$(packed$, 5) = "SVG64" Then
datal = Len(packed$) - 5
s0$ = Right$(packed$, datal)
s1$ = _Base64Decode$(s0$)
unp$ = _Inflate$(s1$)
End If
unpackSVG$ = unp$
End Function
Function rand0 (num)
'returns a random # from 0 to num
rand0 = Int(Rnd * (num + 1))
End Function
this one has an embedded SVG image drawn with Adobe Illustartor. It makes used of deflate/inflate and base64 encoding for sharing data via posts.
Code: (Select All)
'Packed SVG example
'this program requires QB64-Phoenix Edition 4.1 or later
'
'displayes an encoded SVG graphic
'the oriignal data was compressed by use of the _deflate$ commad and _base64encode$ to make it safe to share as a text file on HTML
'
Screen _NewImage(1200, 600, 32)
_FullScreen _SquarePixels , _Smooth
'the following lines are a packed SVg file The original SVG was draewn in Adobe Iluustrator and simplified by hand
'to embed in a program and encoded for compression and safe transmission as tetx file
esvg$ = "SVG64eNrdXN2P5MZx/1cGyIMSoDlh9XcDToDzCHpSngzkXaDXvkVGOuF2odj316c+u5uc2Zt1LECwdZglh0M2q6vr81fV+t3PP7x+PP3xP07f/BfA2TsP23o"
esvg$ = esvg$ + "GJ5+gn4SfeF0XCOd2xZ+WcPXntkT66yJdceEX+hGf9Ys+i0dPzy70rD/nxZ/TL/lcr3SBBtwWfQMes97Z8FjxbrqOlLhVKJG/OHpZ6De/4Lscfpa0AZJDz3t8M5KBo+"
esvg$ = esvg$ + "E0Nh4Zn8pKTVt4PH4HOGDagL/RvaC0eqUoLkqe10+aPjhJGVQeokfs1qCfwt+Bbwx8C80P5of5W9B3JqUBJhqC0ABMDDMPzwNNHz+ZGY2/4SQKHouj9cDjBsyA6iL+Hhyxq"
esvg$ = esvg$ + "2zGQs9/AzMy6hIXPvKLL5EEABcU/+DvER/Fk0pDEgfxFaCfiHxGzhOn+Arwh+5grtEPldiAF4nKQKxWsYpMQ7Fludqst91KO10Xp+tCA+JVHsbtecWyNj3t9WmRX2CJIvYkB"
esvg$ = esvg$ + "1sk2cGziJ+CaxLxA3jblehqLL40PV4WRzeDyxMZphIs1gfyov6Wr0gkCeOVWM9SvAgRwEK7LsmE8UDyPAkRXpms/JqEb9fVJWK9qCQuQ8UpZifqELfBW2ABQkpM3VDvgIe/"
esvg$ = esvg$ + "EgnwkX79Zcmomyw/uIR8J1LtZwFfVFK3RcxAXuTdjaTQtDjqnZXPVSNNEhILNDAZ+CzOIJ8zvT5fhc2FKGMLoxpWbczMF2Qq9GLSHhJuz8wkbc94xGkgTz4SLatQuYiCk"
esvg$ = esvg$ + "bj0mYgeIie2rreF7qS/m0xq8bw0cYn8dn448p1NFJqntU6Km9VY1E34zuaL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ClWQLVamldRCZKubXd66POUjdku7rOVn/OGf12VeJeQKW3mvpNiiFLNsgvkRLxGEVG2FiCJ8SGJx3Jx36ZtG"
esvg$ = esvg$ + "atXEoO2kN8DMCiwNtKzgGpGuvxPBrLiGmEQmd5NYpmzmaUHScbD7rbsnfsYYspQ0tTWE7ao9rlypM9kN7cvFc8xcRpADv1+SfRMRNMF0oAYXZehh9ImrezTZqCbjs"
esvg$ = esvg$ + "N7hU5Wqy1wZNCo7CFlGEHmxk59rWgLoHfkNmseJahsRBP3QcqGi07TQ+plf07aodWa+lv/8QHbTn07VI82ONgKChOwrXJNq4K7fSaTZG5aUGWF5BuybYt+Q3poX1glUn"
esvg$ = esvg$ + "mHU2aiXSf/8UQpIvFxShh2/Y8UsVT6neOU0s/kmUs/c3fO3iMijdDq9rao6xYMl7UBFawR6g1JMN5l5V0VWQiEofGmikZn4Pqrmcj/A0X9oTA="
'
'lets display the image
SVGdraw esvg$, 100, 100
Print "press any key to see the SVG code"
Sleep
Print unpackSVG$(esvg$)
'_Clipboard$ = unpackSVG$(esvg$) 'uncommnet if you want to dump the unencoded SVG defiiniton paste in a file (without the header and footer)
_Delay .5
Print
Print "pretty large isn't it? The SVg files prodcued by Adobe Illustrator are pretty verbose"
Print "The packed SVG from the string esvg$ in the code is "; Len(esvg$); "characters in size."
Print "The unpacked SVG is "; Len(unpackSVG$(esvg$)); " characters in size."
Print "<press any key>"
Sleep
x = 0
For s = 1 To 8
SVGdrawscale esvg$, x, 0, s 'displaying the SVG image at varios scales
x = x + (s * 32)
Next s
Print "The chief advantage is scalability. Images may be scaled without pixelation."
Sleep
System
Function SVGpack$ (svg$)
'takes an SVG descrpiton (any string really) and deflaets it to save space
'the deflated data is convereted to base64 encoding to male is safe to share as text
dc$ = _Deflate$(svg$, 10)
SVGpack$ = "SVG64" + _Base64Encode$(dc$)
End Function
Function unpackSVG$ (packed$)
unp$ = "NOT_A_PACKED_SVG"
If Left$(packed$, 5) = "SVG64" Then
datal = Len(packed$) - 5
s0$ = Right$(packed$, datal)
s1$ = _Base64Decode$(s0$)
unp$ = _Inflate$(s1$)
End If
unpackSVG$ = unp$
End Function
Sub SVGdraw (svgi$, px, py)
'completes an svg layer perviously defined in svgimage$ and display it starting fron the point px.py
'is meant to fill a screen
Dim simg&
'get the screen size and build the header
svgheader$ = "<svg width='" + _Trim$(Str$(_Width)) + "' height='" + _Trim$(Str$(_Height)) + "' >"
svgfooter$ = "</SVG>"
svgimage$ = unpackSVG$(svgi$)
If svgimage$ = "NOT_A_PACKED_SVG" Then
SVGdrawing$ = svgheader$ + svgi$ + svgfooter$ 'attacjing the header,mains svg definiton string and the footer
simg& = _LoadImage(SVGdrawing$, 32, "memory") 'loads the completed SVgdrawing described in the string
_PutImage (px, py), simg& 'put the drawing on the screen
_FreeImage simg& 'free up the memory
Else
SVGdrawing$ = svgheader$ + svgimage$ + svgfooter$ 'attacjing the header,mains svg definiton string and the footer
simg& = _LoadImage(SVGdrawing$, 32, "memory") 'loads the completed SVgdrawing described in the string
_PutImage (px, py), simg& 'put the drawing on the screen
_FreeImage simg& 'free up the memory
svgimage$ = ""
End If
End Sub
Sub SVGdrawscale (svgi$, px, py, scale)
'completes an svg layer perviously defined in svgimage$ and display it starting fron the point px.py
'is meant to fill a screen
'scale changes the scale of the drawing 1.0 is 100% while 0.5 would be 50& and 4 would be 400%
Dim simg&
'get the screen size and build the header
svgheader$ = "<svg width='" + _Trim$(Str$(_Width)) + "' height='" + _Trim$(Str$(_Height)) + "' ><g transform='scale(" + _Trim$(Str$(scale)) + ")' >"
svgfooter$ = " </g></SVG>"
svgimage$ = unpackSVG$(svgi$)
If svgimage$ = "NOT_A_PACKED_SVG" Then
SVGdrawing$ = svgheader$ + svgi$ + svgfooter$ 'attacjing the header,mains svg definiton string and the footer
simg& = _LoadImage(SVGdrawing$, 32, "memory") 'loads the completed SVgdrawing described in the string
_PutImage (px, py), simg& 'put the drawing on the screen
_FreeImage simg& 'free up the memory
Else
SVGdrawing$ = svgheader$ + svgimage$ + svgfooter$ 'attacjing the header,mains svg definiton string and the footer
simg& = _LoadImage(SVGdrawing$, 32, "memorym") 'loads the completed SVgdrawing described in the string
_PutImage (px, py), simg& 'put the drawing on the screen
_FreeImage simg& 'free up the memory
svgimage$ = ""
End If
End Sub