Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 85e34be7ce
Fetching contributors…

Cannot retrieve contributors at this time

file 132 lines (122 sloc) 4.421 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
<!doctype html>

<html lang="en">
<head>
<title>Wheel Insets - 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 type="text/javascript" src="js/processing.js"></script>
</head>
<body class="container_12">
<header class="grid_12">
<hgroup>
<h1>Wheel Insets</h1><h2>w/ <a href="http://processingjs.org">Processing.js</a></h2>
</hgroup>
</header>
<script type="text/processing" data-processing-target="myCanvas">
/**
* <p>This example was used for designing the outer rim of some
* generative wheels. The wheels are designed for laser cutting from
* acrylic and the outer rim has a number of cutouts for friction fitting
* wire track modules.</p>
* <p>The actual generative wheel design is available under GPL v3 and
* can be downloaded from:
*
* http://toxiclibs.org/2010/01/re-inventing-the-wheel/
* </p>
*/

/*
* Copyright (c) 2010 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
*/


int NUM_CUTOUTS=18;
int NUM_ARCSEG=8;
int RADIUS=300;
float INSET=RADIUS-15;
float MATERIAL_THICKNESS=5;
float TOLERANCE=0.05;
float SIZE=MATERIAL_THICKNESS+TOLERANCE;
int BLEED=20;

void setup() {
  size(2*RADIUS+BLEED,2*RADIUS+BLEED);
  background(255);
  translate(width/2,height/2);
  noFill();
  beginShape();
  for(int i=0; i<NUM_CUTOUTS; i++) {
    float alpha=i*TWO_PI/NUM_CUTOUTS;
    float beta=(i+1)*TWO_PI/NUM_CUTOUTS;
    // cutout
    toxi.Vec2D[] insets=computePoints(alpha,INSET,SIZE);
    _vertex(insets[1]);
    _vertex(insets[0]);
    float gamma=computeAngles(alpha,RADIUS,SIZE)[0];
    float delta=computeAngles(beta,RADIUS,SIZE)[1];
    // arc between cutouts
    for(int j=0; j<=NUM_ARCSEG; j++) {
      float theta=lerp(gamma,delta,j/(float)NUM_ARCSEG);
      _vertex(toxi.Vec2D.fromTheta(theta).scaleSelf(RADIUS));
    }
  }
  endShape(CLOSE);
}

//can't override methods the same way as in java, so I added the _
void _vertex(toxi.Vec2D v) {
  vertex(v.x,v.y);
}

float[] computeAngles(float theta, float radius, float dist) {
  toxi.Vec2D[] points=computePoints(theta,radius,dist);
  toxi.Vec2D a=points[0].toPolar();
  toxi.Vec2D b=points[1].toPolar();
  float alpha=a.y<0 ? TWO_PI+a.y : a.y;
  float beta=b.y<0 ? TWO_PI+b.y : b.y;
  return new float[]{
    alpha,beta };
}

Vec2D[] computePoints(float theta, float radius, float dist) {
  toxi.Vec2D p=toxi.Vec2D.fromTheta(theta).scaleSelf(radius);
  toxi.Vec2D n=p.getPerpendicular().normalizeTo(dist/2);
  toxi.Vec2D a=p.add(n);
  toxi.Vec2D b=p.sub(n);
  return new toxi.Vec2D[]{
    a,b };
}
</script>

<canvas id="myCanvas" width="200" height="200">
your browser doesnt support canvas
</canvas>
<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_9">
<p>This example was used for designing the outer rim of some
generative wheels. The wheels are designed for laser cutting from
acrylic and the outer rim has a number of cutouts for friction fitting
wire track modules.</p>
<p>The actual generative wheel design is available under GPL v3 and
can be downloaded from:

<a href="http://toxiclibs.org/2010/01/re-inventing-the-wheel/">http://toxiclibs.org/2010/01/re-inventing-the-wheel/</a>
</p>
</article>
</section>
<footer class="grid_12"><a href="http://haptic-data.com/toxiclibsjs">toxiclibs.js</a></footer>
</body>
</html>
Something went wrong with that request. Please try again.