Skip to content

Commit

Permalink
gma: old toy
Browse files Browse the repository at this point in the history
  • Loading branch information
dskinner committed Mar 1, 2020
1 parent 0e6ff03 commit bc30a33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 57 deletions.
33 changes: 17 additions & 16 deletions gma/gma.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ func (a Multivector) Mul(b Multivector) Multivector {
c = append(c, b0.Mul(b1))
}
}
return simplify(c)
// return simplify(c)
return c
}

func (a Multivector) Add(b Multivector) Multivector {
Expand Down Expand Up @@ -248,21 +249,21 @@ func (a Multivector) ScalarProduct(b Multivector) float64 {
return a.Lc(b).Scalar()
}

func (a Multivector) NormE() float64 {
s := a.ScalarProduct(a.Rev())
if s < 0 {
return 0
}
return math.Sqrt(s)
}

func (a Multivector) NormE2() float64 {
s := a.ScalarProduct(a.Rev())
if s < 0 {
return 0
}
return s
}
// func (a Multivector) NormE() float64 {
// s := a.ScalarProduct(a.Rev())
// if s < 0 {
// return 0
// }
// return math.Sqrt(s)
// }

// func (a Multivector) NormE2() float64 {
// s := a.ScalarProduct(a.Rev())
// if s < 0 {
// return 0
// }
// return s
// }

func (a Multivector) Norm() float64 {
return math.Sqrt(a.NormSq())
Expand Down
50 changes: 9 additions & 41 deletions gma/plot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,14 @@ func saveImage(m image.Image, p string) {
}
}

// -0.835 -0.2321
// -0.70176 -0.3842
func TestJuliaFractal(t *testing.T) {
// e1 := Multivector{{1, E1}}
e1 := Multivector{{1, E1}}

// const width, height = 400, 300
// const zoom = 0.007
const width, height = 400, 300
const zoom = 0.007

const width, height = 800, 600
const zoom = 0.0035
// const width, height = 800, 600
// const zoom = 0.0035

const maxiter = 60

Expand All @@ -260,52 +258,22 @@ func TestJuliaFractal(t *testing.T) {
}

for clr.G = 0; clr.G < maxiter; clr.G++ {
p = p.Mul(Multivector{{1, E1}}).Mul(p).Add(c)
p = p.Mul(e1).Mul(p).Add(c)
if p.NormSq() > 1e4 {
// clr.R = 255
clr.R = clr.G * 2
break
}
}
clr.G *= uint8(255 / maxiter)

// n := p.Norm()/10 + 0.5
// if n > 255 {
// n = 255
// n = 255
// }
// clr.G = uint8(n / 8)
// clr.B = uint8(n / 8)

clr.G *= uint8(255 / maxiter)
m.Set(x, y, clr)
}
}
saveImage(m, "julia.png")
}

// func julia(x Multivector, c Multivector, maxiter int, maxabs float64) float64 {

// }

// func juliaFunc(c Multivector, maxiter int, maxabs float64, zoom float64) func(Multivector) float64 {
// return func(x Multivector) float64 {
// const e = Multivector{Blade{1, 1}}
// x = x.Mul(Multivector{Blade{s: zoom}})
// for i := 0; i < maxiter; i++ {
// x = x.Mul(e).Mul(x).Add(c)
// if x.NormSq() > maxabs {
// return math.Inf(0)
// }
// }
// return x.Norm()
// }
// }

// func mandelbrot(center complex128, maxIter int, maxAbs float64) int {
// z := 0 + 0i
// for i := 0; i < maxIter; i++ {
// z = z*z + center
// if cmplx.IsInf(z) || cmplx.IsNaN(z) || cmplx.Abs(z) > maxAbs {
// return i
// }
// }
// return maxIter
// }

0 comments on commit bc30a33

Please sign in to comment.