|
| 1 | +''' |
| 2 | +
|
| 3 | +''' |
| 4 | + |
| 5 | +circles = [] |
| 6 | +tempo = 1 |
| 7 | + |
| 8 | + |
| 9 | +def setup(): |
| 10 | + size(512, 512, P2D) |
| 11 | + stroke(255, 200) |
| 12 | + fill(255, 75) |
| 13 | + background(128) |
| 14 | + ellipseMode(RADIUS) |
| 15 | + |
| 16 | + |
| 17 | +def draw(): |
| 18 | + background(128) |
| 19 | + for c in circles: |
| 20 | + c.setRadius(c.getRadius() + tempo) |
| 21 | + c.display() |
| 22 | + |
| 23 | + |
| 24 | +def mousePressed(): |
| 25 | + makeCircle(mouseX, mouseY) |
| 26 | + |
| 27 | + |
| 28 | +def makeCircle(x, y): |
| 29 | + for c in circles: |
| 30 | + distance = sqr((x - c.x)^2 + (y - c.y)^2) |
| 31 | + circles.append(Circle(x, y)) |
| 32 | + |
| 33 | + |
| 34 | +def compareCircles(current, other): |
| 35 | + # TODO: (1) @data use a list of distances saved as String. Exact matches.. |
| 36 | + currentRadius = current.getRadius() |
| 37 | + otherRadius = other.getRadius() |
| 38 | + |
| 39 | + for c in circles: |
| 40 | + if currentRadius in c.distances: |
| 41 | + # and other circle matches storedDistance |
| 42 | + other.setRadius(0) |
| 43 | + else: |
| 44 | + if (currentRadius + otherRadius) >= storedDistances: |
| 45 | + if not currentRadius > otherRadius: |
| 46 | + current.setRadius(currentRadius - tempo) |
| 47 | + |
| 48 | + current.setRadius(currentRadius + tempo) |
| 49 | + |
| 50 | + |
| 51 | +class Circle(): |
| 52 | + # TODO: (1) @data - instance var list of distances [other hilite] |
| 53 | + def __init__(self, x, y): |
| 54 | + # if mod([x, y], some_value) = some other value, vary the pitch |
| 55 | + self.x = x |
| 56 | + self.y = y |
| 57 | + self.radius = 1 |
| 58 | + # self.pitch = 0 |
| 59 | + # TODO: (10) @sound loudness based on the distance from the center of this |
| 60 | + # circle to the center of the one which "popped" it. |
| 61 | + # self.loudness = 0 |
| 62 | + # self.dur = |
| 63 | + |
| 64 | + def display(self): |
| 65 | + ellipse(self.x, self.y, 1, 1) |
| 66 | + ellipse(self.x, self.y, self.radius, self.radius) |
| 67 | + |
| 68 | + def getRadius(self): |
| 69 | + return self.radius |
| 70 | + |
| 71 | + def setRadius(self, radius): |
| 72 | + self.radius = radius |
0 commit comments