Working frame generation
This commit is contained in:
parent
8a06d84ca2
commit
f18eb93c32
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
|||||||
*.gif
|
*.gif
|
||||||
*.jpg
|
*.jpg
|
||||||
*.jpeg
|
*.jpeg
|
||||||
|
a.out
|
||||||
|
56
go1/main.go
56
go1/main.go
@ -3,12 +3,56 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ungerik/go3d/vec3"
|
"github.com/ungerik/go3d/vec3"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
// Clamp a float value to the given range
|
||||||
fmt.Printf("Hello world")
|
func fclamp(val float32, minval int, maxval int) int {
|
||||||
thing := vec3.T{
|
return max(minval, min(maxval, int(val)))
|
||||||
0, 0, 0,
|
}
|
||||||
}
|
|
||||||
fmt.Printf("Thing: %v", thing)
|
func main() {
|
||||||
|
log.Printf("Program begin")
|
||||||
|
const (
|
||||||
|
width = 1024
|
||||||
|
height = 768
|
||||||
|
colmax = 255
|
||||||
|
)
|
||||||
|
framebuffer := make([]vec3.T, width*height)
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
for y := range height {
|
||||||
|
for x := range width {
|
||||||
|
framebuffer[x+y*width] = vec3.T{
|
||||||
|
float32(y) / float32(height),
|
||||||
|
float32(x) / float32(width),
|
||||||
|
0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Printf("Generate frame took %dms", time.Since(now).Milliseconds())
|
||||||
|
|
||||||
|
fmt.Printf("P3\n%d %d\n%d\n# Image contents\n", width, height, colmax)
|
||||||
|
|
||||||
|
var buffer strings.Builder
|
||||||
|
now = time.Now()
|
||||||
|
|
||||||
|
for i := range height * width {
|
||||||
|
fb := framebuffer[i]
|
||||||
|
buffer.WriteString(fmt.Sprintf("%d %d %d\t",
|
||||||
|
fclamp(colmax*fb[0], 0, colmax),
|
||||||
|
fclamp(colmax*fb[1], 0, colmax),
|
||||||
|
fclamp(colmax*fb[2], 0, colmax),
|
||||||
|
))
|
||||||
|
if i&63 == 63 {
|
||||||
|
buffer.WriteRune('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Conversion took %dms", time.Since(now).Milliseconds())
|
||||||
|
|
||||||
|
fmt.Printf(buffer.String())
|
||||||
|
fmt.Printf("\n# Image end\n")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user