Code not drawing

So I am new and struggling i have a code that shows no errors but i not getting the desired results can some one help.


PShape svg;
float angle = 0;
float radius = 10;
float frequency = 0.1;

void setup() {
  size(800, 600);
  svg = loadShape("test.svg");
}

void draw() {
  background(255);
  
  // Process each line command in the SVG file
  for (int i = 0; i < svg.getVertexCount() - 1; i++) {
    PVector p1 = svg.getVertex(i);
    PVector p2 = svg.getVertex(i + 1);
    
    // Calculate the distance between two points
    float distance = dist(p1.x, p1.y, p2.x, p2.y);
    
    // Calculate the radius and frequency based on the distance
    float currentRadius = radius + distance * 0.1;
    float currentFrequency = frequency + distance * 0.01;
    
    // Generate a spiraling line based on the current radius and frequency
    float x = width / 2 + cos(angle) * currentRadius;
    float y = height / 2 + sin(angle) * currentRadius;
    angle += currentFrequency;
    
    // Draw the line segment
    stroke(0);
    line(x, y, p2.x, p2.y);
  }
}`Preformatted text`


type or paste code here

and this is the svg file for testing.

<!-- Created for Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="3200"
   height="800"
   id="svg2985"
   version="1.1"
   inkscape:version="0.48.1 r9760">
  <defs
     id="defs2987" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="0.35"
     inkscape:cx="1600"
     inkscape:cy="400"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"  />
  <metadata
     id="metadata2990">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title />
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"> 
     <g>
<path style="fill:none;stroke:black;stroke-width:2px;stroke-linejoin:round;stroke-linecap:round;" d="M 
1644.4978 693.1072

1649.782 681.2707

1642.0172 670.2019

1631.1365 663.3629

1628.7023 676.1177



" />
</g></g></svg>

type or paste code here

type or paste code here
1 Like

Have you checked your coordinates?

line(x, y, p2.x, p2.y);

Are they within your drawing area size(800, 600);? Drawing outside of it has no visible effect.

1 Like

Hello @Rbu,

I get this error with your code:

I suggest you create a shape in setup() and use that for testing.

I was not able to get a vertex count from your SVG and therefore unable to get vertices.

PShape s;

void setup() 
  {
  size(800, 600);

  // Create a shape here
  
  println(s.getChildCount()); //This will tell you the number of children
  println(s.getVertexCount()); //This will tell you the number of vertices
  }

Shape borrowed from references.

Some resources:

:)