Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import svgwrite
import pygame, sys
import math
import os
Expand All @@ -16,8 +17,29 @@
counter = 0
centre = (width//2,height//2)
show_axes = False
paused = 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=1)) # White line

# Save the drawing to the file
dwg.save()

def from_centre(x,y):
return (centre[0]+x,centre[1]-y)
Expand Down Expand Up @@ -127,9 +149,12 @@ 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
if event.key == pygame.K_p:
paused = not paused
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When paused, the animation pauses but if I click somewhere while it is paused, it spawns a planet there which isn't visible while it is still paused, but after resuming it, you can see the spawned planet entering the animation.

if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_pos = pygame.mouse.get_pos()
count += 1
Expand All @@ -145,6 +170,8 @@ def render():
"x":pygame.mouse.get_pos()[0],
"y":pygame.mouse.get_pos()[1],
}
render()
circles.append(rad)
if not paused:
render()
pygame.display.update()
fps.tick(60)
fps.tick(60)