Scripting Example: Triskelion x5

Scripting Example: Triskelion x5

This is an advanced feature: see Scripting Explained.

To make this print:


Use this script:

var CENTER_X = 126, CENTER_Y = 84;
function reverse(arr) {
  var res = [];
  for (var i = 0; i < arr.length; i += 2) {
    res[i] = arr[arr.length - i -2];
    res[i+1] = arr[arr.length - i -1];
  }
  return res;
}

function triskelion(Nsp, Nwh, a) {
  var block1 = [];
  var block2 = [];
  var points = [];
  var a,c,r,t,x,y,x0,y0,t1,t2;
  var dt = 0.04;
  for (var n=0; n < Nsp; n++) {
      r=0;
      t=0;
      x0=CENTER_X+a*Math.cos(2*Math.PI*n/Nsp);
      y0=CENTER_Y+a*Math.sin(2*Math.PI*n/Nsp);
      t1=2*Math.PI*Nwh-Math.PI/Nsp+Math.PI/2;
      t2=t1+2*Math.PI/Nsp;
      c=a*Math.sin(Math.PI/Nsp)*2/Math.PI/(1+4*Nwh);
      savedt=t;
      do {    
        t=t+dt;
        r=c*t;
        x=x0+r*Math.cos(t+Math.PI+2*Math.PI*n/Nsp);
        y=y0+r*Math.sin(t+Math.PI+2*Math.PI*n/Nsp);
        points.push(x);
        points.push(y);
      } while (t < t1);
      block1.push(points);
      points=[];
      t=savedt;
      do {
        t=t+dt;
        r=c*t;
        x=x0+r*Math.cos(t+2*Math.PI*n/Nsp);
        y=y0+r*Math.sin(t+2*Math.PI*n/Nsp);
        points.push(x);
        points.push(y);
        
      } while (t<t2);
      block2.push(points);
      points=[];
  }

  var merged = [];
  merged=merged.concat(block2[0]);
  for (var i = 1; i < Nsp; i++) {
    merged=merged.concat(reverse(block1[i]));
    merged=merged.concat(block2[i]);
  }  
  merged=merged.concat(reverse(block1[0]));

  return merged;
}
foodini.useIngredient(ingredients[0]);
var points = triskelion(5, 2, 40);
foodini.drawPolyline(points);
    • Related Articles

    • Scripting Example: Hexegon x6

      This is an advanced feature: see Scripting Explained. To make this print: Use this script: const polygon = (x, y, size, ang, n) => {   var result = [];   var delta = 2 * Math.PI / n;   ang = ang * 2 * Math.PI / 360;   for (var i = 0; i <= n; i++) {   ...
    • Scripting Example: Rose

      This is an advanced feature: see Scripting Explained. To make this print: Use this script: const rose = (centerX, centerY, stepCount, turns, n, d, A) => {   var results = [];    var k = n / d;   var stepSize = turns * 2 * Math.PI / (stepCount);   for ...
    • Scripting Explained

      You can write JavaScript statements to tell Foodini what to print, giving you precise control. Many schools like this feature for a fun way to teach kids how to code. Don't know JavaScript? Don't worry! This is an advanced feature for those that want ...
    • Scripting Example: Mini swirl flowers x6

      This is an advanced feature: see Scripting Explained. To make this print: Use this script: const rose = (centerX, centerY, stepCount, turns, n, d, A) => {   var results = [];    var k = n / d;   var stepSize = turns * 2 * Math.PI / (stepCount);   for ...
    • Shapes/Creations: What are they, and How-To Create

      A successful Foodini print is made up of 2 main elements: shapes (creations) and ingredients (fillings). Shapes/creations are the shapes that print. Ingredients/fillings are the ingredients that are loaded into the capsules and printed - into ...