|
1 | 1 | # http://patakk.tumblr.com / nightSky
|
2 | 2 | from point import Point
|
3 |
| -from line import Line |
| 3 | +# from line import Line |
4 | 4 |
|
5 |
| -ArrayList < Point> points = ArrayList < Point > () |
6 |
| -ArrayList < Line> lines = ArrayList < Line > () |
7 |
| -N = 500 |
8 |
| -time = 0 |
9 |
| -dst |
10 |
| -lim = 125 |
11 | 5 |
|
| 6 | +points = [] |
| 7 | +lines = [] |
| 8 | +NumPoints = 0 |
| 9 | +Limit = 0 |
| 10 | +HalfWidth = 0 |
| 11 | +HalfHeight = 0 |
| 12 | +HalfDist = 0 |
| 13 | +I_Dont_Know_What_This_Is = dist(0, 0, 960, 540) |
12 | 14 |
|
13 | 15 | def setup():
|
| 16 | + global points, HalfWidth, HalfHeight, HalfDist, NumPoints, Limit |
14 | 17 | size(700, 300)
|
15 |
| - smooth() |
16 |
| - N = 500.0 * dist(0, 0, width / 2, height / 2) / dist(0, 0, 1920 / 2, 1080 / 2)) |
17 |
| - lim = 160.0 * dist(0, 0, width / 2, height / 2) / dist(0, 0, 1920 / 2, 1080 / 2) |
18 | 18 | background(0)
|
19 |
| - n = 0 |
20 |
| - #noiseSeed(5) |
21 |
| - #randomSeed(1200) |
22 |
| - while (n < N) |
23 |
| - x, y, rx, ry, a |
24 |
| - rx = random(width / 2 * 0.74) + random(40) |
25 |
| - ry = random(height / 2 * 0.84) + random(40) |
26 |
| - a = random(2 * PI) |
27 |
| - x = rx * cos(a) |
28 |
| - y = ry * sin(a) |
29 |
| - dx = map(x, 0, width / 2, 0, 1.15) |
30 |
| - dy = map(y, 0, height / 2, 0, 1.35) |
31 |
| - prob = pow(2.72, -(dx * dx * 2 + dy * dy * 2)) |
32 |
| - if random(1) < prob: |
33 |
| - points.add(Point(x, y)) |
34 |
| - n++ |
35 |
| - for n = 0 in range( n < N - 1): # n++ |
36 |
| - x1 = points.get(n).cx |
37 |
| - y1 = points.get(n).cy |
38 |
| - for m = n + 1 in range( m < N): # m++ |
39 |
| - x2 = points.get(m).cx |
40 |
| - y2 = points.get(m).cy |
41 |
| - if dist(x1, y1, x2, y2) < lim / 3: |
42 |
| - lines.add(Line(n, m)) |
| 19 | + smooth() |
43 | 20 | strokeWeight(0.8)
|
| 21 | + HalfWidth = width / 2 |
| 22 | + HalfHeight = height / 2 |
| 23 | + HalfDist = dist(0, 0, HalfWidth, HalfHeight) |
| 24 | + NumPoints = (500.0 * HalfDist / I_Dont_Know_What_This_Is) |
| 25 | + Limit = (160.0 * HalfDist / I_Dont_Know_What_This_Is) |
| 26 | + # n = 0 |
| 27 | + # noiseSeed(5) |
| 28 | + # randomSeed(1200) |
| 29 | + # makePoint() |
| 30 | + points = [makePoint() for _ in range(NumPoints)] |
| 31 | + for point1 in points: |
| 32 | + x1 = point1.startX |
| 33 | + y1 = point1.startY |
| 34 | + for point2 in points: |
| 35 | + x2 = point2.startX |
| 36 | + y2 = point2.startY |
| 37 | + if dist(x1, y1, x2, y2) < Limit / 3: |
| 38 | + lines.append(PVector(points.index(point1), |
| 39 | + points.index(point2))) |
| 40 | + |
| 41 | +def makePoint(): |
| 42 | + while True: |
| 43 | + randX = random(HalfWidth * 0.74) + random(40) |
| 44 | + randY = random(HalfHeight * 0.84) + random(40) |
| 45 | + angle = random(2 * PI) |
| 46 | + startX = randX * cos(angle) |
| 47 | + startY = randY * sin(angle) |
| 48 | + dx = map(startX, |
| 49 | + 0, HalfWidth, 0, 1.15) |
| 50 | + dy = map(startY, |
| 51 | + 0, HalfHeight, 0, 1.35) |
| 52 | + prob = pow(2.72, -(dx**2 * 2 + dy**2 * 2)) |
| 53 | + if random(1) < prob: |
| 54 | + return(Point(startX, startY)) |
44 | 55 |
|
45 | 56 |
|
46 | 57 | def draw():
|
47 | 58 | background(0)
|
48 |
| - translate(width / 2, height / 2) |
49 |
| - for n = 0 in range( n < N): # n++ |
50 |
| - points.get(n).update() |
51 |
| - points.get(n).display() |
52 |
| - for n = 0 in range( n < lines.size()): # n++ |
53 |
| - x1 = points.get(lines.get(n).j).x |
54 |
| - y1 = points.get(lines.get(n).j).y |
55 |
| - x2 = points.get(lines.get(n).k).x |
56 |
| - y2 = points.get(lines.get(n).k).y |
57 |
| - amp = map(dist((x1 + x2) / 2, (y1 + y2) / 2, 0, 0), 0, dist(width / 2, height / 2, 0, 0), 2, 8) |
58 |
| - dst = map(noise((x1 + x2) / 2 * 0.03, (y1 + y2) / 2 * 0.03), 0, 1, 5, lim / 2) |
59 |
| - if dist((x1 + x2) / 2, (y1 + y2) / 2, mouseX - width / 2, mouseY - height / 2) < lim: |
60 |
| - dst = dst * map(dist((x1 + x2) / 2, (y1 + y2) / 2, mouseX - width / 2, mouseY - height / 2), 0, lim, amp, 1) |
61 |
| - if dist(x1, y1, x2, y2) < dst: |
62 |
| - strk = map(dist(x1, y1, x2, y2), 0, dst, 85, 0) |
63 |
| - stroke(255, strk) |
| 59 | + translate(HalfWidth, HalfHeight) |
| 60 | + for _point in points: |
| 61 | + _point.update(frameCount) |
| 62 | + for _line in lines: |
| 63 | + x1 = points[int(_line.x)].x |
| 64 | + y1 = points[int(_line.x)].y |
| 65 | + x2 = points[int(_line.y)].x |
| 66 | + y2 = points[int(_line.y)].y |
| 67 | + plusX = x1 + x2 / 2 |
| 68 | + plusY = y1 + y2 / 2 |
| 69 | + mouseWrapX = mouseX - HalfWidth |
| 70 | + mouseWrapY = mouseY - HalfHeight |
| 71 | + amp = (map(dist(plusX, plusY, 0, 0), |
| 72 | + 0, HalfDist, 2, 8)) |
| 73 | + distance = (map(noise(plusX * 0.03, plusY * 0.03), |
| 74 | + 0, 1, 5, Limit / 2)) |
| 75 | + if dist(plusX, plusY, mouseWrapX, mouseWrapY) < Limit: |
| 76 | + distance = (distance * map(dist(plusX, plusY, mouseWrapX, mouseWrapY), |
| 77 | + 0, Limit, amp, 1)) |
| 78 | + if dist(x1, y1, x2, y2) < distance: |
| 79 | + opacity = map(dist(x1, y1, x2, y2), |
| 80 | + 0, distance, 85, 0) |
| 81 | + stroke(255, opacity) |
64 | 82 | line(x1, y1, x2, y2)
|
65 |
| - time = time + 1 |
|
0 commit comments