-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hx
52 lines (51 loc) · 1.51 KB
/
Test.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import js.Browser.*;
import js.html.*;
class CircleTools implements llhx.LowLevel {
public static function factorial(num: Int): Int {
var product = 1;
for(i in 2...num)
product *= i;
return product;
}
public static function area(r:Float):Float {
return Math.PI * r * r;
}
public static function circ(r:Float):Float {
return 2.0 * Math.PI * r;
}
}
class Test {
static var radius:InputElement;
static var area:InputElement;
static var circ:InputElement;
//static var canvas:CanvasElement;
//static var context:CanvasRenderingContext2D;
static var lastVal:Float;
public static function main() {
lastVal = 0;
if(untyped window.mozRequestAnimationFrame != null)
untyped window.requestAnimationFrame = untyped window.mozRequestAnimationFrame;
window.addEventListener("load", function(_) {
radius = cast document.getElementById("radius");
area = cast document.getElementById("area");
circ = cast document.getElementById("circ");
//canvas = cast document.getElementById("draw");
//context = canvas.getContext2d();
window.requestAnimationFrame(update);
trace(CircleTools.factorial(10));
});
}
static function update(d:Float) {
var radiusv = Std.parseFloat(radius.value);
if(radiusv == lastVal)
return true;
area.value = Std.string(CircleTools.area(radiusv));
circ.value = Std.string(CircleTools.circ(radiusv));
//CircleTools.draw(Std.int(radiusv));
window.requestAnimationFrame(update);
return true;
}
public static function drawPixel(x:Int, y:Int) {
trace('$x, $y');
}
}