• August 14, 2022, 09:43:19 PM

Author Topic: (Question) Rendering the Mandelbrot in Java(fx) only shows result  (Read 100 times)

0 Members and 1 Guest are viewing this topic.

Online Microfractal

  • I like deep mandelbrot zooms!
  • Fractal Flamingo
  • ****
  • Posts: 331
(Question) Rendering the Mandelbrot in Java(fx) only shows result
« on: June 05, 2022, 09:31:40 PM »
Hello, I dived into Java(fx) a couple of weeks ago and am in the process of programming a Mandelbrot. The good thing is that I can quickly create graphical controls with Scenebuilder. The result is also a Mandelbrot, but a problen still exists. When I calculate the Mandelbrot with a method and map the result as a pixel on the canvas, the application only shows me the end result. In other words, when I call the method 'render', the program does not show me the process of rendering (for example, that the program draws one line after the other), but you see nothing, with 100000 iterations that is maybe 4 seconds. Only then you see the fractal. In this time you can not close the program, and also not use. I am writing this text in the hope that someone can tell me how to update the canvas. In the internet I just can't find anything suitable...

Linkback: https://fractalforums.org/index.php?topic=4778.0

Offline 3DickUlus

  • Administrator
  • 3f
  • *******
  • Posts: 3037
Re: Rendering the Mandelbrot in Java(fx) only shows result
« Reply #1 on: June 05, 2022, 10:38:51 PM »
Does it show a "busy" cursor or something to indicate that it's actually doing something? That would at least let the user know that it's working.

if the YX loop is nested inside a single function to generate the data then you may need to break the YX loop into separate functions, calling the X loop function from the Y loop function and calling display(data) or updateView() function on each iteration of the Y loop.

Or call display(data) or updateView() function after each iteration of the Y loop in the nested YX loop.

Is this a web app ie:viewed in a browser or a standalone desktop app?

Without seeing the code it's a guessing game.
« Last Edit: June 05, 2022, 10:53:16 PM by 3DickUlus »

Online Microfractal

  • I like deep mandelbrot zooms!
  • Fractal Flamingo
  • ****
  • Posts: 331
Re: Rendering the Mandelbrot in Java(fx) only shows result
« Reply #2 on: June 06, 2022, 10:41:10 AM »
It is a desktop app.
Here is a different code with the same problem...
Code: [Select]
@FXML
Canvas image;
protected void render() {
        GraphicsContext fractal = image.getGraphicsContext2D();
        for (int y = 0; y < 200; y++) {
            for (int x = 0; x < 200; x++) {
                for (int k = 0; k < 10000; k++) {
                    k--;
                    k++;
                }
                fractal.setFill(Color.rgb(0,0,0));
                fractal.fillRect(x,y,1,1);
            }
        }
    }

the k < 10000 is for the delay.
It shows also only the result.

Offline superheal

  • Fractal Feline
  • **
  • Posts: 199
Re: Rendering the Mandelbrot in Java(fx) only shows result
« Reply #3 on: June 06, 2022, 10:59:29 AM »
I have a java app of my own, not in javafx but swing. Can you trigger a repaint of the canvas? This was the case for swing.

Offline 3DickUlus

  • Administrator
  • 3f
  • *******
  • Posts: 3037
Re: Rendering the Mandelbrot in Java(fx) only shows result
« Reply #4 on: June 07, 2022, 04:30:54 AM »
quote from https://edencoding.com/force-refresh-scene/
Quote
As a basic rule, there are two reasons that your scene wouldn’t refresh:

    1. JavaFX doesn’t know about the changes you’ve made.
    2. You’re preventing JavaFX from checking whether to refresh your scene.

The link above is very informative about javafx scene refresh, it goes on to explain registering a listener on the scene’s refresh pulse.
As I mentioned, you may have to break the loop into separate functions and trigger Xloop on javafx's pulse/tick that refreshes the display. It's currently refreshing before render() and after render() but not during the actual render() function (probably because of the load the nested loop places on the cpu).

Basically remove the Yloop and call render() 60 times a second (return if not finishedX, next Y when ready)

Disclaimer: I'm not a java programmer ;)


xx
gallery lightbox description shows raw bbcodes instead of formatting them

Started by claude on Discuss Fractalforums

3 Replies
473 Views
Last post September 20, 2017, 11:12:39 AM
by Fraktalist
clip
Colored Boundary rendering style

Started by hobold on Programming

7 Replies
311 Views
Last post April 04, 2022, 09:25:52 AM
by hobold
lamp
Help needed (with Java)

Started by Sfumato on JWildfire

0 Replies
494 Views
Last post March 28, 2020, 11:41:39 AM
by Sfumato
xx
Coding Distance Estimation in Java

Started by dankje on Noob's Corner

11 Replies
130 Views
Last post May 05, 2022, 10:01:41 AM
by claude
xx
Arbitrary precision Java

Started by superheal on Programming

0 Replies
189 Views
Last post September 18, 2021, 05:55:18 PM
by superheal