Example #1
0
func (o *drawing) init() {
	if o.canvas == nil {
		o.canvas = canvas.NewCanvas(WIDTH, HEIGHT)
		o.px = 0.0 + MARGIN
		o.py = 100.0 - MARGIN
	}
}
Example #2
0
func main() {
	flag.Parse()

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

	c := canvas.NewCanvas(*width, *height)
	if *grid {
		c.Grid(*width/10, canvas.RGB(100, 100, 100))
	}
	ifs := superfractal.ParseIfsParams(*params)
	switch *style {
	case 1: // Whole.
		c.Fill(0, 0, *width, *height, canvas.Blue)
		// c.WritePng(os.Stdout)
		// return
		c = ifs.WholeGame(c, *num)
	case 0: // Chaos.
		ifs.ChaosGame(c, *num, canvas.Green)
	}
	c.WritePng(os.Stdout)
}
Example #3
0
func NewTriptych(numPanels, width, height int) *Triptych {
	z := &Triptych{
		Panels: make([]*canvas.Canvas, numPanels),
	}
	for i := 0; i < numPanels; i++ {
		z.Panels[i] = canvas.NewCanvas(width, height)
	}
	return z
}
Example #4
0
// 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
}
Example #5
0
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()
}
Example #6
0
func (h H) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
	strs := notnum.Split(r.URL.Path, -1)
	var nums []float64
	for _, s := range strs {
		if s == "" {
			continue
		}
		f, err := strconv.ParseFloat(s, 64)
		if err != nil {
			panic(err)
		}
		nums = append(nums, f)
	}

	can := canvas.NewCanvas(*WIDTH, *HEIGHT)
	can.Grid(50, canvas.RGB(20, 20, 20))

	for i := 0; i < len(nums)-8; i += 9 {
		x1 := int(nums[i+0])
		y1 := int(nums[i+1])
		x2 := int(nums[i+2])
		y2 := int(nums[i+3])
		x3 := int(nums[i+4])
		y3 := int(nums[i+5])

		red := byte(nums[i+6])
		green := byte(nums[i+7])
		blue := byte(nums[i+8])

		can.PaintTriangle(x1, y1, x2, y2, x3, y3, canvas.RGB(red, green, blue))
	}

	w.Header().Set("Content-Type", "image/png")
	can.WritePng(w)
}