Handy renderer on SVGs?

I’m importing some SVGs into a sketch that I’d like to style using HandyRenderer. It looks like there may be some hoops to jump through, as just applying the Handy class to the shape statement doesn’t work

import org.gicentre.handy.*;

HandyRenderer h;
PShape heart;

void setup()
{
  size(800,800); 
  h = new HandyRenderer(this);
  heart = loadShape("heart-svgrepo-com.svg");
  noLoop();
  
}
void draw()
{
  background(247,230,197);
  heart.disableStyle();
  h.shape(heart, width/2, height/2);
}

Anyone have any thoughts? Thanks!

Hi @jjjolton,

Looks like the library doesn’t have the same API as Processing, when hovering on the shape statement it accepts the following arguments:

The method shape(float[], float[], float[]) in the type HandyRenderer is 
not applicable for the arguments (PShape, int, int)

Also searching svg or shape in the source code didn’t give any results…

You can either ask the author if it’s supported or was planned or fork the repository and make your own version! :wink:

1 Like

Good idea, asking the author. I’ve done that now, and if there’s a solution, I’ll follow up here.

Thanks!

1 Like
/** Draws a closed 2d polygon based on the given arrays of vertices.
 *  @param xCoords x coordinates of the shape.
 *  @param yCoords y coordinates of the shape.
 */
public void shape(float[] xCoords, float[] yCoords)
{
	shape(xCoords,yCoords,true);
}

Convert the svg PShape’s coordinates to two float arrays, and call the method above.

1 Like

I’ll see if I can make that work. Thanks!