当前位置:网站首页>Learn go language 0x04: Code of exercises sliced in go language journey
Learn go language 0x04: Code of exercises sliced in go language journey
2022-04-23 11:07:00 【Love blog uncle】
* Exercises : operation slice display picture
Exercise location : https://tour.go-zh.org/moretypes/18
practice : section
Realization Pic. It should return a length of dy The section of , Each of these elements is a length of dx, Element type is uint8 The section of . When you run this program , It interprets each integer as a grayscale value ( ok , It's actually the blue value ) And display its corresponding image .
The choice of image is up to you . Several interesting functions include (x+y)/2, xy, x^y, xlog(y) and x%(y+1).
( Tips : You need to use a loop to allocate [][]uint8 Each of the []uint8; Please use uint8(intValue) Convert between types ; You may use math Functions in packages .)
* Code
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
img := make([][]uint8, dy)
for i := 0; i < dx; i++ {
img[i] = make([]uint8, dx)
}
for i := 0; i < dy; i++ {
for j := 0; j < dx; j++ {
img[i][j] = (uint8)((i+j)/2)
}
}
return img
}
func main() {
pic.Show(Pic)
}
Run on website , The display effect is :

If you run it on the command line , The result is :
notes : I am here cygwin Running in .
$ ./slice02.exe
IMAGE:iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADKElEQVR4nOzVoRHAMAzAQCfX/VduxjDQk8di+mb+mTlnyKB3vYBc9K4XkIs6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6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M6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANM6ANO+AAAA//9hKgMPVczXbQAAAABJRU5ErkJggg==" | base64.exe -d > pic.png
-
(i+j)/2According to the effect :

-
i*jDisplay effect of :

-
i^jThe effect of :

-
i*log(y)The effect of :

i*log(y), The code needs to be changed like this :
package main
import "golang.org/x/tour/pic"
import "math"
func Pic(dx, dy int) [][]uint8 {
img := make([][]uint8, dy)
for i := 0; i < dy; i++ {
img[i] = make([]uint8, dx)
}
for i := 0; i < dy; i++ {
for j := 0; j < dx; j++ {
img[i][j] = (uint8)(i*int(math.Log(float64(j))))
}
}
return img
}
func main() {
pic.Show(Pic)
}
i%(j+1)The effect of :

版权声明
本文为[Love blog uncle]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231102105986.html
边栏推荐
- Prevent SQL injection in web projects
- Precautions for latex formula
- MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
- Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
- Mysql database transaction example tutorial
- Source insight 4.0 FAQs
- Difference between pregnancy box and delivery box
- Mysql系列SQL查询语句书写顺序及执行顺序详解
- VIM + ctags + cscope development environment construction guide
- How to quickly query 10 million pieces of data in MySQL
猜你喜欢

redis优化系列(二)Redis主从原理、主从常用配置

vm设置静态虚拟机

Visualization Road (11) detailed explanation of Matplotlib color

Upgrade the functions available for cpolar intranet penetration

The songbird document editor will be open source: starting with but not limited to markdown

Promise详解

升级cpolar内网穿透能获得的功能

Visualization Road (10) detailed explanation of segmentation canvas function

语雀文档编辑器将开源:始于但不止于Markdown

Canvas详解
随机推荐
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
Intuitive understanding entropy
MBA-day5數學-應用題-工程問題
Source insight 4.0 FAQs
Visual common drawing (I) stacking diagram
VIM usage
Solution architect's small bag - 5 types of architecture diagrams
我的创作纪念日
Promise详解
比深度学习更值得信赖的模型ART
Precautions for latex formula
STM32接电机驱动,杜邦线供电,然后反烧问题
Excel · VBA custom function to obtain multiple cell values
VM set up static virtual machine
How to quickly query 10 million pieces of data in MySQL
学习 Go 语言 0x02:对切片 Slice 的理解
The songbird document editor will be open source: starting with but not limited to markdown
Mba-day5 Mathematics - application problems - engineering problems
Visual common drawing (V) scatter diagram
学习 Go 语言 0x05:《Go 语言之旅》中映射(map)的练习题代码