Skip to content

Instantly share code, notes, and snippets.

@void4
Created April 3, 2025 09:36
Show Gist options
  • Save void4/3665320e0e572a49dbd30c8cdbb7a985 to your computer and use it in GitHub Desktop.
Save void4/3665320e0e572a49dbd30c8cdbb7a985 to your computer and use it in GitHub Desktop.
from math import *
# pip install drawsvg
import drawsvg as draw
w = h = 1024
circle_radius = 500
circle_center_radius = 5
d = draw.Drawing(w, w, origin="center")
# Background
d.append(draw.Rectangle(-w, -w//2, w*2, w, fill='#444'))
d.append(draw.Circle(0, 0, circle_radius, stroke="#000000", stroke_width=5, fill="#eeeeee"))
beta = pi/4
r = (-sin(beta) + sqrt(sin(beta)**2 + 2 - 2*cos(beta)))/(2 - 2*cos(beta))
start_arc_x = 0
start_arc_y = r * circle_radius
end_arc_x = (cos(beta) + r*sin(beta))*circle_radius
end_arc_y = (sin(beta) - r*cos(beta))*circle_radius
d.append(draw.Circle(start_arc_x, start_arc_y, r*circle_radius, stroke="#ff0000", stroke_width=10, fill=None, fill_opacity=0))
d.append(draw.Circle(end_arc_x, end_arc_y, r*circle_radius, stroke="#0000ff", stroke_width=10, fill=None, fill_opacity=0))
d.append(draw.Circle(0, 0, circle_center_radius, stroke="#dddddd", stroke_width=2, fill="#000000"))
start_x = 0
start_y = 0
end_x = cos(beta) * circle_radius
end_y = sin(beta) * circle_radius
d.append(draw.Line(start_x, start_y, end_x, end_y, stroke="black", stroke_width=8))
d.append(draw.Text(f"β={beta*180/pi:.2f}°", font_size=18, x=0, y=-20, stroke="black", text_anchor='middle'))
d.save_png(f"opticurve.png")
d.save_svg(f"opticurve.svg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment