package main import "fmt" import "os" //for handling the logging output func main() { // Image var image_width int = 256 var image_height int = 256 // Rendering fmt.Println("P3") fmt.Println(image_width, " ", image_height, "\n255") for j := 0; j < image_height; j++ { fmt.Fprintf(os.Stderr, "\rScanlines remaining: %d ", image_height-j) for i := 0; i < image_width; i++ { r := float32(i) / float32(image_width - 1) g := float32(j) / float32(image_height-1) b := 0 ir := int(r * 256) ig := int(g * 256) ib := int(b * 256) fmt.Println(ir, " ", ig, " ", ib) } } // INFO: The pixels are written out in rows. // Image file can be created with // go run main.go > image.ppm to save image }