1/*
2 I was inspired by this: https://www.youtube.com/watch?v=DEqXNfs_HhY
3
4 "floatMemset" and "byteMemset" - analogue of memset from C
5 https://stackoverflow.com/questions/30614165/is-there-analog-of-memset-in-go
6
7 Original C code: https://www.dropbox.com/s/79ga2m7p2bnj1ga/donut_deobfuscated.c?dl=0
8*/
9
10package main
11
12import (
13 "math"
14 "strings"
15 "time"
16
17 "honnef.co/go/js/dom/v2"
18)
19
20const (
21 delay = 100 * time.Millisecond // 10 fps
22 coreString = ".,-~:;=!*#$@"
23)
24
25type sliceType interface {
26 len() int
27}
28
29func floatMemset(arr []float64, v float64) {
30 for i := range arr {
31 arr[i] = v
32 }
33}
34
35func byteMemset(arr []string, v string) {
36 for i := range arr {
37 arr[i] = v
38 }
39}
40
41func main() {
42 A := float64(0)
43 B := float64(0)
44 el := dom.GetWindow().Document().QuerySelector("#donut-main-window")
45 htmlEl := el.(dom.HTMLElement)
46
47 var i, j float64
48 var k int
49
50 z := make([]float64, 1760)
51 b := make([]string, 1760)
52 for {
53 currString := ""
54 byteMemset(b, " ")
55 floatMemset(z, 0)
56
57 for j = 0; j < 6.28; j += 0.07 {
58 for i = 0; i < 6.28; i += 0.02 {
59 c := math.Sin(i)
60 d := math.Cos(j)
61 e := math.Sin(A)
62 f := math.Sin(j)
63 g := math.Cos(A)
64 h := d + 2
65 D := 1 / (c*h*e + f*g + 5)
66 l := math.Cos(i)
67 m := math.Cos(B)
68 n := math.Sin(B)
69 t := c*h*g - f*e
70
71 x := int(40 + 30*D*(l*h*m-t*n))
72 y := int(12 + 15*D*(l*h*n+t*m))
73
74 o := int(x + 80*y)
75
76 N := int(8 * ((f*e-c*d*g)*m - c*d*e - f*g - l*d*n))
77
78 if y < 22 && y > 0 && x > 0 && x < 80 && D > z[o] {
79 z[o] = D
80
81 // golang doesn't have ternary operator
82 point := 0
83 if N > 0 {
84 point = N
85 }
86
87 b[o] = string(coreString[point])
88 }
89
90 }
91 }
92
93 for k = 0; k < 1761; k++ {
94 v := "<br>"
95
96 if k%80 > 0 {
97 v = string(b[k])
98 }
99
100 currString += v
101
102 A += 0.00004
103 B += 0.00002
104 }
105 currString = strings.ReplaceAll(currString[4:], " ", " ")
106 htmlEl.SetInnerHTML(currString)
107 time.Sleep(delay)
108 }
109
110}