mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:34:15 +08:00
36 lines
595 B
Go
36 lines
595 B
Go
// multidim_array.go
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
const (
|
|
WIDTH = 1920
|
|
HEIGHT = 1080
|
|
// WIDTH = 5
|
|
// HEIGHT = 4
|
|
)
|
|
|
|
type pixel int
|
|
var screen [WIDTH][HEIGHT]pixel
|
|
|
|
func main() {
|
|
for y := 0; y < HEIGHT; y++ {
|
|
for x := 0; x < WIDTH; x++ {
|
|
screen[x][y] = 0
|
|
}
|
|
}
|
|
fmt.Println(screen)
|
|
|
|
for row := range screen {
|
|
for column := range screen[0] {
|
|
screen[row][column] = 1
|
|
}
|
|
}
|
|
|
|
fmt.Println(screen)
|
|
}
|
|
/* Output for WIDTH = 5 and HEIGHT = 4:
|
|
[[0 0 0 0] [0 0 0 0] [0 0 0 0] [0 0 0 0] [0 0 0 0]]
|
|
[[1 1 1 1] [1 1 1 1] [1 1 1 1] [1 1 1 1] [1 1 1 1]]
|
|
*/
|