Created
August 23, 2013 16:23
-
-
Save ckimrie/6321247 to your computer and use it in GitHub Desktop.
JS Bin math visualisation competition entry. Working version can be seen here: http://jsbin.com/oyecax/2/
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> | |
<meta name="description" content="JS Bin Competition Entry" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="surface"></div> | |
</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
require(['dojox/gfx', 'dojox/gfx/fx'], function(gfx){ | |
var angle = 0, | |
width = 500, | |
height = 500, | |
x = width / 2, | |
y = height / 2, | |
surface = gfx.createSurface('surface', width, height), | |
ellipses = [], | |
movingTarget = surface.createGroup(); | |
//Red Circle | |
surface.createCircle({ | |
cx: x, | |
cy: y, | |
r: 50 | |
}).setStroke('red'); | |
for(var i = 0; i < 4; i++){ | |
ellipses[i] = surface.createEllipse({ | |
cx: x, | |
cy: y, | |
rx: 150, | |
ry: 50 | |
}).setStroke('red').applyTransform(gfx.matrix.rotategAt(45 * i, x, y)); | |
} | |
//Blue Circle | |
surface.createCircle({ | |
cx: x, | |
cy: y, | |
r: 100 | |
}).setStroke('blue'); | |
surface.createLine({ | |
x1: x - 100, | |
y1: y, | |
x2 : x + 100, | |
y2: y | |
}).setStroke('blue'); | |
surface.createLine({ | |
x1: x, | |
y1: y -100, | |
x2 : x, | |
y2: y + 100 | |
}).setStroke('blue'); | |
//Black Moving Target | |
movingTarget.createLine({ | |
x1: - 100, | |
y1: 0, | |
x2: 100, | |
y2: 0 | |
}).setStroke('black'); | |
movingTarget.createLine({ | |
x1: 0, | |
y1: -100, | |
x2: 0, | |
y2: 100 | |
}).setStroke('black'); | |
movingTarget.createCircle({ | |
cx: 0, | |
cy: 0, | |
r: 3 | |
}).setStroke('black'); | |
movingTarget.createCircle({ | |
cx: 0, | |
cy: -100, | |
r: 3 | |
}).setStroke('black'); | |
movingTarget.createCircle({ | |
cx: 0, | |
cy: 100, | |
r: 3 | |
}).setStroke('black'); | |
movingTarget.createCircle({ | |
cx: 100, | |
cy: 0, | |
r: 3 | |
}).setStroke('black'); | |
movingTarget.createCircle({ | |
cx: 50, | |
cy: 0, | |
r: 4 | |
}).setStroke('blue'); | |
movingTarget.createCircle({ | |
cx: 0, | |
cy: 0, | |
r: 50 | |
}).setStroke('blue'); | |
movingTarget.createCircle({ | |
cx: -50, | |
cy: 0, | |
r: 4 | |
}).setStroke('blue'); | |
movingTarget.createCircle({ | |
cx: -100, | |
cy: 0, | |
r: 3 | |
}).setStroke('black'); | |
movingTarget.moveToFront(); | |
function draw() { | |
var x2 = Math.cos(angle * Math.PI / 180) * 50, | |
y2 = Math.sin(angle * Math.PI / 180) * 50; | |
movingTarget.setTransform(gfx.matrix.translate({ x : x + x2, y : y + y2})); | |
movingTarget.applyTransform(gfx.matrix.rotateg(-angle)); | |
angle++; | |
setTimeout(draw, 16); | |
} | |
draw(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment