We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello. I made several sketches using external svg file that i made in illustrator. I use them to animate some parts of svg. It works well on my PC, but when i put my .pde into web page, using processing.min.js it doesn't work. In general code works, but without SVG. I put SVG into data folder and link it in Setup section. Should i have extra code to make it work?
Answers
Unfortunately Pjs is still mostly stuck at ancient Processing 1.5.1 version:
http://ProcessingJS.org/reference/
It features PShape: http://ProcessingJS.org/reference/PShape/
However only for loading an already existing ".svg" rather than creating our own: :(
http://ProcessingJS.org/reference/loadShape_/
My advice if you need to create a shape is convert your Java Mode script to run under p5.js:
https://GitHub.com/processing/p5.js/wiki/Processing-transition
B/c it features many shape-related functions:
http://p5js.org/reference/#group-Shape
For Java familiarity, go w/ ES6 JS using the
class
structure keyword:https://developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
Thanks for your answer. Basically, i'm using svg for getting "child" from it and slightly transform them in loop section. code looks like this in general:
Now it seems that P5.js doesn't accept svg. I found it on https://github.com/processing/p5.js/wiki/Processing-transition
For a successful transpilation from Processing's Java to Pjs' JS we need to stick w/ Processing 1's API.
For example @ line #35:
parts[i].draw(g);
, You're invoking draw() method which doesn't exist in the old PShape: http://ProcessingJS.org/reference/PShape/The formal way to display a PShape is the function shape(): http://ProcessingJS.org/reference/shape_/
Even in Processing 3: https://Processing.org/reference/shape_.html
It's also very important to hit F12 when running the transpiled code in browser in order to check for any error messages there. :-&
Thanks again. I should start learning Processing.Js from the beginning. Now start changing my code according to your advises and seems it will work soon. Thanks.