First chapter done
This commit is contained in:
parent
2d3c46c0fe
commit
49eec396d5
2 changed files with 65570 additions and 0 deletions
31
main.go
Normal file
31
main.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue