Skip to content

Commit 57dfb0c

Browse files
committed
Tarbell's #003 A fully working, albeit very slowly.
Process sketches commits. Hodgin's #003 A partially working. Process sketches need docstring updates.
1 parent b998c9a commit 57dfb0c

File tree

12 files changed

+202
-325
lines changed

12 files changed

+202
-325
lines changed

Whitney Artport - (Software) Structures/#003/A/Interpretation/Number_003_A_Hodgin/Number_003_A_Hodgin.pde

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ void setup()
4646
background(bgColor);
4747
smooth();
4848
colorMode(RGB, 255);
49-
ellipseMode(CENTER_RADIUS);
49+
ellipseMode(RADIUS);
5050
noStroke();
51-
framerate(30);
51+
frameRate(30);
5252
createCircles();
5353
}
5454

@@ -273,7 +273,7 @@ class Circle
273273
vertex(x - xd*.75 + random(-1.0,1.0), y - yd*.75 + random(-1.0,1.0));
274274
vertex(circle[i].x, circle[i].y);
275275
endShape();
276-
//line (x, y, circle[i].x, circle[i].y);
276+
line (x, y, circle[i].x, circle[i].y);
277277
}
278278
}
279279
noStroke();

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414
from disc import Disc
1515

16+
1617
# Object array.
1718
discs = []
1819
num = 100
@@ -50,3 +51,18 @@ def draw():
5051
disc.drawSelf()
5152
disc.render(discs)
5253
disc.renderPxRiders()
54+
55+
def boundsCheck(x, y, pad):
56+
constrainedX = constrain(x, -pad, width + pad)
57+
constrainedY = constrain(y, -pad, height + pad)
58+
if constrainedX != x:
59+
if x < 0:
60+
return False
61+
else:
62+
x = True
63+
if constrainedY != y:
64+
if y < 0:
65+
y = height + pad * 2
66+
else:
67+
y = -pad
68+
return x, y

Whitney Artport - (Software) Structures/#003/A/Interpretation/Number_003_A_Tarbell/disc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pxrider import PxRider
22

3-
43
# Disc object.
54
class Disc(object):
65
def __init__(self, index, x, y, velocityX, velocityY, destRadius):
@@ -60,17 +59,18 @@ def move(self):
6059
# Add velocity to position.
6160
self.x += self.velocityX
6261
self.y += self.velocityY
63-
bound = width + self.radius * 2
62+
boundWidth = width + self.radius * 2
63+
boundHeight = height + self.radius * 2
6464

6565
# Bound check.
6666
if self.x + self.radius < 0:
67-
self.x += bound
67+
self.x += boundWidth
6868
if self.x - self.radius > width:
69-
self.x -= bound
69+
self.x -= boundWidth
7070
if self.y + self.radius < 0:
71-
self.y += bound
71+
self.y += boundHeight
7272
if self.y - self.radius > width:
73-
self.y -= bound
73+
self.y -= boundHeight
7474

7575
# Increase to destination radius.
7676
if self.radius < self.destRadius:
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Pixel Rider object.
22
class PxRider(object):
3-
43
def __init__(self):
54
self.theta = random(TAU)
65
self.deltaV = 0.0
@@ -18,30 +17,32 @@ def move(self, x, y, radius):
1817
# Draw.
1918
px = x + radius * cos(self.theta)
2019
py = y + radius * sin(self.theta)
21-
# color = get(px, py)
22-
loadPixels()
23-
color = pixels[int(px) + int(py) * height]
24-
if brightness(color) > 48:
25-
self.glowpoint(px, py)
20+
screenColor = get(int(px), int(py))
21+
# loadPixels()
22+
# screenColor = pixels[int(py) * this.width + int(px)]
23+
if brightness(screenColor) > 48:
24+
PxRider.glowpoint(px, py)
2625
self.charge = 164
2726
else:
2827
stroke(self.charge)
2928
point(px, py)
3029
self.charge *= 0.98
3130

32-
def tpoint(x, y, myColor, trans):
33-
# Place translucent point.
34-
# color = get(x, y)
35-
loadPixels()
36-
color = pixels[x + y * height]
37-
r = red(color) + (red(myColor) - red(color)) * trans
38-
g = green(color) + (green(myColor) - green(color)) * trans
39-
b = blue(color) + (blue(myColor) - blue(color)) * trans
40-
stroke(color(r, g, b))
41-
point(x, y)
42-
43-
def glowpoint(px, py):
31+
@classmethod
32+
def glowpoint(cls, px, py):
4433
for i in range(-2, 3):
4534
for j in range(-2, 3):
4635
a = (0.8 - i**2 * 0.1) - j**2 * 0.1
47-
self.tpoint(px + i, py + j, '#FFFFFF', a)
36+
PxRider.tpoint(px + i, py + j, '#FFFFFF', a)
37+
38+
@classmethod
39+
def tpoint(cls, x, y, myColor, trans):
40+
# Place translucent point.
41+
screenColor = get(int(x), int(y))
42+
# loadPixels()
43+
# screenColor = pixels[int(y) * this.width + int(x)]
44+
r = red(screenColor) + (red(myColor) - red(screenColor)) * trans
45+
g = green(screenColor) + (green(myColor) - green(screenColor)) * trans
46+
b = blue(screenColor) + (blue(myColor) - blue(screenColor)) * trans
47+
stroke(color(r, g, b))
48+
point(x, y)

Whitney Artport - (Software) Structures/#003/A/Number_003_A/Number_003_A.pyde

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ circles = None
2121

2222
def setup():
2323
size(800, 600)
24-
circles = [Circle(random(width), height / NumCircles * i,
24+
circles = [Circle(i, random(width), height / NumCircles * i,
2525
(random(1, 6)) * 10, random(-1.0, 1.0),
26-
random(-1.0, 1.0), i) for i in range(NumCircles)]
26+
random(-1.0, 1.0))
27+
for i in range(NumCircles)]
2728
strokeWeight(0.5)
2829
ellipseMode(CENTER)
2930
background(255)
@@ -35,5 +36,5 @@ def draw():
3536
for circle in circles:
3637
circle.update(circles)
3738
circle.move()
38-
circle.makepoint()
39+
circle.drawSelf()
3940
noFill()
Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
class Circle(object):
22
'''A circle object'''
33

4-
def __init__(self, centerX, centerY, radius, xspeed, yspeed, index):
5-
self.centerX = centerX
6-
self.centerY = centerY
4+
def __init__(self, index, x, y, radius, xspeed, yspeed):
5+
self.index = index
6+
self.x = x
7+
self.y = y
78
self.radius = radius
89
self.rSqr = self.radius**2
9-
self.index = index
1010
self.xspeed = xspeed
1111
self.yspeed = yspeed
1212

@@ -15,36 +15,49 @@ def update(self, circles):
1515
if circle.index != self.index:
1616
self.intersect(circle)
1717

18-
def makepoint(self):
18+
def drawSelf(self):
1919
stroke(0)
20-
point(self.centerX, self.centerY)
20+
point(self.x, self.y)
2121

2222
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
23+
self.x += self.xspeed
24+
self.y += self.yspeed
25+
if self.xspeed > 0 and self.x > width + self.radius:
26+
self.x = -self.radius
27+
elif self.x < -self.radius:
28+
self.x = width + self.radius
29+
if self.yspeed > 0 and self.y > height + self.radius:
30+
self.y = -self.radius
31+
elif self.y < -self.radius:
32+
self.y = height + self.radius
3333

3434
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) * 4)
50-
line(paX, paY, pbX, pbY)
35+
distance = dist(self.x, self.y, other.x, other.y)
36+
if (distance > self.radius + other.radius
37+
or distance < abs(self.radius - other.radius)):
38+
return # No solution.
39+
a = (self.rSqr - other.rSqr + distance**2) / (2 * distance)
40+
hyp = sqrt(self.rSqr - a**2)
41+
midpointX = Circle.calc2(self.x, '+', a, Circle.calc1(other.x, self.x, distance))
42+
midpointY = Circle.calc2(self.y, '+', a, Circle.calc1(other.y, self.y, distance))
43+
pointAX = Circle.calc2(midpointX, '+', hyp, Circle.calc1(other.y, self.y, distance))
44+
pointAY = Circle.calc2(midpointY, '-', hyp, Circle.calc1(other.x, self.x, distance))
45+
pointBX = Circle.calc2(midpointX, '-', hyp, Circle.calc1(other.y, self.y, distance))
46+
pointBY = Circle.calc2(midpointY, '+', hyp, Circle.calc1(other.x, self.x, distance))
47+
Circle.renderIntersect(midpointX, midpointY, pointAX, pointAY, pointBX, pointBY)
48+
49+
@classmethod
50+
def renderIntersect(cls, midpointX, midpointY, pointAX, pointAY, pointBX, pointBY):
51+
stroke(255 - dist(pointAX, pointAY, pointBX, pointBY) * 4)
52+
line(pointAX, pointAY, pointBX, pointBY)
53+
54+
@classmethod
55+
def calc1(cls, first, second, distance):
56+
return (first - second) / distance
57+
58+
@classmethod
59+
def calc2(cls, first, operation, second, function):
60+
if operation == '+':
61+
return first + second * function
62+
elif operation == '-':
63+
return first - second * function

Whitney Artport - (Software) Structures/#003/Process/s3_process_1/s3_process_1.pde

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
// Modified by Casey Reas
55

66

7+
78
Circle circleA, circleB;
89

10+
911
void setup()
1012
{
1113
size( 300, 300 );

Whitney Artport - (Software) Structures/#003/Process/s3_process_1/s3_process_1.pyde

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ circleB = None
1111

1212

1313
def setup():
14-
size(300, 300)
14+
size(800, 800)
1515
frameRate(30)
1616
circleA = Circle(150, 150, 50)
1717
circleB = Circle(150, 150, 60)
@@ -52,10 +52,10 @@ def intersect(circleA, circleB):
5252
pointAY = calc2(midpointY, '-', hyp, calc1(circleB.x, circleA.x, distance))
5353
pointBX = calc2(midpointX, '-', hyp, calc1(circleB.y, circleA.y, distance))
5454
pointBY = calc2(midpointY, '+', hyp, calc1(circleB.x, circleA.x, distance))
55-
render(midpointX, midpointY, pointAX, pointAY, pointBX, pointBY)
55+
renderIntersect(midpointX, midpointY, pointAX, pointAY, pointBX, pointBY)
5656

5757

58-
def render(midpointX, midpointY, pointAX, pointAY, pointBX, pointBY):
58+
def renderIntersect(midpointX, midpointY, pointAX, pointAY, pointBX, pointBY):
5959
fill(0)
6060
rect(midpointX, midpointY, 5, 5)
6161
ellipse(pointAX, pointAY, 10, 10)

0 commit comments

Comments
 (0)