I have a simple sketch that opens and image, samples the pixels and redraws them with circles at set intervals.
It works great in a loop but I only want it to process the image then stop. When I use the noLoop(); option in setup my sketch dosen’t get beyond asking for the file. If I don’t use noLoop(), it works but just keeps looping and processing.
My code below. Any help would be appreciated.
Thanks,
Phil
import processing.svg.*;
//changes these 2 values to get the image you like
float dotSmall = 6 ;
int space = 4;
int skipX = int(dotSmall)+space ;
int dotLarge = int (dotSmall) ;
import javax.swing.*;
import java.util.*;
boolean fileSelected;
String path;
PImage img;
int skipY = skipX;
void setup() {
background(0);
noStroke();
fill(0);
colorMode(HSB);
ellipseMode(CORNER) ;
size (100, 100);
selectImage(); // select an image to process
noLoop();
}
void draw() {
if (path != null) // Processing has a file to process.
{
println("starting");
img = loadImage(path);
int sx = img.width;
int sy = img.height;
surface.setResizable(true);
surface.setSize(sx, sy);
String svgPath = path+".svg";
beginRecord(SVG, svgPath);
for (int x=1; x < sx; x=x+skipX) {
for (int y=1; y < sy; y=y+skipY) {
color c = img.get(x, y);
float bright= brightness(c);
int b = round (bright);
float dotSize = (map(b, 0, 255, dotLarge, dotSmall));
fill(c);
circle(x, y, dotSize);
}
}
endRecord();
println("finished");
}
}
void selectImage()
{
selectInput("Select a movie to play:", "fileSelected");
}
void fileSelected(File selection)
{
if (selection != null)
{
path = selection.getAbsolutePath();
fileSelected = true;
println("User selected " + path);
}
}
by the way the project is run by volunteers and it would be nice if you refrain from making ironic comments on the features (I personally found the title is slightly offensive)
@micuat I tried your solution and it worked great, thanks.
The one issue I have is that because my surface starts at 100,100 pixels when my image is drawn, I only see a really low quality cropped image after the sketch runs.
Basically I read the size of the image and want to change the surface size prior to drawing the dots but currently it does the opposite. It seems to draw the dots based on the 100x100 then change the size of the surface.