Scripting Example: Rose

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 (var theta = 0; theta < d * turns * 2 * Math.PI; theta += stepSize) {
    var x = centerX + A * Math.cos(k * theta) * Math.cos(theta);
    var y = centerY + A * Math.cos(k * theta) * Math.sin(theta); 
    results.push(x, y);
    console.log(x);console.log(y);
  }
  return results;
};

foodini.useIngredient(ingredients[0]);
var X = 256/2, Y = 148/2, SIZE = 60, STEPS = 400, TURNS = 1;
[[5,4]].forEach((nd, i) => {
  const pts = rose(X + 2 * (SIZE + 5)* i, Y, STEPS, TURNS, nd[0], nd[1], SIZE);
  foodini.drawPolyline(pts,false,false);
});

    • Related Articles

    • 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 ...
    • 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: 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];     ...
    • 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 ...