Skip to content

Instantly share code, notes, and snippets.

@garciadelcastillo
Last active August 29, 2015 14:11
Show Gist options
  • Save garciadelcastillo/41052af5a6f53407ddb8 to your computer and use it in GitHub Desktop.
Save garciadelcastillo/41052af5a6f53407ddb8 to your computer and use it in GitHub Desktop.
Sketchpad.js - Points vs. Nodes
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="sketchpadDiv">
<canvas id="sketchpadCanvas"></canvas>
</div>
</body>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="http://www.garciadelcastillo.es/sketchpad/sketchpad.js"></script>
<script type="text/javascript" src="sketch.js"></script>
</html>
// Create new instance of Sketchpad in target Canvas
var pad = new Sketchpad('sketchpadCanvas');
// Create a Line between two Nodes, and two nested Circles
var A = new pad.Node(160, 120),
B = new pad.Node(480, 120),
AB = pad.Line.between(A, B);
var C = pad.Point.along(AB, 0.75),
circleC = pad.Circle.centerRadius(C, 51);
var D = pad.Point.along(circleC, 0.25),
circleD = pad.Circle.centerRadius(D, 26);
// Now create the same setup, using Node elements as anchors instead
var M = new pad.Node(160, 280),
N = new pad.Node(480, 280),
MN = pad.Line.between(M, N);
var O = pad.Node.along(MN, 0.75, {clamp: true}),
circleO = pad.Circle.centerRadius(O, 51);
var P = pad.Node.along(circleO, 0.25),
circleP = pad.Circle.centerRadius(P, 26);
// Display Tags only on Node elements
pad.tagNodes();
body {
margin: 0;
padding: 0;
}
#sketchpadDiv {
position: absolute;
width: 100%;
height: 100%;
border: 1px solid #000;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#sketchpadCanvas {
position: absolute;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment