Access shape classes of SVG on p5 canvas with CSS

Hi,

here's what I'm trying to do: I want to include a svg image in my p5 canvas and change the properties of certain shapes of that svg image using css. The image is basically a tree, featuring a trunk, big leaves and small leaves. In the svg file, I've grouped the corresponding shapes and assigned a class to each group like this:

<g class='tree'> <g class='bigLeaf'> <path style = 'fill:#000000;' d='this is the path of the first leaf ' /> </g> <g class = 'trunk'> <path ... /> </g> </g>

The js. file looks like this:

var canvas; var treeImg; function preload(){ treeImg = loadImage("gfx/tree_simple_css.svg"); } function setup(){ canvas = createCanvas(windowWidth/2,windowHeight/2); canvas.position(windowWidth/4,windowHeight/4); } function draw(){ background('#C7F6F7'); image(treeImg, .5*width, .5*height); }

With css I'd now like to be able to change e.g. the size of the tree with .tree{size: 50%} or hide the big leaves, you get the idea... Ultimately I'd like the sketch to behave responsive, that's why I'm trying to work with css here. This naive approach however doesn't work, instead what would be the best or the right way to do this?

I'd very much appreciate any help on this issue. Cheers!

Answers

Sign In or Register to comment.