From cc14709f4c2ceab8d2e2ce458b61074a4eecc2b6 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 8 Jul 2024 13:00:54 +0200 Subject: [PATCH 1/3] use svgwrite to save as svg --- main.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 94e759f..63f1d1c 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import svgwrite import pygame, sys import math import os @@ -18,6 +19,26 @@ show_axes = False lines = [] +circles = [] + +def lines_to_svg(lines, output_file): + # Create an SVG drawing + dwg = svgwrite.Drawing(output_file, profile='full', size=(width, height)) + + # Add a black background + dwg.add(dwg.rect(insert=(0, 0), size=(width, height), fill=svgwrite.rgb(0, 0, 0, '%'))) + + # Add a circle + for radius in circles: + dwg.add(dwg.circle(center=centre, r=radius, fill='none', stroke=svgwrite.rgb(100, 100, 100, '%'), stroke_width=1)) + + # Iterate over the list of lines and add them to the SVG + for line in lines: + start, end = line + dwg.add(dwg.line(start=start, end=end, stroke=svgwrite.rgb(100, 100, 100, '%'), stroke_width=2)) # White line + + # Save the drawing to the file + dwg.save() def from_centre(x,y): return (centre[0]+x,centre[1]-y) @@ -127,6 +148,7 @@ def render(): if event.key == pygame.K_s: if not os.path.isdir("images"): os.makedirs("images") + lines_to_svg(lines, f"images/{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.svg"); pygame.image.save(screen, f"images/{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.png") if event.key == pygame.K_a: show_axes = not show_axes @@ -145,6 +167,7 @@ def render(): "x":pygame.mouse.get_pos()[0], "y":pygame.mouse.get_pos()[1], } + circles.append(rad) render() pygame.display.update() - fps.tick(60) + fps.tick(60) \ No newline at end of file From 3ef4630b687ad5fd50efedc5cf67674453297b26 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 8 Jul 2024 13:58:37 +0200 Subject: [PATCH 2/3] add pause key "P" --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 63f1d1c..6ba98e4 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ counter = 0 centre = (width//2,height//2) show_axes = False +paused = False lines = [] circles = [] @@ -152,6 +153,8 @@ def render(): pygame.image.save(screen, f"images/{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.png") if event.key == pygame.K_a: show_axes = not show_axes + if event.key == pygame.K_p: + paused = not paused if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: mouse_pos = pygame.mouse.get_pos() count += 1 @@ -168,6 +171,7 @@ def render(): "y":pygame.mouse.get_pos()[1], } circles.append(rad) - render() + if not paused: + render() pygame.display.update() fps.tick(60) \ No newline at end of file From 0959bbc3a4f60ef60dcc4375deb31dba3070b46a Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 9 Jul 2024 09:12:12 +0200 Subject: [PATCH 3/3] change stroke width --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 6ba98e4..ac7c22a 100644 --- a/main.py +++ b/main.py @@ -36,7 +36,7 @@ def lines_to_svg(lines, output_file): # Iterate over the list of lines and add them to the SVG for line in lines: start, end = line - dwg.add(dwg.line(start=start, end=end, stroke=svgwrite.rgb(100, 100, 100, '%'), stroke_width=2)) # White line + dwg.add(dwg.line(start=start, end=end, stroke=svgwrite.rgb(100, 100, 100, '%'), stroke_width=1)) # White line # Save the drawing to the file dwg.save()