Skip to content

Instantly share code, notes, and snippets.

@ctlusto
Created October 23, 2015 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctlusto/d81ab7202c11026f579a to your computer and use it in GitHub Desktop.
Save ctlusto/d81ab7202c11026f579a to your computer and use it in GitHub Desktop.
Happy Trails
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Happy Trails</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="calculator"></div>
<script src="//www.desmos.com/api/v0.5/calculator.js?apiKey=dcb31709b452b1cf9dc26972add0fda6"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script src="main.js"></script>
</body>
</html>
var elt = document.getElementById('calculator');
var opts = {
expressionsCollapsed: true,
lockViewport: true
};
var exp = [
{
id: 'a',
latex: 'a = 0'
},
{
id: 'b',
latex: 'b = 0'
},
{
id: 'point',
latex: '(a, b)',
color: Desmos.Colors.RED
}
];
var calc = Desmos.Calculator(elt, opts);
calc.setExpressions(exp);
var svg = d3.select('body').append('svg')
.style({position: 'absolute', 'pointer-events': 'none'});
var coords = calc.graphpaperBounds.pixelCoordinates;
svg.attr('width', coords.width)
.attr('height', coords.height)
.style({top: coords.top, left: coords.left});
var aHelper = calc.HelperExpression({latex: 'a'});
aHelper.observe('numericValue', function() {
requestAnimationFrame(omgCircles);
});
var bHelper = calc.HelperExpression({latex: 'b'});
function omgCircles() {
var px = calc.mathToPixels({x: aHelper.numericValue, y: bHelper.numericValue});
svg.insert("circle")
.attr("cx", px.x)
.attr("cy", px.y)
.attr("r", 10)
.style("fill", Desmos.Colors.next())
.style("fill-opacity", 1)
.transition()
.duration(1000)
.ease(Math.sqrt)
.attr("r", 40)
.style("fill-opacity", 1e-6)
.remove();
}
html,
body {
margin: 0;
}
html,
body,
#calculator {
width: 100%;
height: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment