Skip to content

Instantly share code, notes, and snippets.

@anjiro
Created August 25, 2016 19:22
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 anjiro/405e0d3f9be23e0cf649d61a4da972ef to your computer and use it in GitHub Desktop.
Save anjiro/405e0d3f9be23e0cf649d61a4da972ef to your computer and use it in GitHub Desktop.
Assignment 1 example
<html>
<head>
<meta charset="utf-8">
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="paperjs-v0.9.23/dist/paper-full.js"></script>
<script type="text/paperscript" canvas="paper">
var $ = window.$;
//Fill in the background
var background = new Shape.Rectangle(view.bounds);
background.fillColor = "Red";
//Set up my initial path to draw
var path = new Path();
path.strokeColor = "black";
var public_key = 'YGV3jNvQMjh2G4oOLwdx';
function drawData()
{
$.ajax({
url: 'https://data.sparkfun.com/output/' + public_key + '.json',
data: {page: 1},
dataType: 'jsonp',
}).done(
function(results)
{
console.log("Got " + results.length + " results");
var incx = view.bounds.width / results.length;
//Start at the middle left of the rectangle
var loc = view.bounds.leftCenter - incx;
path.remove();
path = new Path();
path.strokeColor = "black";
path.moveTo(loc);
for(var i = 0; i < results.length; i++)
{
row = results[i];
loc = new Point(loc.x + incx,
(parseFloat(row.my) - 95) * 80 + view.bounds.height/2 + 100);
path.lineTo(loc);
}
/*
$.each(results,
function(index, row)
{
loc = new Point(loc.x + incx,
(parseFloat(row.my) - 95) * 80 + view.bounds.height/2 + 100);
path.lineTo(loc);
}
);
*/
view.draw();
window.setTimeout(drawData, 30000);
}
);
}
drawData();
</script>
</head>
<body>
<canvas id="paper" width="500px" height="200px" resize></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment