processing - draw shape on input gives unexpected result how to fix? -


i want draw shape based on input of slider. see code below:

import controlp5.*; controlp5 cp5;  int people = 5; int dmamt = 0; int peoplehis; slider abc;  pshape vorm;  void setup() {    cp5 = new controlp5(this);    size(displaywidth, displayheight);     cp5.addslider("people")      .setposition(10,10)      .setwidth(400)      .setrange(0,20)      .setvalue(0)      .setnumberoftickmarks(20)      .setslidermode(slider.fix)    ;       cp5.addslider("dmamt")      .setposition(450,10)      .setwidth(400)      .setrange(0,255)       .setvalue(0)      .setnumberoftickmarks(5)      .setslidermode(slider.fix)   ;      vorm = createshape();   framerate(10); }   void draw(){    if(peoplehis != people){      vorm.beginshape();      vorm.fill(dmamt);      for(int = 0; <= people; i++){         vorm.vertex(random(500), random(500));      }      endshape();   }   peoplehis = people;    shape(vorm, 100,100);  } 

the first time set slider value shape desired amount of points. when change slider value after first time value of slider added points drawn. want new shape. old shape should gone. see below example:

first value of slider = 5 gives me shape 5 points (great);

second value of silder = 12 gives me shape 17 points (not great) want 12 points instead of 17.

how do this?? not experienced code :(

a processing pshape can consist of multiple shapes, can add calling beginshape(), vertex(), , endshape() functions multiple times.

if want recreate new shape instead of adding multiple shapes, call createshape() function again start on new pshape instance. also, make sure clear out previous frames calling background() function.

here simple example:

pshape shape;  void setup() {     size(500, 500);    shape = createshape();   framerate(60); }  void mousepressed(){   shape = createshape();   shape.beginshape();   for(int = 0; < 3; i++){     shape.vertex(random(width), random(height));   }   shape.endshape(); }  void draw(){   background(0);   shape(shape, 0,0);  } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo