Skip to content

Instantly share code, notes, and snippets.

@jpbougie
Created November 27, 2009 19:03
Show Gist options
  • Save jpbougie/244176 to your computer and use it in GitHub Desktop.
Save jpbougie/244176 to your computer and use it in GitHub Desktop.
import itertools
import math
skew(0.0, 0.0)
stroke(0.3, 0.3, 0.3, 1.0)
class ConcentricCircle(object):
def __init__(self, x, y, radius, qty, attraction, width):
self.x = x
self.y = y
self.qty = qty
self.radius = radius
self.attraction = attraction
self.width = width
def draw(self):
push()
fill(0.0, 0.0, 0.0, 0.0)
stroke(self.strokecolor())
for i in xrange(self.qty + 1):
strokewidth(self.width * i / self.qty)
r = (self.radius * i) / self.qty * 2
r += self.attraction * (float(self.qty - i) / self.qty)
offset = (r / 2)
oval(self.x - offset, self.y - offset, r, r)
pop()
def nearest_point(self, x, y):
vector = (x - self.x, y - self.y)
length = math.sqrt(vector[0] * vector[0] + vector[1] * vector[1])
vector = [component / length for component in vector]
return (self.x + vector[0] * (self.radius), self.y + vector[1] *(self.radius))
def strokecolor(self):
return (0.3, 0.3, 0.3, 1.0)
def join_circles(a, b, width = 5):
strokewidth(0)
x1, y1 = a.nearest_point(b.x, b.y)
x2, y2 = b.nearest_point(a.x, a.y)
color(c.strokecolor())
strokewidth(width)
line(x1, y1, x2, y2)
c = ConcentricCircle(500, 500, 100, 3, 130, 10)
c.draw()
c2 = ConcentricCircle(615, 615, 50, 5, 40, 5)
c2.draw()
c3 = ConcentricCircle(650, 320, 30, 2, 10, 2)
c3.draw()
join_circles(c, c2)
join_circles(c, c3, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment