Created
April 10, 2026 18:35
-
-
Save scumola/74b7bcacae9a66008410160dcdd61a9f to your computer and use it in GitHub Desktop.
Dots and lines in SVG format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import drawsvg as draw | |
| import math | |
| import random | |
| spacing = 7 | |
| stroke = 0.5 | |
| rows, cols = (200, 200) | |
| arr = [[0]*(cols*2)]*(rows*2) | |
| d = draw.Drawing(450, 450, origin='center') | |
| for x in (range(-cols, rows, spacing+1)): | |
| for y in (range(-cols, rows, spacing+1)): | |
| size = random.randint(1,spacing) | |
| if (size > 1): | |
| arr[x][y] = size | |
| if ((x > -200) and (y > -200)): | |
| if (size > spacing * .9): | |
| d.append(draw.Line(x,y,x-spacing-1,y, stroke_width=stroke, stroke='black')) | |
| if (size < spacing * .5): | |
| d.append(draw.Line(x,y,x-spacing-1,y-spacing-1, stroke_width=stroke, stroke='black')) | |
| if (size < spacing * .5): | |
| if (y < 190): | |
| d.append(draw.Line(x,y,x-spacing-1,y+spacing+1, stroke_width=stroke, stroke='black')) | |
| if (size > spacing * .9): | |
| d.append(draw.Line(x,y,x,y-spacing-1, stroke_width=stroke, stroke='black')) | |
| for x in (range(-cols, rows, spacing+1)): | |
| for y in (range(-cols, rows, spacing+1)): | |
| size = random.randint(1,spacing) | |
| if (size > 1): | |
| if (arr[x][y] > 0): | |
| d.append(draw.Circle(x, y, size/2, fill='white', stroke_width=stroke, stroke='black')) | |
| d.save_svg('stuff.svg') | |
| d # Display as SVG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment