jacopocolo / p5-sketchplugin

A plugin for using p5.js code inside Sketch
http://www.jacopocolo.com/p5sketchplugin/
GNU Lesser General Public License v2.1
220 stars 12 forks source link

Bug when selecting an artboard #2

Closed lanceplaine closed 7 years ago

lanceplaine commented 7 years ago

Steps to reproduce the bug

  1. Create an empty artboard
  2. Select the artboard (The bug doesn't happen otherwise)
  3. Run the code
  4. Bug: One part of the pie chart is too big (the pink)
screen shot 2017-09-22 at 4 34 50 pm

Code used

Pie chart

//The percentages you need to visualize
var percentages = [30,60,10];

function setup() {
  //Creates an 400x400 artboard
  createCanvas(400, 400);
  //Remove Borders
  noStroke();
}

function draw() {
  //Custom function defined underneath
  pieChart(300, percentages);
}

//We define a function called pieChart that asks
//for diameter and percentage
function pieChart(diameter, data) {

  //We keep trak of the last angle drawn. The initial value
  //defines where the pie chart stars. -HALF_PI it 12 on a clock.
  var lastAngle = -HALF_PI;

  //We run a loop that runs as many times as there
  //are elements in the percentages array
  for (var i = 0; i < data.length; i++) {

    //Every time we run the loop we define a random rgb color
    //for each section of the pie
    fill(random(255),random(255),random(255));

    //We draw an arc that is centered at the center of the artboard,
    //has the first parameter of pieChart as a diameter
    //and takes one of the values from percentage, divides it by 100
    //multiplies it by 360 (so we get the percentage in degrees)
    //and then converts it into radians for angle
    //The variabile lastAngle is used to make sure we have arcs that
    //start where the last arc ended.
    arc(width/2, height/2, diameter, diameter, lastAngle,  lastAngle+radians((data[i]/100)*360));
    lastAngle += radians((data[i]/100)*360);
  }
}
jacopocolo commented 7 years ago

What a fantastic find, I've been wondering for weeks WHY one masks would not work and never realized that it was connected to the current selection. Thanks, this should be an easy fix!

lanceplaine commented 7 years ago

No problem :)