From Rosetta Code:
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. It can be described by the equation: $$r=a+b\theta$$ with real numbers \$a\$ and \$b\$.
Here is my attempt to draw it in Python (using Pillow):
"""This module creates an Archimdean Spiral.""" from math import cos, sin, pi from PIL import Image, ImageDraw def translate(point, screen_size): """ Takes a point and converts it to the appropriate coordinate system. Note that PIL uses upper left as 0, we want the center. Args: point (real, real): A point in space. screen_size (int): Size of an N x N screen. Returns: (real, real): Translated point for Pillow coordinate system. """ return point + screen_size / 2, point + screen_size / 2 def draw_spiral(a, b, img, step=0.5, loops=5): """ Draw the Archimdean spiral defined by: r = a + b*theta Args: a (real): First parameter b (real): Second parameter img (Image): Image to write spiral to. step (real): How much theta should increment by. (default: 0.5) loops (int): How many times theta should loop around. (default: 5) """ draw = ImageDraw.Draw(img) theta = 0.0 r = a prev_x = int(r*cos(theta)) prev_y = int(r*sin(theta)) while theta < 2 * loops * pi: theta += step r = a + b*theta # Draw pixels, but remember to convert to Cartesian: x = int(r*cos(theta)) y = int(r*sin(theta)) draw.line(translate((prev_x, prev_y), img.size) + translate((x, y), img.size), fill=1) prev_x = x prev_y = y if __name__ == '__main__': IMAGE_SIZE = 300, 300 img = Image.new('1', IMAGE_SIZE) draw_spiral(1, 2, img) img.save('spiral.png')
The program outputs this image: