Skip to content

Commit 64af5a1

Browse files
committed
{Software} Structure
#003A, #003A Tarbell, and my #003A are all running properly.
1 parent 160a9ee commit 64af5a1

File tree

7 files changed

+189
-202
lines changed

7 files changed

+189
-202
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'''
2+
Modified
3+
Structure 3
4+
5+
A surface filled with one hundred medium to small sized circles.
6+
Each circle has a different size and direction, but moves at the
7+
same slow rate.
8+
Display:
9+
A. The instantaneous intersections of the circles
10+
B. The aggregate intersections of the circles
11+
12+
Implemented by Casey Reas <http://groupc.net>
13+
8 March 2004
14+
Processing v.68 <http://processing.org>
15+
16+
'''
17+
from circle import Circle
18+
19+
NumCircles = 150
20+
circles = None
21+
22+
23+
def setup():
24+
size(1280, 720, P3D)
25+
# random x, y based on index value
26+
circles = [Circle(random(width), height / NumCircles * i,
27+
(random(1, 6)) * 10, random(-0.7, 0.7),
28+
random(-0.7, 0.7), i) for i in range(NumCircles)]
29+
smooth(4)
30+
ellipseMode(CENTER)
31+
background(173)
32+
33+
34+
def draw():
35+
background(173)
36+
stroke(0)
37+
for circle in circles:
38+
circle.update(circles)
39+
circle.move()
40+
noFill()

Whitney Artport - (Software) Structures/#003/A/Interpretation/Number_003_A_Alkov/Number_003_A_mod.pyde

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Circle(object):
2+
'''A circle object'''
3+
4+
def __init__(self, centerX, centerY, radius, xspeed, yspeed, index):
5+
self.centerX = centerX
6+
self.centerY = centerY
7+
self.radius = radius
8+
self.rSqr = self.radius**2
9+
self.index = index
10+
self.xspeed = xspeed
11+
self.yspeed = yspeed
12+
13+
def update(self, circles):
14+
for circle in circles:
15+
if circle.index != self.index:
16+
self.intersect(circle)
17+
18+
def makepoint(self):
19+
stroke(0)
20+
point(self.centerX, self.centerY)
21+
22+
def move(self):
23+
self.centerX += self.xspeed
24+
self.centerY += self.yspeed
25+
if self.xspeed > 0 and self.centerX > width + self.radius:
26+
self.centerX = -self.radius
27+
elif self.centerX < -self.radius:
28+
self.centerX = width + self.radius
29+
if self.yspeed > 0 and self.centerY > height + self.radius:
30+
self.centerY = -self.radius
31+
elif self.centerY < -self.radius:
32+
self.centerY = height + self.radius
33+
34+
def intersect(self, other):
35+
dx = self.centerX - other.centerX
36+
dy = self.centerY - other.centerY
37+
dSqr = dx**2 + dy**2
38+
diameter = sqrt(dSqr)
39+
if diameter > self.radius + other.radius or diameter < abs(self.radius - other.radius):
40+
return # no solution
41+
a = (self.rSqr - other.rSqr + dSqr) / (2 * diameter)
42+
h = sqrt(self.rSqr - a**2)
43+
x2 = self.centerX + a * (other.centerX - self.centerX) / diameter
44+
y2 = self.centerY + a * (other.centerY - self.centerY) / diameter
45+
paX = x2 + h * (other.centerY - self.centerY) / diameter
46+
paY = y2 - h * (other.centerX - self.centerX) / diameter
47+
pbX = x2 - h * (other.centerY - self.centerY) / diameter
48+
pbY = y2 + h * (other.centerX - self.centerX) / diameter
49+
stroke(255 - dist(paX, paY, pbX, pbY) * 2)
50+
line(paX, paY, pbX, pbY)

0 commit comments

Comments
 (0)