Problems with exporting to SVG

Quite new to processing so might be overlooking something. I’m trying to export the following as SVG. but it hangs at the for statements. also tried without screen display but that is also not working.

PImage img;

import processing.svg.*;


void setup() {

  img = loadImage ("NASA.jpg");
  img.filter(GRAY);
  img.resize(800, 800);
  size(800, 800);
  beginRecord(SVG, "planet3.svg");
  float tiles = 5;
  float tileSize = width/tiles;
  translate(tileSize/2, tileSize/2);
  //size(800, 800, SVG, "filename.svg");

  background(255);
  fill(0);
  noStroke();
  print("123");

  for (int x = 0; x <img.width; x++) {
    for (int y = 0; y <img.height; y++) {
      color c = img.get(int(x*tileSize), int(y*tileSize));
      float size = map(brightness(c), 0, 255, tileSize, 0);
      ellipse(x*tileSize, y*tileSize, size, size);
    }
  }
  endRecord();
  print("test");
  //exit();
}

1 Like

Hello,

Take a look here:

This worked but took a few seconds to display:

Example
PImage img;
import processing.svg.*;

void setup() {

  size(200, 200);
  
  img = loadImage ("sunflower.jpg");
  img.filter(GRAY);
  img.resize(200, 200);
  
  beginRecord(SVG, "planet3.svg");
  float tiles = 5;
  float tileSize = width/tiles;
  translate(tileSize/2, tileSize/2);
  //size(800, 800, SVG, "filename.svg");

  background(255);
  fill(0);
  noStroke();
  print("123");

  for (int x = 0; x <img.width; x++) 
    {
    for (int y = 0; y <img.height; y++) 
      {
      color c = img.get(int(x*tileSize), int(y*tileSize));
      float size = map(brightness(c), 0, 255, tileSize, 0);
      ellipse(x*tileSize, y*tileSize, size, size);
      println(x+y*img.width);
      }
    }
  println("test1");  
  endRecord();
  println("test2");
  //exit();
}

tint1

image

:)

2 Likes

I just noticed result after letting it run, rendering time seems to be way longer then I expected.

Is there a way that would make more sense?

I work mainly with vector art, so the idea to make dot patterns or whatever shape from an image is what I’m after.

Hello,

See reference for get() and the comments about speed:

Take a look here:

Then create your vector art from above.

:)

2 Likes

found the culprit.

for (int x = 0; x <img.width; x++) {
    for (int y = 0; y <img.height; y++) {
      color c = img.get(int(x*tileSize), int(y*tileSize));
      float size = map(brightness(c), 0, 255, tileSize, 0);
      ellipse(x*tileSize, y*tileSize, size, size);
    }
  }

should be

for (int x = 0; x <tiles; x++) {
    for (int y = 0; y <tiles; y++) {
      color c = img.get(int(x*tileSize), int(y*tileSize));
      float size = map(brightness(c), 0, 255, tileSize, 0);
      ellipse(x*tileSize, y*tileSize, size, size);
    }
  }

when I opened it in illustrator I saw it drew outside the canvas. rendering times seem to be decent now.

2 Likes