Why isn't the whole SVG-file transforming?

edited April 2016 in Questions about Code

Hi everyone,

I'm trying to transform a loaded SVG-file, but one line doesn't transform, despite I'm looping through all the children. Does anybody know how to fix this?

Link to my SVG-file: https://dl.dropboxusercontent.com/u/104619472/a-01.svg

My code:

PShape s;

void setup() {
  size(1200, 800);
}

void draw() {
  background(0);
  translate(400, 100);
  s = loadShape("a-01.svg");
  editCharacter(s);
  shape(s);
}

void editCharacter(PShape s) {

  s.disableStyle();

  for (int i = 0; i < s.getVertexCount(); i++) {
    PVector v = s.getVertex(i);
      if (v.y < 50){
      v.x = v.x * mouseX/100;
      } else {
      v.x = v.x * mouseX/100;
      }

    s.setVertex(i, v.x, v.y);
    noFill();
    stroke(255);
  }

  if (s.getChildCount() > 0) {
    for (int i = 0; i < s.getChildCount(); i++) {
      editCharacter(s.getChild(i));
    }
  }
}

Answers

  • Answer ✓

    Assuming you use Illustrator, I suggest using the pen tool and add an extra vertex on the line that doesn't alter.

    Cause right now it's a line in the svg code: <line fill="none" stroke="#000000" stroke-width="2.5" stroke-linecap="square" stroke-linejoin="bevel" stroke-miterlimit="10" x1="276.992" y1="269.125" x2="276.992" y2="141.627"/>

    If you add 1 more point it will be forced into a path.

    For people that need the parameters (vertices of the line that doesn't move):

          if (s.getFamily() == PShape.PRIMITIVE) {
             float[] p = s.getParams();
             //where screwed, we can't set them
          }
    

    But as the comment states. There is no way to change them since setParams if private.

    One other way I can think of (which I don't recommend), is to program that PRIMITIVE shapes get replaced by PATH shapes. (if possible).

    I have opened an issue about the problem here:

    https://github.com/processing/processing/issues/4433

  • private & packaged-protected are the #1 enemy of Processing programmers!!! X(

  • Adding an extra vertex point works! Thanks! :)

  • @GoToLoop

    I agree, I'm against using private in general. Unless something has to do with security or something. I wasted countless hours by trying to do something and then reach a dead end cause of one method that is private.

    Maybe time for you to move away from processing :)

  • edited April 2016
    • We can always turn to reflection in order to by-pass access restrictions. :ar!
    • Problem is posting such huge boilerplate code would distress beginners a lot! 8-}
    • I simply dunno what it is exactly they're protecting us from by using private. :O)
    • Wouldn't protected be enough to label that some class member isn't intended for general access?
    • While at the same time still allowing us to "hack" the class by sub-classing it? *-:)
    • However for the PShape class, due to the fact it's created by "loaders" and other "builder" intermediary functions, it needs to have 100% public members! 8-X
    • That is, even if setParams() would be protected instead of private, loadShape() still wouldn't give us our modified PShape class, but always the original! :-O
    • Unless we'd @Override loadShape() as well, forcing it to return our hacked PShape. :P
Sign In or Register to comment.