Add tests for examples from Nim in Action.
This commit is contained in:
parent
a585748f27
commit
7889c03cbc
34 changed files with 1213 additions and 0 deletions
19
tests/niminaction/Chapter8/canvas/canvas.nim
Normal file
19
tests/niminaction/Chapter8/canvas/canvas.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import dom
|
||||
|
||||
type
|
||||
CanvasRenderingContext* = ref object
|
||||
fillStyle* {.importc.}: cstring
|
||||
strokeStyle* {.importc.}: cstring
|
||||
|
||||
{.push importcpp.}
|
||||
|
||||
proc getContext*(canvasElement: Element,
|
||||
contextType: cstring): CanvasRenderingContext
|
||||
|
||||
proc fillRect*(context: CanvasRenderingContext, x, y, width, height: int)
|
||||
|
||||
proc moveTo*(context: CanvasRenderingContext, x, y: int)
|
||||
|
||||
proc lineTo*(context: CanvasRenderingContext, x, y: int)
|
||||
|
||||
proc stroke*(context: CanvasRenderingContext)
|
||||
19
tests/niminaction/Chapter8/canvas/canvas_test.nim
Normal file
19
tests/niminaction/Chapter8/canvas/canvas_test.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import canvas, dom
|
||||
|
||||
proc onLoad() {.exportc.} =
|
||||
var canvas = document.getElementById("canvas").EmbedElement
|
||||
canvas.width = window.innerWidth
|
||||
canvas.height = window.innerHeight
|
||||
var ctx = canvas.getContext("2d")
|
||||
|
||||
ctx.fillStyle = "#1d4099"
|
||||
ctx.fillRect(0, 0, window.innerWidth, window.innerHeight)
|
||||
|
||||
ctx.strokeStyle = "#ffffff"
|
||||
let letterWidth = 100
|
||||
let letterLeftPos = (window.innerWidth div 2) - (letterWidth div 2)
|
||||
ctx.moveTo(letterLeftPos, 320)
|
||||
ctx.lineTo(letterLeftPos, 110)
|
||||
ctx.lineTo(letterLeftPos + letterWidth, 320)
|
||||
ctx.lineTo(letterLeftPos + letterWidth, 110)
|
||||
ctx.stroke()
|
||||
Loading…
Add table
Add a link
Reference in a new issue