Skip to content

Commit 1ca0b23

Browse files
committed
formula touchups
- Style. - Copyedit. - Fix up comments. - Rename for clarity.
1 parent 2560453 commit 1ca0b23

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

formula/formula.pyde

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
1-
'''
2-
A sketch based on (a radical misinterpretation of) the formula from the JS1K
3-
segment of Steven Wittens' "Making Things With Maths" video. Really,
4-
everything is mine except the math in `segment.py`.
1+
'''A sketch inspired by (a radical misinterpretation of) the math from the
2+
JS1K segment of Steven Wittens' "Making Things With Maths" video. Really,
3+
everything is mine except the math in `segment.py`. See also
4+
http://acko.net/blog/js1k-demo-the-making-of
55
66
Implemented in Processing.py/Processing 2.1 by Ben Alkov 11-16 Sept 2014.
77
'''
88
from tentacle import Tentacle
99

1010

1111
time = 0
12-
Tick = 1 / 100.0 # Bad Python FP.
12+
Tick = 1 / 100.0 # Boo Python FP.
1313
SphereRadius = 200
14-
Tentacles = None
15-
Colors = [[color(169, 202, 240), # rgb(169, 202, 240) # blues
14+
Colors = [[color(169, 202, 240), # rgb(169, 202, 240) blues
1615
color(160, 191, 227), # rgb(160, 191, 227)
1716
color(142, 170, 202), # rgb(142, 170, 202)
1817
color(115, 137, 163), # rgb(115, 137, 163)
1918
color(70, 84, 99)], # rgb(70, 84, 99)
20-
# reds
21-
[color(206, 151, 96), # rgb(206, 151, 96)
19+
[color(206, 151, 96), # rgb(206, 151, 96) reds
2220
color(207, 105, 43), # rgb(207, 105, 43)
2321
color(193, 87, 37), # rgb(193, 87, 37)
2422
color(124, 40, 12), # rgb(124, 40, 12)
2523
color(120, 41, 13)], # rgb(120, 41, 13)
26-
# greens
27-
[color(115, 146, 34), # rgb(115, 146, 34)
24+
[color(115, 146, 34), # rgb(115, 146, 34) greens
2825
color(104, 135, 23), # rgb(104, 135, 23)
2926
color(92, 109, 29), # rgb(92, 109, 29)
3027
color(78, 93, 22), # rgb(78, 93, 22)
3128
color(63, 76, 16)] # rgb(63, 76, 16)
3229
]
30+
Tentacles = [Tentacle(i * -100, Colors[i % 3])
31+
for i in range(6)]
3332

3433
def setup():
35-
global Tentacles
3634
size(512, 512, OPENGL)
3735
rectMode(RADIUS)
3836
ellipseMode(RADIUS)
3937
strokeWeight(2)
40-
Tentacles = [Tentacle(i * -100, Colors[i % 3])
41-
for i in range(6)]
4238

4339

4440
def draw():
45-
global time, Tentacles
41+
global time
4642
rightHanded()
4743
fade()
4844
time += Tick
49-
for tentacle in Tentacles:
50-
tentacle.update(time, Tick, SphereRadius)
45+
for t in Tentacles:
46+
t.update(time, Tick, SphereRadius)
5147

5248

5349
def rightHanded():

formula/segment.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@ class Segment(object):
22
'''A Segment, which encapsulates its own position and color, and can draw
33
itself'''
44

5-
def __init__(self, index, tickOffset, altitude, lineColor):
6-
self.index = index
7-
# A "magic" number. 12 just seems to look good.
8-
self.tickOffset = tickOffset * 12
5+
def __init__(self, id, tickOffset, alti, color):
6+
self.id = id
97
# Effectively, the distance between segments.
10-
self.altitude = altitude
11-
self.lineColor = lineColor
12-
self.location = PVector(0.0, 0.0, 0.0)
8+
self.alti = alti
9+
self.tickOffset = tickOffset
10+
self.color = color
11+
self.loc = PVector(0.0, 0.0, 0.0)
12+
# A magic number. 12 just seems to look good.
13+
self.tickOffset *= 12
1314

14-
def calc(self, time, sphereRadius):
15-
# New formula from http://acko.net/blog/js1k-demo-the-making-of
15+
def calc(self, time, sRadius):
1616
# Spherical coords.
17-
lon = cos(time + sin(time * 0.31)) * 2 + sin(time * 0.83) * 3 + time * 0.02
18-
lat = sin(time * 0.7) - cos(3 + time * 0.23) * 3
17+
# New formula from http://acko.net/blog/js1k-demo-the-making-of
18+
lon = (cos(time + sin(time * 0.31)) * 2
19+
+ sin(time * 0.83)
20+
* 3 + time * 0.02)
21+
lat = (sin(time * 0.7)
22+
- cos(3 + time * 0.23) * 3)
1923
# Convert to cartesian 3D.
2024
# http://acko.net/blog/js1k-demo-the-making-of
21-
self.location.set(cos(lon) * cos(lat) * (sphereRadius + self.altitude),
22-
sin(lon) * cos(lat) * (sphereRadius + self.altitude),
23-
sin(lat) * (sphereRadius + self.altitude))
25+
self.loc.set(cos(lon) * cos(lat) * (sRadius + self.alti),
26+
sin(lon) * cos(lat) * (sRadius + self.alti),
27+
sin(lat) * (sRadius + self.alti))
2428

2529
def drawSelf(self, other):
26-
stroke(self.lineColor)
27-
line(self.location.x, self.location.y, self.location.z,
28-
other.location.x, other.location.y, other.location.z)
30+
stroke(self.color)
31+
line(self.loc.x, self.loc.y, self.loc.z,
32+
other.loc.x, other.loc.y, other.loc.z)

formula/tentacle.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ class Tentacle(object):
55
'''A Tentacle made of Segments.
66
'''
77
# Factor to determine the distance between Segments.
8-
AltitudeOffset = 1
8+
AltiOffset = 1
99

1010
def __init__(self, timeOffset, palette):
1111
self.timeOffset = timeOffset
1212
self.palette = palette
1313
self.segments = [Segment(i, i, # Second `i` is tickOffset.
14-
Tentacle.AltitudeOffset * i + i,
14+
(Tentacle.AltiOffset * i) + i,
1515
self.palette[i])
1616
for i in range(5)]
1717

18-
def update(self, time, Tick, sphereRadius):
19-
for segment in self.segments:
20-
segment.calc((time - self.timeOffset) -
21-
(segment.tickOffset * Tick),
22-
sphereRadius)
18+
def update(self, time, Tick, sRadius):
19+
for seg in self.segments:
20+
seg.calc((time - self.timeOffset) - (seg.tickOffset * Tick),
21+
sRadius)
2322
# Don't try to draw the last segment.
24-
if segment.id is not len(self.segments) - 1:
23+
if seg.id != len(self.segments) - 1:
2524
# Draw to the next segment.
26-
segment.drawSelf(self.segments[segment.id + 1])
25+
seg.drawSelf(self.segments[seg.id + 1])

0 commit comments

Comments
 (0)