Last active
August 29, 2015 14:22
-
-
Save mathdoodle/b2c5609b25bba3c000da to your computer and use it in GitHub Desktop.
Measure
This file contains hidden or 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": "a7bd5e81-da71-4f0b-a669-431e324f6e9e", | |
"description": "Measure", | |
"dependencies": { | |
"DomReady": "latest", | |
"davinci-blade": "1.1.1" | |
}, | |
"operatorOverloading": true | |
} |
This file contains hidden or 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> | |
<style> | |
/* STYLE-MARKER */ | |
</style> | |
<!-- SCRIPTS-MARKER --> | |
</head> | |
<body> | |
<pre id='output'></pre> | |
<script> | |
// CODE-MARKER | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
DomReady.ready(function() { | |
try { | |
calculation(); | |
} | |
catch(e) { | |
function red(arg: any) { | |
return "<span style='color:red'>" + arg + "</span>"; | |
} | |
println(red(e.message)); | |
} | |
}); | |
/** | |
* Units of Measure and Operator Overloading | |
*/ | |
function calculation() { | |
var space = blade.e3ga; | |
var e1 = space.e1; | |
var e2 = space.e2; | |
var units = space.units; | |
var meter = units.meter; | |
var newton = units.newton; | |
var kilogram = units.kilogram; | |
var second = units.second; | |
var yard = units.yard; | |
var mile = units.mile; | |
var inch = units.inch; | |
var a = -9.81 * e2 * newton / kilogram; | |
showvar('a', a.toFixed(2)); | |
var mass = 5 * kilogram; | |
showvar('m', mass.toFixed(2)); | |
var F = mass * a; | |
showvar('F = m * a', F.toFixed(2)); | |
var c = 2.998e8 * meter / second; | |
showvar('c', c.toExponential()); | |
var theta = Math.PI / 4; | |
var u = (Math.cos(theta) * e2 + Math.sin(theta) * e1) * meter / second; | |
showvar('u', u.toFixed(4)); | |
var t = 4 * second; | |
showvar('t', t); | |
var v = u + a * t; | |
showvar('v= u + a * t', v.toFixed(4)); | |
showvar('meter', meter); | |
var length = yard + meter + mile + inch; | |
showvar('yard', yard.toFixed(4)); | |
showvar('mile', mile.toFixed(4)); | |
showvar('inch', inch.toFixed(4)); | |
showvar('meter + yard + mile + inch', (length/mile).toFixed(4) + " miles"); | |
showvar('meter + second', meter + second); | |
} | |
/** | |
* Print the HTML string without a line ending. | |
*/ | |
function print(html: string): void { | |
var element = document.getElementById('output'); | |
element.innerHTML = element.innerHTML + html; | |
} | |
/** | |
* Print the HTML string and go to the next line. | |
*/ | |
function println(html: string): void { | |
print(html + '\n'); | |
} | |
function showvar(name: string, value: any) { | |
println("<b>" + name + "</b> => " + value) | |
} |
This file contains hidden or 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
#output { | |
position: absolute; | |
left: 400px; | |
top: 100px; | |
font-size: 26pt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment