コード例 #1
0
ファイル: main.go プロジェクト: strickyak/superfractal
func main() {
	flag.Parse()

	// Special -l list command, listing short names for builtin IFSs.
	if *list {
		for k, v := range superfractal.Builtin {
			Printf("%s\t%s\n", k, v)
		}
		return
	}

	// Parse IFSs & construct initial Triptych.
	ifss := superfractal.ParseListOfIfsParams(*params)
	src := superfractal.NewTriptych(*numPanels, *width, *height)

	if *startTriang {
		// Special hack for demoing sier's traingles
		for i := 0; i < *numPanels; i++ {
			src.Panels[i].PaintTriangle(0, 0, 0, *height, *width, 0, canvas.White)
		}
	} else {
		// Fill initial Triptych with different colors.
		r, g, b := byte(255), byte(0), byte(0)
		for i := 0; i < *numPanels; i++ {
			if *mustWhite {
				r, g, b = byte(255), byte(255), byte(255)
			}
			src.Panels[i].Fill(0, 0, *width, *height, canvas.RGB(r, g, b))

			// Rotate & dim the colors a bit, on each iteration.
			// TODO: something better than this.
			r, g, b = byte(0.96*float64(b)), byte(0.96*float64(r)), byte(0.96*float64(g))
		}
	}

	// Loop for *num steps, creating successive superfractal approximations.
	for i := 0; i < *num; i++ {
		targ := superfractal.NewTriptych(*numPanels, *width, *height)
		targ.SuperStep(src, ifss)

		for j := 0; j < *numPanels; j++ {
			filename := Sprintf("%s.%03d.%03d.png", *base, i, j)
			canvas.Say(filename)
			f, err := os.Create(filename)
			if err != nil {
				panic(err)
			}
			targ.Panels[j].WritePng(f)
			f.Close()
		}
		src = targ
	}
}
コード例 #2
0
ファイル: coded.go プロジェクト: strickyak/superfractal
func main() {
	flag.Parse()

	// Special -l list command, listing short names for builtin IFSs.
	if *list {
		for k, v := range superfractal.Builtin {
			Printf("%s\t%s\n", k, v)
		}
		return
	}

	// Parse IFSs & construct initial Triptych.
	ifss := superfractal.ParseListOfIfsParams(*params)
	tree := &superfractal.CodeTree{
		Depth: *depth,
		IFSs:  ifss,
	}
	tree.Init(*seed)

	can := canvas.NewCanvas(*width, *height)
	tmp1 := make([]byte, *depth)
	tmp2 := make([]byte, *depth)
	for i := 0; i < *num; i++ {
		x, y := tree.RandomPoint(tmp1, tmp2)

		if *fuzz > 1 {
			xf := rand.Intn(*fuzz)
			yf := rand.Intn(*fuzz)
			can.FSet(x+float64(xf)/float64(*width), y+float64(yf)/float64(*height), canvas.White)
		} else {
			can.FSet(x, y, canvas.White)
		}
		/*
			for xf := 0; xf < *fuzz; xf++ {
			for yf := 0; yf < *fuzz; yf++ {
				can.FSet(x + float64(xf)/float64(*width), y + float64(yf)/float64(*height), canvas.White)
			}
			}
		*/
	}

	canvas.Say(*filename)
	fd, err := os.Create(*filename)
	if err != nil {
		panic(err)
	}
	can.WritePng(fd)
	fd.Close()
}