Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARRAYTO_SVG
#1
being able to load SVGs into memory gives QB64 Phoenix Edition programs a very powerful vector drawing tool. 
This in effect gives us a better draw command.
Here's a simple example that takes a two dimensional array of points and converts it to an SVG to be rendered.


Code: (Select All)
'arrayto_svg    v0.1
'by James D. Jarvis 11/15/2023,   QB64 3.9.0 or higher required
'Convert a two-dimensional numerical array into an SVG and draw that SVG on the screen
'
'made possible due to the SVG example in the QB64 Phoenix Edition WIKI example for _LOADIMAGE
'$dynamic
$Resize:Smooth
Dim As String svg
Dim img As Long
Dim a(3, 2), b(4, 2)
Screen _NewImage(1000, 500, 32)
a(1, 1) = 100: a(1, 2) = 100
a(2, 1) = 100: a(2, 2) = 200
a(3, 1) = 200: a(3, 2) = 200
svg = arrayto_svg$(a(), 20, "#EEEEEE", "#557733") 'convert the array a() into a closed polygon in an SVG
img = _LoadImage(svg, 32, "memory") 'load that SVG into the image
_PutImage , img 'draw the image
_FreeImage img 'free the image

b(1, 1) = 300: b(1, 2) = 200
b(2, 1) = 600: b(2, 2) = 200
b(3, 1) = 600: b(3, 2) = 300
b(4, 1) = 300: b(4, 2) = 300
svg = arrayto_svg$(b(), 5, "#770000", "#FFCCCC") 'convert the array a() into a closed polygon in an SVG
img = _LoadImage(svg, 32, "memory") 'load that SVG into the image
_PutImage , img 'draw the image
_FreeImage img 'free the image
Function arrayto_svg$ (aop(), swid, sklr As String, fklr As String)
    'convert a two dimensional numerical array aop(p,2) to a closed polygon to draw as an SVG
    Dim nsvg As String
    maxp = UBound(aop)
    nsvg = "<?xml version='1.0' encoding='utf-8'?>"
    nsvg = nsvg + "<!-- Generator: QB64_SVG, SVG Export . SVG Version: 6.00 Build 0)  -->"
    nsvg = nsvg + "<svg version='1.2' baseProfile='tiny' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'"
    nsvg = nsvg + "    x='0px' y='0px' viewBox='0 0 1000 500' overflow='visible' xmlConfusedpace='preserve'>"
    nsvg = nsvg + "<g>"
    nsvg = nsvg + "<path fill='" + fklr + "' stroke='" + sklr + "' stroke-width='" + _Trim$(Str$(swid)) + "' stroke-miterlimit='10' d='M"
    For p = 1 To maxp
        nsvg = nsvg + Str$(aop(p, 1)) + "," + Str$(aop(p, 2)) + ","
    Next p
    nsvg = nsvg + Str$(aop(1, 1)) + "," + Str$(aop(1, 2))
    nsvg = nsvg + "'/>"
    nsvg = nsvg + "</g>"
    nsvg = nsvg + "</svg>"
    arrayto_svg$ = nsvg
End Function
Reply


Messages In This Thread
ARRAYTO_SVG - by James D Jarvis - 11-15-2023, 07:11 PM
RE: ARRAYTO_SVG - by bplus - 11-15-2023, 07:15 PM
RE: ARRAYTO_SVG - by James D Jarvis - 11-15-2023, 07:17 PM
RE: ARRAYTO_SVG - by bplus - 11-15-2023, 09:44 PM
RE: ARRAYTO_SVG - by James D Jarvis - 11-15-2023, 11:05 PM



Users browsing this thread: 1 Guest(s)