Расчет фрактала на Go, Rust, Python
This commit is contained in:
52
main.go
Normal file
52
main.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/cmplx"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
size := flag.Int("size", 128, "размер")
|
||||
depth := flag.Int("depth", 8, "глубина")
|
||||
g2 := flag.Float64("g2", 0.0, "вещественная часть для g2")
|
||||
g3 := flag.Float64("g3", 1.0, "вещественная часть для g3")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
// Преобразуем в complex128
|
||||
cg2 := complex(*g2, 0)
|
||||
cg3 := complex(*g3, 0)
|
||||
|
||||
code := fractal(*size, *depth, cg2, cg3)
|
||||
fmt.Println(code)
|
||||
|
||||
}
|
||||
|
||||
func fractal(size int, depth int, g2 complex128, g3 complex128) string {
|
||||
var zy, zx float64
|
||||
var z complex128
|
||||
var yf float64 = 2
|
||||
var xf float64 = 2
|
||||
var yi float64 = -2
|
||||
var xi float64 = -2
|
||||
|
||||
var code string
|
||||
|
||||
for y := 0; y < size; y++ {
|
||||
zy = float64(y)*(yf-yi)/float64(size-1) + yi
|
||||
for x := 0; x < size; x++ {
|
||||
zx = float64(x)*(xf-xi)/float64(size-1) + xi
|
||||
z = complex(zx, zy)
|
||||
for i := 0; i < depth; i++ {
|
||||
if cmplx.Abs(z) > 2 {
|
||||
code += strconv.FormatInt(int64(i), 10)
|
||||
break
|
||||
}
|
||||
z = (cmplx.Pow(z, 4) + g2*cmplx.Pow(z, 2)/2 + 2*g3*z + cmplx.Pow(g2, 2)/16) / (4*cmplx.Pow(z, 3) - g2*z - g3)
|
||||
}
|
||||
}
|
||||
}
|
||||
return code
|
||||
}
|
||||
Reference in New Issue
Block a user