Using a code from Processing 10 doesn't work on Processing 13

edited December 2017 in Questions about Code

Hello all

I'm running a code from a couple of years ago which worked fine on the old version of processing but doesn't work on Processing 13.

line 16 is causing troubles please please help?

thank you!

import java.io.*;

int outputWidth = 819;
int outputHeight = 819;
int smallWidth = 9;
int smallHeight = 9;

String imagePath;
String[] images;
int imageCount;
PGraphics pg;

void setup() {
  size(819, 819);
  pg = createGraphics(outputWidth, outputHeight, P2D);
  imagePath = selectFolder();
  if (imagePath != null) { images = loadImageFilenames(imagePath); } else { exit(); }
}

void draw() {
  PImage currentImage = loadImage(imagePath + "/" + images[imageCount % images.length]);
  currentImage.resize(smallWidth, smallHeight);
  int x = (smallWidth * imageCount) % outputWidth;
  int y = ((smallWidth * imageCount) / outputWidth) * smallHeight;
  if (y < outputHeight) {
    pg.beginDraw();
    pg.image(currentImage, x, y);
    pg.endDraw();
    background(0);
    image(pg, 0, 0, width, height);
    imageCount++;
  } else {
    pg.save("output.png");
    exit();
  }
}

String[] loadImageFilenames(String path) {
  File folder = new File(path);
  FilenameFilter imgFilter = new FilenameFilter() {
    public boolean accept(File dir, String name) {
      String lowCase = name.toLowerCase();
      return lowCase.endsWith(".jpg")
      || lowCase.endsWith(".png")
      || lowCase.endsWith(".tga");
    }
  };
  return folder.list(imgFilter);
}

Answers

  • Processing 10 ???

    Processing 13 ???

    i don't recognise those version numbers. currently we are on 3.3.6

    the reference for selectfolder looks different from what you have there:

    https://processing.org/reference/selectFolder_.html

  • edited December 2017

    @koogs Somebody from the future.... :(|)

    @alenalo What OS btw?

    Kf

  • edited December 2017

    Keep in mind that old versions of Processing are all still available -- so if you really want to just run your code, and you know exactly what old version you were using when it worked, then you could also try running it on that old version of Processing.

    Here are the last 4 stable releases:

    And here are the last 463 incremental releases:

  • Can you please be more specific than saying it doesn't work or it's giving you trouble? What exact error are you seeing?

  • edited December 2017

    Thank you very much for links and responses

    koogs, version 1.5.1

    jeremydouglass, I have done dot the older version of processing do not open for some reason

    KevinWorkman, so I used this code a couple of years ago using version 1.5.1

    But I now want to use the same code on a different mac and it doesn't let me run. this is the error I am seeing!!

    Screen Shot 2017-12-11 at 10.03.26 !

  • see selectFolder in the reference. it now takes two arguments.

    OH WAIT, I SAID THAT 4 DAYS AGO

    But I now want to use the same code on a different mac

    is the different mac also running 1.5.1? because the above was probably changed sometime in the last 3 years.

  • edited December 2017

    Thank you koogs

    for some strangest reason when i download 1.5.1 it just doesn't run on my mac.

    do you think there is any way to change the code so that it runs my old code on the new Processing version? sorry Koogs, I know you have already given me the reference to selectFolder, but can't figure out how what i should put in my code so that it selects the folder i need.

    The way it worked before was: My sketch and folder 'Images' were located in folder A and processing automatically selected folder 'Images' inside folder A to process it, but now it seems like it can't find the location of folder 'Images'

    please please help

  • did you try the example in the reference?

  • Yes, can you have a look please? Screen Shot 2017-12-11 at 16.47.50

  • It doesn't return a result any more. It's a void method. That's what the error means.

    Look closer at the reference example.

  • https://processing.org/reference/selectFolder_.html

    1. give selectFolder the name of a top-level function you intend to write, as a string. This is your "callback"
    2. write that function, e.g. folderSelected. It takes the result of the user dialog box as an argument, and then does... whatever you want.
  • Thank you so much all. Sorry to ask again (and being an overly cheeky beginner) but Jeremydouglas can you can you please kindly advice where exactly on in the code it goes? Soooo need to run this code for a christmas surprise for someone (promise will learn and not ask for such a huge favours when learn it:)

Sign In or Register to comment.