Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
from reportlab.pdfgen import canvas from reportlab.lib.units import cm, inch, mm c = canvas.Canvas("ulam.pdf", pagesize=(23*inch, 23*inch)) total = int(23*inch/mm * 23 * inch/mm) # Sieve of Eratosthenes nums = [ i for i in range(2*total) ] primes = [ True for i in range(2*total) ] primes[0] = False primes[1] = False for p in range(len(primes)): if primes[p]: i = 2 while i*p < len(primes): primes[i*p] = False i += 1 import random def drawDot(x, y): r = random.random() g = random.random() b = 1 - (r**2 + g**2)**.5 c.setFillColorRGB(random.random()/2+.25, random.random()/2+.25, random.random()/2+.25) c.circle(x*mm + 23*inch/2, y*mm + 23*inch/2, .5*mm, stroke=0, fill=1) sidelength = 1 x = 0 y = 0 n = 1 while n < total: for _ in range(sidelength): x += 1 n += 1 if primes[n]: drawDot(x,y) for _ in range(sidelength): y += 1 n += 1 if primes[n]: drawDot(x,y) sidelength += 1 for _ in range(sidelength): x -= 1 n += 1 if primes[n]: drawDot(x,y) for _ in range(sidelength): y -= 1 n += 1 if primes[n]: drawDot(x,y) sidelength += 1 c.showPage() c.save()
This paste will be private.
From the Design Piracy series on my blog: