draw using color palette rather than RGB directly.
This commit is contained in:
parent
82b0b0a386
commit
575791cfc1
5 changed files with 277 additions and 14 deletions
|
|
@ -6,14 +6,14 @@ import (
|
|||
"github.com/pnx/go-raytracer/world"
|
||||
)
|
||||
|
||||
func DrawColumn(ctx *graphics.Context, x int32, wall_h int32, color math.Color) {
|
||||
func DrawColumn(ctx *graphics.Context, x int32, wall_h int32, color byte) {
|
||||
if wall_h < ctx.Height() {
|
||||
y1 := (ctx.Height() - wall_h) / 2
|
||||
y2 := (ctx.Height() + wall_h) / 2
|
||||
|
||||
// Top
|
||||
// renderer.SetDrawColor(90, 90, 0, 255)
|
||||
ctx.DrawLine(x, 0, int32(x), y1, math.Color{R: 90, G: 90, B: 0, A: 255})
|
||||
ctx.DrawLine(x, 0, int32(x), y1, 0x1D)
|
||||
|
||||
// // Middle
|
||||
// renderer.SetDrawColor(color.R, color.G, color.B, color.A)
|
||||
|
|
@ -22,7 +22,7 @@ func DrawColumn(ctx *graphics.Context, x int32, wall_h int32, color math.Color)
|
|||
// Bottom
|
||||
if y2 < ctx.Height() {
|
||||
// renderer.SetDrawColor(50, 50, 50, 255)
|
||||
ctx.DrawLine(x, y2, int32(x), ctx.Height(), math.Color{R: 50, G: 50, B: 50, A: 255})
|
||||
ctx.DrawLine(x, y2, int32(x), ctx.Height(), 0x19)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -31,15 +31,15 @@ func DrawColumn(ctx *graphics.Context, x int32, wall_h int32, color math.Color)
|
|||
ctx.DrawLine(x, 0, int32(x), ctx.Height(), color)
|
||||
}
|
||||
|
||||
func DrawScene(ctx *graphics.Context, camera math.Transform, level *world.Level, colorMap []math.Color) {
|
||||
func DrawScene(ctx *graphics.Context, camera math.Transform, level *world.Level) {
|
||||
for x := range ctx.Width() {
|
||||
result := CastRay(camera, level, int(x), int(ctx.Width()))
|
||||
lineHeight := int(float64(ctx.Height()) / result.Distance)
|
||||
|
||||
color := colorMap[level.Cell(int(result.Cell.X), int(result.Cell.Y))-1]
|
||||
color := level.Cell(int(result.Cell.X), int(result.Cell.Y))
|
||||
|
||||
if result.Side > 0 {
|
||||
color = color.Shade(2)
|
||||
color += 0x8
|
||||
}
|
||||
|
||||
DrawColumn(ctx, int32(x), int32(lineHeight), color)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue