This example is taken from the Sitepoint book, JavaScript? (cite required).
Last active
February 18, 2018 22:48
-
-
Save mathdoodle/fef1199a33a46b34764d to your computer and use it in GitHub Desktop.
Ice Cream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="https://jspm.io/system@0.19.34.js"></script> | |
<link rel='stylesheet' href='style.css'> | |
</head> | |
<body> | |
<canvas id='my-canvas'></canvas> | |
<script> | |
System.defaultJSExtensions = true | |
System.import('./script') | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"uuid": "ba223414-560d-4bac-b702-894c8e9a3788", | |
"description": "Ice Cream", | |
"dependencies": {}, | |
"name": "ice-cream", | |
"version": "1.0.0", | |
"author": "David Geo Holmes", | |
"keywords": [ | |
"HTML5", | |
"Canvas", | |
"mathdoodle" | |
], | |
"linting": true, | |
"hideConfigFiles": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.getElementById('my-canvas') as HTMLCanvasElement | |
canvas.width = 400 | |
canvas.height = 400 | |
canvas.style.left = '0px' | |
canvas.style.top = '0px' | |
canvas.style.height = '400px' | |
canvas.style.width = '400px' | |
const context = canvas.getContext('2d') as CanvasRenderingContext2D | |
context.beginPath() | |
context.moveTo(150, 100) | |
context.lineTo(200, 225) | |
context.lineTo(250, 100) | |
context.fillStyle = '#d3bea5' | |
context.fill() | |
context.stroke() | |
context.beginPath() | |
context.arc(200, 100, 50, 0, Math.PI, true) | |
context.fillStyle = '#fb6cf9' | |
context.fill() | |
context.closePath() | |
context.stroke() | |
export function toHexString(c: number): string { | |
const hex = c.toString(16) | |
return hex.length === 1 ? "0" + hex : hex | |
} | |
export function rgb(r: number, g: number, b: number): string { | |
return "#" + toHexString(r) + toHexString(g) + toHexString(b) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: blue; | |
} | |
#my-canvas { | |
position: absolute; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"allowJs": true, | |
"checkJs": true, | |
"declaration": true, | |
"emitDecoratorMetadata": true, | |
"experimentalDecorators": true, | |
"jsx": "react", | |
"module": "system", | |
"noImplicitAny": true, | |
"noImplicitReturns": true, | |
"noImplicitThis": true, | |
"noUnusedLocals": true, | |
"noUnusedParameters": true, | |
"preserveConstEnums": true, | |
"removeComments": false, | |
"skipLibCheck": true, | |
"sourceMap": true, | |
"strictNullChecks": true, | |
"suppressImplicitAnyIndexErrors": true, | |
"target": "es5", | |
"traceResolution": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": { | |
"array-type": [ | |
true, | |
"array" | |
], | |
"curly": false, | |
"comment-format": [ | |
true, | |
"check-space" | |
], | |
"eofline": true, | |
"forin": true, | |
"jsdoc-format": true, | |
"new-parens": true, | |
"no-conditional-assignment": false, | |
"no-consecutive-blank-lines": true, | |
"no-construct": true, | |
"no-for-in-array": true, | |
"no-inferrable-types": [ | |
true | |
], | |
"no-magic-numbers": false, | |
"no-shadowed-variable": true, | |
"no-string-throw": true, | |
"no-trailing-whitespace": [ | |
true, | |
"ignore-jsdoc" | |
], | |
"no-var-keyword": true, | |
"one-variable-per-declaration": [ | |
true, | |
"ignore-for-loop" | |
], | |
"prefer-const": true, | |
"prefer-for-of": true, | |
"prefer-function-over-method": false, | |
"prefer-method-signature": true, | |
"radix": true, | |
"semicolon": [ | |
true, | |
"never" | |
], | |
"trailing-comma": [ | |
true, | |
{ | |
"multiline": "never", | |
"singleline": "never" | |
} | |
], | |
"triple-equals": true, | |
"use-isnan": true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment