优化 wz 生命游戏代码的中文范

This commit is contained in:
chai2010
2025-10-25 20:23:44 +08:00
parent fd608db4dd
commit 46ed385c78
14 changed files with 110 additions and 27 deletions

View File

@@ -0,0 +1,7 @@
+---+ +---+
| o | | o |
| +----+ |
| |
| 1010 |
| |
+------------+

View File

@@ -13,9 +13,12 @@ func PrintLogoSvg() {
}
func PrintLogo(more bool) {
if is1024Day() {
switch {
case is1010Day():
fmt.Print(logo1010)
case is1024Day():
fmt.Print(logo1024)
} else {
default:
fmt.Print(logo)
}
@@ -25,6 +28,11 @@ func PrintLogo(more bool) {
fmt.Println()
}
func is1010Day() bool {
_, month, day := time.Now().Date()
return month == 10 && day == 10
}
func is1024Day() bool {
_, month, day := time.Now().Date()
return month == 10 && day == 24
@@ -40,6 +48,16 @@ const logo = `
+------------+
`
const logo1010 = `
+---+ +---+
| o | | o |
| +----+ |
| |
| 1010 |
| |
+------------+
`
const logo1024 = `
+---+ +---+
| o | | o |

View File

@@ -440,7 +440,7 @@ func (check *Checker) collectObjects() {
case *ast.TypeSpec:
obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Name, nil)
obj.setNode(s)
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: false})
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: s.Assign.IsValid()})
if s.Doc == nil {
if d.Lparen == token.NoPos && d.Doc != nil {

View File

@@ -1,10 +1,10 @@
注: 版权 @2025 life 作者。保留所有权利。
引入 "image"
引入 "image/color"
引入 "js/canvas"
引入 "数学/随机数"
引入 "洪荒"
引入 "图像"
引入 "图像/颜色"
引入 "假死门/画布"
引入 "数学/随机数"
全局:
宽度 :整型 = 0
@@ -12,27 +12,27 @@
暂停中 :布尔 = 假
细胞状态甲 :*image·Gray = 空
细胞状态乙 :*image·Gray = 空
细胞状态快照 :*image·RGBA = 空
细胞状态甲 :*图像·灰色图像 = 空
细胞状态乙 :*图像·灰色图像 = 空
细胞状态快照 :*图像·彩色图像 = 空
画布上下文 :canvas·Context2D
画布上下文 :画布·平面上下文
完毕
函数·初始化(宽, 高, 随机火种: 整型):
宽度 = 宽
高度 = 高
细胞状态甲 = image·NewGray(宽, 高)
细胞状态乙 = image·NewGray(宽, 高)
细胞状态快照 = image·NewRGBA(宽, 高)
细胞状态甲 = 图像·新建灰色图像(宽, 高)
细胞状态乙 = 图像·新建灰色图像(宽, 高)
细胞状态快照 = 图像·新建彩色图像(宽, 高)
随机数·点火(长整型(随机火种))
循环 i := 0; i < 宽度*高度; i++:
循环 := 0; < 宽度*高度; ++:
如果 (随机数·整数() % 2) != 0:
细胞状态甲·Pix[i] = color·Gray(1)
细胞状态甲·Pix[] = 颜色·灰色(1)
否则:
细胞状态甲·Pix[i] = color·Gray(0)
细胞状态甲·Pix[] = 颜色·灰色(0)
完毕
完毕
完毕
@@ -61,16 +61,16 @@
如果 细胞状态甲·Pix[竖*宽度+横] != 0:
找辙 邻居数量:
有辙 2, 3:
细胞状态乙·Pix[竖*宽度+横] = color·Gray(1)
细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(1)
没辙:
细胞状态乙·Pix[竖*宽度+横] = color·Gray(0)
细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(0)
完毕
否则:
找辙 邻居数量:
有辙 3:
细胞状态乙·Pix[竖*宽度+横] = color·Gray(1)
细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(1)
没辙:
细胞状态乙·Pix[竖*宽度+横] = color·Gray(0)
细胞状态乙·Pix[竖*宽度+横] = 颜色·灰色(0)
完毕
完毕
完毕
@@ -92,15 +92,15 @@
循环 横 := 0; 横 < 宽度; 横++:
循环 竖 := 0; 竖 < 高度; 竖++:
如果 细胞状态甲·Pix[竖*宽度+横] != 0:
细胞状态快照·SetRGBA(横, 竖, 0xFF0000FF)
细胞状态快照·设置彩色(横, 竖, 0xFF0000FF)
否则:
细胞状态快照·SetRGBA(横, 竖, 0xFFFFFFFF)
细胞状态快照·设置彩色(横, 竖, 0xFFFFFFFF)
完毕
完毕
完毕
注: 绘制到 Canvas
画布上下文·PutImageData(
画布上下文·装填图像数据(
洪荒·原生(细胞状态快照·Pix), 0, 0, 0, 0,
单精(宽度), 单精(高度),
)

View File

@@ -0,0 +1,9 @@
注: 这是注释
引入 "菠萝"
函数·主控:
甲 := 菠萝·创建我的整型(100)
乙 := 菠萝·创建我的整型(42)
输出(甲 + 乙)
完毕

View File

@@ -15,6 +15,10 @@ type MyInt :struct {
V: int
}
func NewMyInt(x: int) => MyInt {
return MyInt{V: x}
}
#wa:generic AddF64
func MyInt.Add(a: int) {
this.V += a

View File

@@ -34,3 +34,7 @@ func RGBA.RGBAAt(x, y: int) => color.RGBA {
func RGBA.SetRGBA(x, y: int, c: color.RGBA) {
this.Pix[y*this.Width+x] = c
}
func RGBA.设置彩色(x, y: int, c: color.RGBA) {
this.Pix[y*this.Width+x] = c
}

View File

@@ -611,6 +611,10 @@ func Context2D.PutImageData(imagedata: []u8, dx, dy: f32, dirtyX, dirtyY, dirtyW
jsPutImageData(this.GetHandle(), imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
}
func Context2D.装填图像数据(imagedata: []u8, dx, dy: f32, dirtyX, dirtyY, dirtyWidth, dirtyHeight: f32) {
jsPutImageData(this.GetHandle(), imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
}
/*****************************************
* *
* Synthesis *

View File

@@ -190,7 +190,8 @@ var stdPkgs = []string{
}
var wzStdPkgs = []string{
"",
"菠萝", // apple
"书", // fmt
"图像", // image
"图像/颜色", // image/color
"数学/随机数", // math/rand

View File

@@ -3,6 +3,10 @@
引入 "js/canvas"
函数·查询画布(代号: 字串) => (canvas·Canvas, 布尔):
类型·画布 = canvas·Canvas
类型·平面上下文 = canvas·Context2D
函数·查询画布(代号: 字串) => (画布, 布尔):
返回 canvas·QueryCanvas(代号)
完毕

View File

@@ -0,0 +1,15 @@
注: Copyright (C) 2025 武汉凹语言科技有限公司
注: SPDX-License-Identifier: MIT
引入 "image"
类型·灰色图像 = image·Gray
类型·彩色图像 = image·RGBA
函数·新建灰色图像(宽, 高: 整型) => *灰色图像:
返回 image·NewGray(宽, 高)
完毕
函数·新建彩色图像(宽, 高: 整型) => *彩色图像:
返回 image·NewRGBA(宽, 高)
完毕

View File

@@ -1,2 +1,6 @@
注: Copyright (C) 2024 武汉凹语言科技有限公司
注: Copyright (C) 2025 武汉凹语言科技有限公司
注: SPDX-License-Identifier: MIT
引入 "image/color"
类型·灰色 = color.Gray

View File

@@ -0,0 +1,3 @@
# 菠萝包
这是 apple 包的中文版本。

View File

@@ -0,0 +1,10 @@
注: Copyright (C) 2025 武汉凹语言科技有限公司
注: SPDX-License-Identifier: MIT
引入 "apple"
类型·我的整型 = apple·MyInt
函数·创建我的整型(某: 整型) => 我的整型:
返回 apple·NewMyInt(某)
完毕