Sketchpad implements the possibility of working with lists of Objects as operators. Please note Sets
are currently under severe redevelopment, and behavior may change any time soon.
Last active
August 29, 2015 14:11
-
-
Save garciadelcastillo/aa3af62c631774c65de5 to your computer and use it in GitHub Desktop.
Sketchpad.js - Sets
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> | |
<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> |
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
// Create new instance of Sketchpad in target Canvas | |
var pad = new Sketchpad('sketchpadCanvas'); | |
// Create some Lines and Circles | |
var A = new pad.Node(128, 100), | |
B = new pad.Node(256, 300), | |
C = new pad.Node(512, 100), | |
D = new pad.Node(384, 300), | |
E = new pad.Node(320, 100), | |
AB = pad.Line.between(A, B), | |
DC = pad.Line.between(D, C), // note orientation change here | |
circleE = pad.Circle.centerRadius(E, 50); | |
// Create a Set of numbers with 100 steps from 0 to 1 | |
var divs = pad.Set.range(0, 1, 100); | |
// Use those values to create Point Sets along Lines and Circles | |
var ABpts = pad.Point.along(AB, divs), | |
DCpts = pad.Point.along(DC, divs), | |
circleEpts = pad.Point.along(circleE, divs); | |
// Apply new Style | |
pad.currentStyle( new pad.Style({ stroke: 'rgba(127, 127, 127, 0.3' }) ); | |
// Create Line Sets between Point Sets | |
var lineToLine = pad.Line.between(ABpts, DCpts), | |
lineToCircle = pad.Line.between(DCpts, circleEpts); |
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
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