<commit_before>package main

import (
	//"math/cmplx"
	"image/color"
	"image/png"
	"os"

	"./fractal"
)

func mandelbrot(z, c complex128, max float64, depth int) color.Color {
	if depth > 1 {
		a, b := real(z), imag(z)
		znew := complex((a*a-b*b),2*a*b) + c
		/*if cmplx.Abs(znew) < max {
			return mandelbrot(znew, c, max, depth-1)
		}*/
		if a*a+b*b < max {
			return mandelbrot(znew, c, max, depth-1)
		}


	}
	return color.RGBA{uint8(255/depth), uint8(255/depth), uint8(255/depth), 255}
}

func mandelbrotIter(z, c complex128, max float64, depth int) color.Color {
	var a, b float64
	iteration := depth
	for a*a+b*b < max && iteration > 0{
		a, b = real(z), imag(z)
		z = complex((a*a-b*b),2*a*b) + c
		iteration--
	}
	return color.RGBA{uint8(255*iteration/depth), uint8((255*iteration)/depth), uint8(255*iteration/depth), 255}
}


func main() {
	f := fractal.NewFractal(complex(-3, -1.5), complex(1.5, 1.5), 1000)
	f.Apply2All(
		func(c complex128) color.Color {
			return mandelbrot(complex(0,0), c, 4, 100)
		})

	fo, err := os.Create("output.png")
	defer fo.Close()

	if err != nil {
		panic(err)
	}
	png.Encode(fo, f)
}<commit_msg>some strong optimizations added<commit_after>package main

import (
	//"math/cmplx"
	"image/color"
	"image/png"
	"os"
	"fmt"
	"./fractal"
)


func mandelbrotRecur(z, c complex128, max float64, depth int) color.Color {
	if depth > 1 {
		a, b := real(z), imag(z)
		znew := complex((a*a-b*b),2*a*b) + c
		/*if cmplx.Abs(znew) < max {
			return mandelbrot(znew, c, max, depth-1)
		}*/
		if a*a+b*b < max {
			return mandelbrotRecur(znew, c, max, depth-1)
		}
	}
	fmt.Printf("bop")
	return color.RGBA{uint8(255/depth), uint8(255/depth), uint8(255/depth), 255}
}



func mandelbrotIter(z, c complex128, max float64, depth int, r []complex128) color.Color {
	var a, b float64
	iteration := 0
	l := len(r)
iter:
	for a*a+b*b < max && iteration < depth{
		iteration++
		a, b = real(z), imag(z)
		z = complex((a*a-b*b),2*a*b) + c
		if iteration % l == 0 {
			for i:=l-1; i>0; i-- {
				if r[i] == z {
					iteration = depth
					break iter 
				}
			}
		}
		r[iteration%l] = z

	}
	return color.RGBA{uint8(255*iteration/depth), uint8((255*iteration)/depth), uint8(255*iteration/depth), 255}
}

func loopdetect(path []complex128, c complex128) {
	
}


func main() {
	f := fractal.NewFractal(complex(-3, -1.5), complex(1.5, 1.5), 1000)
	d := 1000
	r := make([]complex128, 40)
	f.Apply2All(
		func(c complex128) color.Color {
			return mandelbrotIter(complex(0,0), c, 4, d, r)
		})

	fo, err := os.Create("output.png")
	defer fo.Close()

	if err != nil {
		panic(err)
	}
	png.Encode(fo, f)
}
{'fraction_non_alphanumeric': 0.18869365928189458, 'fraction_numerical': 0.059587471352177235, 'mean_word_length': 3.476923076923077, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3880127', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1154, 'n_words': 256}