The code below shows how to create a custom function that creates and returns a custom PShape object. The PShape method: shape(PShape s, float x, float y ) is used in draw( ) to render the shape by inputing the specified values for parameters: x, y:
voidsetup( ) {size( 600,600);colorMode(HSB,360,100,100,100);//HSBAbackground(360); //white}voiddraw( ) { color purple =color( 270,100,100); float len =100;if ( mousePressed) {translate( mouseX, mouseY); //move origin to mouse postionPShape s =createMyShape1( len, purple); //create PShapeshape( s,0,0 ); //display at translated originresetMatrix(); //move origin back to upper left }}PShapecreateMyShape1( float len, color c1) {//fill( c1); //for some PShapes, use fill before creating the shapePShape s =createShape(RECT,0,0, len, len) ;s.setFill( c1);//for some PShapes, use setFill( ) after creating the shapereturn s;}