当前位置:网站首页>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
边栏推荐
- Structure of C language (Advanced)
- An interesting interview question
- Data analysis learning (I) data analysis and numpy Foundation
- Precautions for latex formula
- PlatoFarm推出正式版游戏经济模型的特点分析
- Typora operation skill description (I) md
- vm设置静态虚拟机
- MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
- mysql分表之后如何平滑上线详解
- MySQL分区表实现按月份归类
猜你喜欢

Mysql8.0安装指南

Visual Road (XII) detailed explanation of collection class

Microsoft Access database using PHP PDO ODBC sample

GO接口使用

Visual common drawing (III) area map

Jupyter Lab 十大高生产力插件

Typora operation skill description (I) md

Ueditor -- limitation of 4m size of image upload component

Source insight 4.0 FAQs

Cygwin 中的 rename 用法
随机推荐
Visual common drawing (IV) histogram
精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
@valid,@Validated 的学习笔记
ConstraintLayout布局
web三大组件(Servlet,Filter,Listener)
Excel·VBA自定义函数获取单元格多数值
GO接口使用
PlatoFarm推出正式版游戏经济模型的特点分析
MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
Visual solutions to common problems (VIII) mathematical formulas
第六站神京门户-------手机号码的转换
The songbird document editor will be open source: starting with but not limited to markdown
Pytorch implementation of transformer
Visual common drawing (I) stacking diagram
@Valid, @ validated learning notes
Database management software sqlpro for SQLite for Mac 2022.30
Excel · VBA array bubble sorting function
MySQL sorting feature details
R-Drop:更强大的Dropout正则方法
Implementation of inserting millions of data into MySQL database in 10 seconds