Skip to content

Commit 595a6f3

Browse files
committed
更新 canvas 例子
1 parent 4c3a2d1 commit 595a6f3

File tree

10 files changed

+65
-121
lines changed

10 files changed

+65
-121
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/output/*.wasm
2+
/output/*.wat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
3+
<title>凹语言绘制 Logo 例子</title>
4+
5+
<div style="text-align: center;">
6+
<canvas id="canvas" width="400" height="400"></canvas>
7+
</div>
8+
9+
<script type="text/javascript" src="./logo.js"></script>
10+
11+
<script>
12+
let app = new WaApp();
13+
app.init().then((result) => {
14+
app.main();
15+
})
16+
</script>
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// 版权 @2023 logo 作者。保留所有权利。
2+
3+
import "js/canvas"
4+
5+
func main {
6+
println("你好,凹语言!")
7+
8+
c, _ := canvas.QueryCanvas("canvas")
9+
ctx, _ := c.GetContext2D()
10+
11+
ctx.SetFillStyle("green")
12+
ctx.FillRect(50, 10, 300, 10)
13+
ctx.FillText("https://wa-lang.org/", 150, 30)
14+
15+
drawWaLogo(ctx)
16+
}
17+
18+
func drawWaLogo(ctx: canvas.Context2D) {
19+
ctx.MoveTo(50, 50)
20+
ctx.LineTo(150, 50)
21+
ctx.LineTo(150, 150)
22+
ctx.LineTo(250, 150)
23+
ctx.LineTo(250, 50)
24+
ctx.LineTo(350, 50)
25+
ctx.LineTo(350, 350)
26+
ctx.LineTo(50, 350)
27+
ctx.LineTo(50, 50)
28+
29+
// O O
30+
ctx.Rect(95, 95, 10, 10)
31+
ctx.Rect(295, 95, 10, 10)
32+
33+
// W
34+
ctx.MoveTo(200, 230)
35+
ctx.LineTo(200-34, 230+34)
36+
ctx.LineTo(200-34-34, 230+34-34)
37+
38+
ctx.MoveTo(200, 230)
39+
ctx.LineTo(200+34, 230+34)
40+
ctx.LineTo(200+34+34, 230+34-34)
41+
42+
ctx.Stroke()
43+
}

waroot/examples/canvas-logo/wa.mod

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 版权 @2023 hello 作者。保留所有权利。
2+
3+
name = "logo"
4+
pkgpath = "myapp"

waroot/examples/canvas/.gitignore

-1
This file was deleted.

waroot/examples/canvas/Makefile

-7
This file was deleted.

waroot/examples/canvas/index.html

-4
This file was deleted.

waroot/examples/canvas/index.js

-43
This file was deleted.

waroot/examples/canvas/src/main.wa

-52
This file was deleted.

waroot/examples/canvas/wa.mod

-14
This file was deleted.

0 commit comments

Comments
 (0)