Cellular Automata in Processing

Hey, I have simple question. I want implemation the Cellular Automata mechanism in processing, I know how write this automata because i wrote it in c++. I want to create application with GUI and I use the GUI Builder.

My question is how to draw in a special window contained in the main windows? This means the main window I have buttons at the top and at the bottom where the panel wants to be was outlined, it can be done? Or what is the best library to use for this?

Answers

  • This can be done in plain old Processing, I think: you just restrain the drawing of the automata to a given section of the sketch. If it is difficult, for any reason, you can draw on a PGraphics of the size of the drawing area, then draw this PGraphics on the sketch.

  • The most basic way to do this is to draw the buttons yourself. They're just rectangles with text on them. You'd also have to handle the clicking yourself- just check the mouseX and mouseY variables when you detect a click event.

    A step above that would be to use a Processing GUI library, such as ControlP5.

    Another approach would be to embed your Processing sketch inside a Java application, then use Swing or JavaFX to render the buttons. I'm not sure how hard that is now that PApplets no longer extend Applet though.

  • I have question. I did a cellular automat and i have two class cell and grid. The first class has required parameters , second or grid has features such as : display , initiate , environment , etc . And it works ok . I know how to create an object Pgraphics , but my question is how do you draw the window PGraphics ? I have to connect the object PGraphics with my drawing , but I do not know too much like . Does anyone have any idea or simple suggestion for me ( or example) ? I would be very grateful.

  • edited May 2015

    my question is how do you draw the window PGraphics ?

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

    the core idea is to make the PGraphics the size you need later, draw on it and then display it where you want it to be.

  • edited May 2015

    Ok it's work. But in cellular autmat in function display() i have something like that:

    for (int i=0; i<width; i++) { for (int j=0; j<height; j++) { if (cells[i][j].pobierzStan()==2) { set(i*pixel, j*pixel, cells[i][j].pobierzKolor()); } else { set(i*pixel, j*pixel, empty); } } }

    But the set() doesn't work, how to change it? Or is there a counterpart?

  • Answer ✓

    I think

    pg.set(i*pixel, j*pixel, cells[i][j].pobierzKolor());

    like here:

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

  • edited May 2015 Answer ✓
    • the idea is to paint all on the internal PGraphics pg with set() and all these commands and finally put pg out with image(pg, 51, 30);
  • Ok, it's work. Thanks for all

  • great!

Sign In or Register to comment.