husonet | Tarih: 12.09.2019
Go dili ve Slices egzersiz
Go dili slices konusuyla ilgili google egzersizini yapalım
Go dili ve Slices konusuyla ilgili https://tour.golang.org/moretypes/18 sayfasındaki egzersizle ilgili aşağıdaki örneği inceleyebilirsiniz.
package main
import (
"golang.org/x/tour/pic"
)
func Pic(dx, dy int) [][]uint8 {
s := make([][]uint8, dy)
for y := range s {
s[y] = make([]uint8, dx)
s[y][10] = uint8(255)
s[y][11] = uint8(100)
s[y][12] = uint8(100)
s[y][13] = uint8(100)
s[y][14] = uint8(100)
s[y][15] = uint8(100)
s[y][16] = uint8(255)
for x := range s[y] {
switch y {
case 10:
{
if uint8(s[10][x]) == uint8(255) {
s[10][11] = uint8(100)
s[10][12] = uint8(100)
s[10][13] = uint8(100)
s[10][14] = uint8(100)
s[10][15] = uint8(100)
} else {
s[10][x] = uint8(255)
}
}
case 11:
s[11][x] = uint8(100)
case 12:
s[12][x] = uint8(100)
case 13:
s[13][x] = uint8(100)
case 14:
s[14][x] = uint8(100)
case 15:
s[15][x] = uint8(100)
case 16:
{
if uint8(s[16][x]) == uint8(255) {
s[16][11] = uint8(100)
s[16][12] = uint8(100)
s[16][13] = uint8(100)
s[16][14] = uint8(100)
s[16][15] = uint8(100)
} else {
s[16][x] = uint8(255)
}
}
}
}
}
return s
}
func main() {
pic.Show(Pic)
}
Aşağıdaki şekilde base64 kodunu browsera yapıştırım imagı görüntüleyebilirsiniz.
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAAC+ElEQVR4nOzbQWqFMBRA0aS41O+qXGw6LrUWOrHfe85QCDjwwsPwtjHW+NlaY9+/PDmOMefFCXgnH3e/ANxJAKQJgDQBkCYA0gRAmgBIEwBpAiBtW1cXwef+cAT+p/l6+ZzpMgKRJgDSBECaAEib67d/Ot/3AeAxtuvtltM6LMTwGEYg0gRAmgBIEwBpAiBNAKQJgDQBkCYA0gRAmgBIEwBpAiBNAKQJgDQBkCYA0gRAmgBIEw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