-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(graphics): add graphics package
- Loading branch information
1 parent
cb65f6f
commit aa55905
Showing
5 changed files
with
79 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package graphics | ||
|
||
const width = 0x40 | ||
const height = 0x20 | ||
|
||
type Graphics struct { | ||
display [height][width]byte | ||
Width int | ||
Height int | ||
} | ||
|
||
func NewGraphics() *Graphics { | ||
return &Graphics{ | ||
Width: width, | ||
Height: height, | ||
} | ||
} | ||
|
||
func (g *Graphics) Clear() { | ||
for i := 0; i < g.Height; i++ { | ||
for j := 0; j < g.Width; j++ { | ||
g.display[i][j] = 0x00 | ||
} | ||
} | ||
} | ||
|
||
func (g *Graphics) GetPixel(y int, x int) byte { | ||
return g.display[y][x] | ||
} | ||
|
||
func (g *Graphics) SetPixel(y int, x int, b byte) { | ||
g.display[y][x] = b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package graphics_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gaoliveira21/chip8/core/graphics" | ||
) | ||
|
||
func TestSetAndGetPixel(t *testing.T) { | ||
g := graphics.NewGraphics() | ||
|
||
g.SetPixel(0, 0, 0x1) | ||
|
||
if g.GetPixel(0, 0) != 0x1 { | ||
t.Errorf("graphics.Display[0][0] = 0x%X; expected 0x01", g.GetPixel(0, 0)) | ||
} | ||
} |