Jump to content

Recommended Posts

Posted
6 hours ago, AttilaP said:

Thanks everyone for the feedback. Using texture might not be a proper solution, as it does not have a specific pattern, it is always different.

@AttilaP In my example each circle diameter it's randomly generated (but it could be generated by your own implementation) just the background grid it's a texture.

Posted

SVG Example written to html, Creating it is fast. Loading it in the browser seems to be acceptable even for bigger grids.
I have no solution for a simple way to convert the SVG to PNG or other formats. Some examples are around

 

#include <FileConstants.au3>

Global Const $CELL_SIZE = 30
Global Const $GRID_PADDING = 5
Global Const $MIN_CIRCLE_RADIUS = 5
Global Const $MAX_CIRCLE_RADIUS = 10
Global $START = TimerInit()

Global $htmlFile


func WriteHTMLHead()
    filewrite($htmlFile , "<!DOCTYPE html><html><body>")
EndFunc
func WriteHTMLFooter()
    filewrite($htmlFile , " </body></html>")
endfunc

func WriteSVGStart($grid_size)
    filewrite($htmlFile , "<svg width=""" & $grid_size*($CELL_SIZE+$GRID_PADDING) & """ height=""" &  $grid_size*($CELL_SIZE+$GRID_PADDING)& """>")
EndFunc

func WriteSVGEnd()
    filewrite($htmlFile , " </svg>")
EndFunc

Func WriteSVGCircles($GRID_SIZE)
    Local $circleString

    For $i = 0 To $GRID_SIZE - 1
        For $j = 0 To $GRID_SIZE - 1
            Local $iRadius = Random($MIN_CIRCLE_RADIUS, $MAX_CIRCLE_RADIUS, 1)
            Local $iCenterX = $GRID_PADDING * 1.5 + $j * ($CELL_SIZE + $GRID_PADDING) + $CELL_SIZE / 2
            Local $iCenterY = $GRID_PADDING * 1.5 + $i * ($CELL_SIZE + $GRID_PADDING) + $CELL_SIZE / 2

            $circleString="<circle cx=""" & $iCenterX & """ cy=""" & $iCenterY & """ r=""" & $iRadius & """ stroke=""green"" stroke-width=""4"" fill=""yellow"" />"

            filewrite($htmlFile, $circlestring & @crlf)
        Next

    Next

EndFunc   ;==>DrawSVGCircles

func writeGrid($grid_size)
    local $iCol
    local $iRow
    for $iRow=0 to $grid_size
        local $iRowY=($iRow*($CELL_SIZE+$GRID_PADDING))
        filewrite($htmlFile , "    <line x1=""0"" y1=""" & $iRowY & """ x2=""" & $grid_size*($CELL_SIZE+$GRID_PADDING) & """ y2=""" & $iRowY & """ style=""stroke:red;stroke-width:2"" />")
    next

    for $iCow=0 to $grid_size
        local $iCol=($iCow*($CELL_SIZE+$GRID_PADDING))
        filewrite($htmlFile , "    <line x1=""" &$iCol & """ y1=""0"" x2=""" & $iCol & """ y2=""" & $grid_size*($CELL_SIZE+$GRID_PADDING) & """ style=""stroke:red;stroke-width:2"" />")
    next

EndFunc

func exampleSVG($grid_size)
    $htmlFile = FileOpen("C:\demo\svgdemo.html", $FO_OVERWRITE )
    WriteHTMLHead()
    WriteSVGStart($grid_size)
    writeGrid($grid_size)
    WriteSVGCircles ($grid_size)
    WriteSVGEnd()
    WriteHTMLFooter()
    fileclose($htmlFile)
EndFunc

exampleSVG(500)

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...