// Generate a sort of half-sphere as a ppm file. package main import "fmt" import "math" func pic(colors int, size int) [][]uint8 { var ySlice [][]uint8 var sqrt2 = math.Sqrt(2) var floatColors = float64(colors) var floatSize = float64(size) var halfSize = floatSize / 2.0 for x := 0.0; x < floatSize; x++ { // fmt.Println("x:", x) var xSlice []uint8 for y := 0.0; y < floatSize; y++ { // fmt.Println("y:", y) var xCoord = float64(x-halfSize) / halfSize var yCoord = float64(y-halfSize) / halfSize var zCoord = math.Sqrt(xCoord*xCoord+yCoord*yCoord) / sqrt2 var color = uint(zCoord * (floatColors - 1.0)) xSlice = append(xSlice, uint8(color)) } ySlice = append(ySlice, xSlice) } // fmt.Println(ySlice) return ySlice } func main() { var size = 200 var colors = 256 var slice = pic(colors, size) fmt.Println("P3") fmt.Println(size, size) fmt.Println(colors) for _, yValue := range slice { for _, xValue := range yValue { fmt.Print(xValue, " ", xValue, " ", xValue, " ") } fmt.Println() } }