1
1
class Point (object ):
2
- def __init__ (self , startX , startY ):
3
- self .startX = startX
4
- self .startY = startY
2
+ HalfWidth = 0
3
+ HalfHeight = 0
4
+ HalfDist = 0
5
+ Limit = 0
6
+
7
+ def __init__ (self , index ):
8
+ self .index = index
9
+ self .startX = 0
10
+ self .startY = 0
5
11
self .rnd = random (5 , 30 )
6
12
self .diameter = map (self .rnd , 5 , 30 , 0.5 , 2 )
7
13
if random (1 ) > 0.5 :
@@ -11,8 +17,39 @@ def __init__(self, startX, startY):
11
17
self .phi = random (360 )
12
18
self .x = 0
13
19
self .y = 0
20
+ self .lines = []
21
+ self .makePoint ()
22
+
23
+ def makePoint (self ):
24
+ while True :
25
+ randX = random (Point .HalfWidth * 0.74 ) + random (40 )
26
+ randY = random (Point .HalfHeight * 0.84 ) + random (40 )
27
+ angle = random (2 * PI )
28
+ initX = randX * cos (angle )
29
+ initY = randY * sin (angle )
30
+ dx = map (initX ,
31
+ 0 , Point .HalfWidth , 0 , 1.15 )
32
+ dy = map (initY ,
33
+ 0 , Point .HalfHeight , 0 , 1.35 )
34
+ prob = pow (2.72 , - (dx ** 2 * 2 + dy ** 2 * 2 ))
35
+ if random (1 ) < prob :
36
+ self .startX = initX
37
+ self .startY = initY
38
+ return
39
+
40
+ def setLines (self , others ):
41
+ # for other in others:
42
+ # if (self is not other
43
+ # and dist(self.x, self.y, other.x, other.y) < Limit / 3):
44
+ # lines.append(PVector(self.index,
45
+ # other.index))
46
+ thirdLimit = Point .Limit / 3
47
+ self .lines = [other .index
48
+ for other in others
49
+ if (self is not other
50
+ and dist (self .x , self .y , other .x , other .y ) < thirdLimit )]
14
51
15
- def update (self , time ):
52
+ def update (self , time , others ):
16
53
if self .rt :
17
54
self .x = self ._calc (self .startX , cos , time )
18
55
self .y = self ._calc (self .startY , sin , time )
@@ -22,7 +59,29 @@ def update(self, time):
22
59
noStroke ()
23
60
fill (255 )
24
61
ellipse (self .x , self .y , self .diameter , self .diameter )
62
+ self .drawLines (others )
25
63
64
+ def drawLines (self , others ):
65
+ halfLimit = Point .Limit / 2
66
+ for other in others :
67
+ if (self is not other
68
+ and other .index in self .lines ):
69
+ plusX = self .x + other .x * 0.5
70
+ plusY = self .y + other .y * 0.5
71
+ mouseWrapX = mouseX - Point .HalfWidth
72
+ mouseWrapY = mouseY - Point .HalfHeight
73
+ amp = (map (dist (plusX , plusY , 0 , 0 ),
74
+ 0 , Point .HalfDist , 2 , 8 ))
75
+ distance = (map (noise (plusX * 0.03 , plusY * 0.03 ),
76
+ 0 , 1 , 5 , halfLimit ))
77
+ if dist (plusX , plusY , mouseWrapX , mouseWrapY ) < Point .Limit :
78
+ distance = (distance * map (dist (plusX , plusY , mouseWrapX , mouseWrapY ),
79
+ 0 , Point .Limit , amp , 1 ))
80
+ if dist (self .x , self .y , other .x , other .y ) < distance :
81
+ opacity = map (dist (self .x , self .y , other .x , other .y ),
82
+ 0 , distance , 85 , 0 )
83
+ stroke (255 , opacity )
84
+ line (self .x , self .y , other .x , other .y )
26
85
27
86
def _calc (self , coord , func , time ):
28
87
return coord + self .rnd * func (radians (time * self .diameter + self .phi ))
0 commit comments