Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added an experimental packaging utility for PJS users, fixed a bug in…

… InterpolateStrategy
  • Loading branch information...
commit 749291046177ecc47b3fa5c367079f83532d71c7 1 parent 3b6863c
@hapticdata hapticdata authored
View
157 examples/PolarLines_pjs.html
@@ -0,0 +1,157 @@
+<!doctype html>
+
+<html lang="en">
+<head>
+ <title>Polar Lines - toxiclibs.js examples</title>
+ <meta name="author" content="Kyle Phillips">
+ <link href="css/style.css" rel="stylesheet" type="text/css">
+ <!-- Date: 2011-01-09 -->
+ <script type="text/javascript" src="../build/toxiclibs.js"></script>
+ <script src="../src/toxi-packaging.js"></script>
+ <script type="text/javascript" src="js/processing.js"></script>
+ <script type="text/javascript">
+ /*
+ * This code searches for all the <script type="application/processing" target="canvasid">
+ * in your page and loads each script in the target canvas with the proper id.
+ * It is useful to smooth the process of adding Processing code in your page and starting
+ * the Processing.js engine.
+ */
+
+ if (window.addEventListener) {
+ window.addEventListener("load", function() {
+ var scripts = document.getElementsByTagName("script");
+ var canvasArray = Array.prototype.slice.call(document.getElementsByTagName("canvas"));
+ var canvas;
+ for (var i = 0, j = 0; i < scripts.length; i++) {
+ if (scripts[i].type == "application/processing") {
+ var src = scripts[i].getAttribute("target");
+ if (src && src.indexOf("#") > -1) {
+ canvas = document.getElementById(src.substr(src.indexOf("#") + 1));
+ if (canvas) {
+ new Processing(canvas, scripts[i].text);
+ for (var k = 0; k< canvasArray.length; k++)
+ {
+ if (canvasArray[k] === canvas) {
+ // remove the canvas from the array so we dont override it in the else
+ canvasArray.splice(k,1);
+ }
+ }
+ }
+ } else {
+ if (canvasArray.length >= j) {
+ new Processing(canvasArray[j], scripts[i].text);
+ }
+ j++;
+ }
+ }
+ }
+ }, false);
+ }
+
+ </script>
+</head>
+<body class="container_12">
+<header class="grid_12">
+ <hgroup>
+ <h1>Polar Lines</h1>
+ <h2>w/ <a href="http://processingjs.org">Processing.js</a></h2>
+ </hgroup>
+</header>
+
+<script type="application/processing">
+/**
+ * PolarLines demo shows the difference between lines in normal cartesian
+ * and polar coordinate systems, where a line is actually a curve/spiral.
+ * Both "lines" are shown in parallel and the only difference is the order
+ * of the .toCartesian() conversion (either inside or outside the loop).
+ *
+ * Usage: move mouse to adjust line endpoint
+ */
+
+/*
+ * Copyright (c) 2006-2008 Karsten Schmidt
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+import toxi.geom.*;
+
+
+toxi.globalize();
+
+void setup() {
+ size(640,560);
+ smooth();
+}
+
+void draw() {
+ background(245);
+ translate(width/2,height/2);
+ stroke(255,0,0);
+ strokeWeight(2);
+
+ // start point at radius 10, 0 degrees
+ Vec2D a=new Vec2D(10,0);
+
+ // end point at mouse position
+ Vec2D b=new Vec2D(mouseX,mouseY).sub(width/2,height/2).toPolar();
+ // force at least 1 full turn to create spiral
+ b.y+=4*PI;
+
+ // draw a "line" from a -> b in POLAR space
+ // calculate intermediate points
+ for(int i=0, num=200; i<num; i++) {
+ // interpolate in polar space
+ // and only convert result into cartesian
+ Vec2D p=a.interpolateTo(b,(float)i/num).toCartesian();
+ point(p.x,p.y);
+ }
+
+ // draw a line from a -> b in CARTESIAN space
+ // transfer points into cartesian space
+ a.toCartesian();
+ b.toCartesian();
+ stroke(0,0,255);
+ // calculate intermediate points
+ for(int i=0,num=50; i<num; i++) {
+ // interpolation already happens in cartesian space
+ // no further conversion needed
+ Vec2D p=a.interpolateTo(b,(float)i/num);
+ point(p.x,p.y);
+ }
+}
+
+</script>
+<div class="grid_12">
+<canvas id="myCanvas" width="200" height="200">
+ your browser doesnt support canvas
+</canvas>
+</div>
+<section id="details" class="grid_12">
+<aside id="authors" class="grid_6">
+<p>original example by <a href="http://postspectacular.com">Karsten Schmidt</a><br/>
+ Toxiclibs ported to js by <a href="http://workofkylephillips.com">Kyle Phillips</a>
+</p>
+</aside>
+<article id="description" class="grid_12">
+<p>PolarLines demo shows the difference between lines in normal cartesian and polar coordinate systems, where a line is actually a curve/spiral. Both "lines" are shown in parallel and the only difference is the order of the .toCartesian() conversion (either inside or outside the loop).</p>
+</article>
+</section>
+<footer class="grid_12"><a href="http://haptic-data.com">toxiclibs.js
+</a></footer>
+</body>
+</html>
View
2  src/core/math/InterpolateStrategy.js
@@ -111,7 +111,7 @@ toxi.CosineInterpolation.prototype = {
toxi.DecimatedInterpolation = function(steps,strategy) {
if(steps === undefined)throw new Error("steps was not passed to constructor");
this.numSteps = steps;
- this.strategy = (strategy==undefined)? new LinearInterpolation() : strategy;
+ this.strategy = (strategy===undefined)? new toxi.LinearInterpolation() : strategy;
}
toxi.DecimatedInterpolation.prototype = {
View
117 src/toxi-packaging.js
@@ -0,0 +1,117 @@
+(function(){
+ var packages = {
+ "geom" : [
+ "AABB",
+ "AxisAlignedCylinder",
+ "BernsteinPolynomial",
+ "Circle",
+ "CircleIntersector",
+ "Cone",
+ "Ellipse",
+ "IsectData2D",
+ "IsectData3D",
+ "Line2D",
+ "Line3D",
+ "Matrix4x4",
+ "Polygon2D",
+ "Quaternion",
+ "Ray2D",
+ "Ray3D",
+ "Ray3DIntersector",
+ "Rect",
+ "Sphere",
+ "Spline2D",
+ "Triangle",
+ "Vec2D",
+ "Vec3D",
+ "XAxisCylinder",
+ "YAxisCylinder",
+ "ZAxisCylinder"
+ ],
+ "geom.mesh" : [
+
+ //mesh
+ "BezierPath",
+ "Face",
+ "Selector",
+ "SphereFunction",
+ "SphericalHarmonics",
+ "SuperEllipsoid",
+ "SurfaceMeshBuilder",
+ "TriangleMesh",
+ "Vertex",
+ "VertexSelector"
+ ],
+
+ "math" : [
+
+ //math
+ "MathUtils",
+ "SigmoidInterpolation",
+ "BezierInterpolation",
+ "CircularInterpolation",
+ "CosineInterpolation",
+ "DecimatedInterpolation",
+ "LinearInterpolation",
+ "ExponentialInterpolation",
+ "Interpolation2D",
+ "ThresholdInterpolation",
+ "ZoomLensInterpolation",
+ "ScaleMap",
+ "SinCosLUT",
+ ],
+
+ "math.waves" : [
+ "AbstractWave",
+ "SineWave",
+ "AMFMSineWave",
+ "ConstantWave",
+ "FMHarmonicSquareWave",
+ "FMSawtoothWave",
+ "FMSineWave",
+ "FMSquareWave",
+ "FMTriangleWave"
+ ]
+ };
+
+
+ toxi.package = function(){
+ var getPackageObject = function(o,packageString){
+ var split = packageString.split('.');
+ var returnObject = undefined;
+ if(split.length < 2){
+ returnObject = {object: o, package: split[0]};
+ } else if(split.length > 1){
+ o[split[0]] = o[split[0]] || {};
+ returnObject = {object: o[split[0]], package: split[1]};
+ }
+
+ if(split.length > 2){
+ var nextString = packageString.slice(split[0].length+1);
+ returnObject = getPackageObject(o[split[0]],nextString);
+ }
+ return returnObject;
+ };
+ for(var p in packages){
+ var packageObj = getPackageObject(this,p);
+ var toxiPackage = packageObj.object;
+ var id = packageObj.package;
+ var classes = packages[p];
+ var o = {};
+ for(var i=0,len=classes.length;i<len;i++){
+ o[classes[i]] = toxi[classes[i]];
+ }
+ toxiPackage[id] = o;
+ }
+ };
+
+ toxi.globalize = function() {
+ for(var p in packages){
+ var classes = packages[p];
+ for(var i=0,len=classes.length;i<len;i++){
+ window[classes[i]] = toxi[classes[i]];
+ }
+ }
+ };
+
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.