-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
125 lines (101 loc) · 2.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
let t = 0
let c = [
math.complex(math.random(50), math.random(50)),
math.complex(math.random(50), math.random(50)),
math.complex(math.random(50), math.random(50)),
math.complex(math.random(50), math.random(50)),
math.complex(math.random(50), math.random(50)),
math.complex(math.random(50), math.random(50)),
math.complex(0, 0)
]
function print (value) {
const precision = 2
console.log(math.format(value, precision))
}
function setup() {
createCanvas(800, 600)
background(0)
}
function draw() {
background(0)
translate(400, 300)
t += 0.05
beginShape()
for(let t = 0; t <= math.pi * 2; t += 0.04) {
let cn = F(t)
stroke('rgb(0, 255, 0)')
noFill()
vertex(math.ceil(cn.re), math.ceil(-1 * cn.im))
}
endShape()
let sumarr = []
let pc = c.slice(0, (c.length - 1) / 2)
let mc = c.slice((c.length - 1) / 2, c.length - 1)
sumarr.push(c[c.length - 1])
for(let i = 0, pci = 0, mci = 0; i < c.length - 1; i++) {
if(i % 2 == 0) {
sumarr.push(math.multiply(pc[pci], math.pow(math.e, math.multiply(math.i, (pci + 1) * t))))
pci++
} else if(i % 2 == 1) {
sumarr.push(math.multiply(mc[mci], math.pow(math.e, math.multiply(math.i, -1 * (mci + 1) *t))))
mci++
}
stroke('rgb(255, 255, 255)')
noFill()
line(
math.ceil(sum(sumarr.slice(0, sumarr.length - 1)).re),
math.ceil(-1 * sum(sumarr.slice(0, sumarr.length - 1)).im),
math.ceil(sum(sumarr).re),
math.ceil(-1 * sum(sumarr).im)
)
fill('rgb(255, 255, 255)')
noStroke()
ellipse(
math.ceil(sum(sumarr).re),
math.ceil(-1 * sum(sumarr).im),
4
)
stroke('rgba(255, 255, 255, 0.5)')
noFill()
ellipse(
math.ceil(sum(sumarr.slice(0, sumarr.length - 1)).re),
math.ceil(-1 * sum(sumarr.slice(0, sumarr.length - 1)).im),
2 * math.abs(
math.subtract(
sum(sumarr.slice(0, sumarr.length - 1)),
sum(sumarr)
)
)
)
}
if(t >= 6.28)
t = 0
}
function F(t) {
let ret = math.complex(0, 0)
ret = math.add(ret, c[c.length - 1])
for (let i = 0, j = 1; i < (c.length - 1) / 2; i++, j++) {
ret = math.add(ret,
math.multiply(c[i],
math.pow(math.e,
math.multiply(j,
math.multiply(math.i,
t )))))
}
for (let i = (c.length - 1) / 2, j = 1; i < (c.length - 1); i++, j++) {
ret = math.add(ret,
math.multiply(c[i],
math.pow(math.e,
math.multiply(-1 * j,
math.multiply(math.i,
t )))))
}
return ret
}
function sum(arr) {
let ret = math.complex(0, 0)
for (let i = 0; i < arr.length; i++) {
ret = math.add(ret, arr[i])
}
return ret
}