/************************************************************************** * * * SVG glyph manipulation sketch, primarily developed for use with Processing.js * * * * © Michiel Kamermans , all rights reserved. * * * **************************************************************************/ // ----------------- // SKETCH VARIABLES // ----------------- /** * the list of layers that need to be drawn - one layer per SVG 'image' */ ArrayList layers = new ArrayList(); /** * canvas margins */ int margin = 50; // --------------------- // INTERACTION METHODS // --------------------- /** * hooked up to something outside the sandbox? */ boolean hooked = false; void setHooked(boolean h) { hooked = h; for(int l=0, end=layers.size(); l1) { for(int l=1; lwidth || nh>height) { size(nw,nh); } // iterate to next last = current; }} // otherwise we only center else { int nw = last.getXPos() + last.getXScaled(last.getWidth()); int nh = last.getYPos() + last.getYScaled(last.getHeight()); if(nw>width || nh>height) { size(nw,nh); }} } // interface for on-page javascript SVGGlyphLayer getLayer(int l) { return (SVGGlyphLayer)layers.get(l); } /** * reset the sketch */ void clear() { size(180,1); background(0); layers = new ArrayList(); } /** * set the margin explicitly */ void setMargin(int m) { margin = m; } /** * Makes the canvas [margin]px wider and higher */ void fixMargin() { size(width+margin, height+margin); } // ---------------- // SKETCH METHODS // ---------------- /** * ridiculously simple setup */ void setup() { noLoop(); clear(); } /** * draw all layers on a white background */ void draw() { background(255); for(int l=0, end=layers.size(); l