コード例 #1
0
ファイル: chaos.go プロジェクト: strickyak/superfractal
func (o IFS) WholeStep(src *canvas.Canvas, dest *canvas.Canvas) {
	wait := make(chan int)
	for k := 0; k < len(o.Choices); k++ {
		canvas.Say("    go Map", k)
		go o.Choices[k].MapImageTo(src, dest, k, wait)
	}
	for k := 0; k < len(o.Choices); k++ {
		w := <-wait
		canvas.Say("      Waited", w)
	}
}
コード例 #2
0
ファイル: chaos.go プロジェクト: strickyak/superfractal
// WholeGame
func (o IFS) WholeGame(src *canvas.Canvas, n int) *canvas.Canvas {
	t1 := src.Dup()
	t2 := canvas.NewCanvas(src.Width, src.Height)
	for i := 0; i < n; i++ {
		canvas.Say("WholeStep", i)
		o.WholeStep(t1, t2)
		t1, t2 = t2, t1
		t2.Fill(0, 0, t2.Width, t2.Height, canvas.Black)
	}
	return t1
}
コード例 #3
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
	}
}
コード例 #4
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()
}
コード例 #5
0
ファイル: super.go プロジェクト: strickyak/superfractal
// Execute one step building a superfractal, reading images from src,
// and writing on the receiver, which should be a new blank Triptych.
func (o *Triptych) SuperStep(src *Triptych, ifss []*IFS) {
	wait := make(chan int)
	for i := 0; i < len(o.Panels); i++ {
		dest := o.Panels[i]

		// Pick an IFS at random.
		ifs := ifss[rand.Intn(len(ifss))]

		// For each map in the ifs,
		for j := 0; j < len(ifs.Choices); j++ {
			affine := ifs.Choices[j]

			// pick a source, and map it onto the dest.
			src := src.Panels[rand.Intn(len(src.Panels))]
			go affine.MapImageTo(src, dest, i*1000+j, wait)
		}
		for j := 0; j < len(ifs.Choices); j++ {
			k := <-wait
			canvas.Say("Done", k)
		}
	}
}