Pen tool & Area Calculation

edited January 2015 in p5.js

Hi everyone,

I wonder if there is a way to draw a custom shape by picking points from the mouse (Like "Pen Tool" in photoshop and Illustrator) and then calculating the are of that shape? Thanks...


  • Hey. Try this to create a pen-like tool (sorry for the formatting). Getting the area of the shape is harder and out of my competence though.

    var prevPosX;
    var prevPosY;
    function setup() {
    function draw() {
    function mousePressed() {
      if (prevPosX !=0 && prevPosY !=0) {
         line(prevPosX, prevPosY, mouseX, mouseY);
         prevPosX = mouseX;
         prevPosY = mouseY;
         return false;
  • edited February 2015

    I haven't tried coding but since processing can track the x and y coordinates, you can probably make a code base on the algorithms of finding the area irregular polygon :

    I am thinking you will probably need to set a counter with mouse pressed(for the vertices) and using a for loop that will go through the calculation and that should work

Sign In or Register to comment.