func main() {
	// Example file used here is Lenna50.jpg from the task "Percentage
	// difference between images" converted with with the command
	// convert Lenna50.jpg -colorspace gray Lenna50.ppm
	// It shows very obvious compression artifacts when viewed at higher
	// zoom factors.
	b, err := raster.ReadPpmFile("Lenna50.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
	g0 = b.Grmap()
	w, h := g0.Extent()
	g1 = raster.NewGrmap(w, h)
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			g1.SetPx(x, y, median(x, y))
		}
	}
	// side by side comparison with input file shows compression artifacts
	// greatly smoothed over, although at some loss of contrast.
	err = g1.Bitmap().WritePpmFile("median.ppm")
	if err != nil {
		fmt.Println(err)
	}
}
func main() {
	g = raster.NewGrmap(w, h)
	// off center seed position makes pleasingly asymetrical tree
	g.SetPx(w/3, h/3, frost)
	var x, y int
generate:
	for a := 0; a < n; {
		// generate random position for new particle
		x, y = rand.Intn(w), rand.Intn(h)
		switch p, ok := g.GetPx(x, y); p {
		case frost:
			// position is already set.  find a nearby free position.
			for p == frost {
				x += rand.Intn(3) - 1
				y += rand.Intn(3) - 1
				p, ok = g.GetPx(x, y)

				// execpt if we run out of bounds, consider the particle lost.
				if !ok {
					continue generate
				}
			}
		default:
			// else particle is in free space.  let it wander
			// until it touches tree
			for !hasNeighbor(x, y) {
				x += rand.Intn(3) - 1
				y += rand.Intn(3) - 1
				// but again, if it wanders out of bounds consider it lost.
				_, ok = g.GetPx(x, y)
				if !ok {
					continue generate
				}
			}
		}
		// x, y now specify a free position toucing the tree.
		g.SetPx(x, y, frost)
		a++
		// progress indicator
		if a%100 == 0 {
			fmt.Println(a, "of", n)
		}
	}
	g.Bitmap().WritePpmFile("tree.ppm")
}
func main() {
	g := raster.NewGrmap(400, 300)
	g.AaLine(7.4, 12.3, 307, 122.5)
	g.AaLine(177.4, 12.3, 127, 222.5)
	g.Bitmap().WritePpmFile("wu.ppm")
}
func main() {
	g := raster.NewGrmap(width, height)
	ftree(g, width/2, height*9/10, length, 0, depth)
	g.Bitmap().WritePpmFile("ftree.ppm")
}