Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created April 18, 2020 15:58
Show Gist options
  • Save amatiasq/0c5ff9d569d9217e7cc889a08b2b4472 to your computer and use it in GitHub Desktop.
Save amatiasq/0c5ff9d569d9217e7cc889a08b2b4472 to your computer and use it in GitHub Desktop.
Created with Fable REPL
html, body {
margin: 0;
padding: 0;
}
module BasicCanvas
open Fable.Core
open Fable.Core.JsInterop
open Browser.Types
open Browser
let init() =
let width = document.body.offsetWidth
let height = document.body.offsetHeight
let canvas = document.querySelector(".view") :?> HTMLCanvasElement
canvas.width <- width;
canvas.height <- height;
let ctx = canvas.getContext_2d()
// The (!^) operator checks and casts a value to an Erased Union type
// See http://fable.io/docs/interacting.html#Erase-attribute
ctx.fillStyle <- !^"rgb(0,0,0)"
ctx.fillRect(0., 0., width, height)
ctx.fillStyle <- !^"rgb(200,0,0, 0.5)"
ctx.fillRect (10., 10., 55., 50.)
ctx.fillStyle <- !^"rgba(0, 0, 200, 0.5)"
ctx.fillRect (30., 30., 55., 50.)
ctx.fillStyle <- !^"rgba(255, 255, 255, 0.5)"
ctx.font <- "30px Arial"
ctx.fillText ("Hack and Craft", 100., 100., 1000.)
init()
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<canvas class="view" width="400" height="400"></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment