Glowy ellipses using javaFX bloom [MULTIPLE QUESTIONS]

Multiple questions >

  1. How to make glowy ellipses using javaFX bloom?

  2. How to make ellipse motion effect that it fades in to the ellipse?
    Thank you

EDIT :

  1. And how to import javafx bloom library?
1 Like
  1. surface = (PSurfaceFX) getSurface();
    canvas = (Canvas) surface.getNative();
    canvas.setEffect(new Bloom());
    
  2. fill(255, 100);
    rect(0, 0, width, height);
    
  3. import javafx.scene.effect.Bloom;

Example: This Processing project with bloom effect added.

1 Like

Getting many errors like “PSurface doesn’t exist”

You might have to import that too:

import processing.core.PSurface;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
1 Like

Still getting > “The class ‘PSurfaceFX’ doesn’t exist”, “The variable ‘canvas’ doesn’t exist” and “The name ‘canvas’ cannot be recognized”.

Fix?

Also this is my full code >

import processing.core.PSurface;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.effect.Bloom;

fill(255, 100);
rect(0, 0, width, height);

surface = (PSurfaceFX) getSurface();
canvas = (Canvas) surface.getNative();
canvas.setEffect(new Bloom());
1 Like

You have a setup() and draw() loop right? Or are you completely new to Processing?

Try using

import processing.javafx.PSurfaceFX;

Also, you have to declare

Canvas canvas = (Canvas) surface.getNative();

if it‘s a new Variable.
Same for surface.

1 Like

Still getting error > java.lang.reflect.InvocationTargetException

FULL CODE >

import processing.javafx.PSurfaceFX;
import processing.core.PSurface;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.effect.Bloom;


Canvas canvas = (Canvas) surface.getNative();

void setup() {
  size(800, 600);
}

void draw() {
  fill(255, 100);
rect(0, 0, width, height);

surface = (PSurfaceFX) getSurface();
canvas = (Canvas) surface.getNative();
canvas.setEffect(new Bloom());
}

You can get the cause by adding

try {

} catch (InvocationTargetException e) {
e.getCause().printStackTrace();
}

This way you can see where the problem lies specifically. Please do this and tell us what you got.

Also, you did declare the canvas variable, but never the surface variable in the Code you posted, which is likely the cause of the problem.

Getting error > The class InvokationTargetException doesn’t exist.

Also how do I declare the surface?

You need to include

import java.lang.reflect.InvocationTargetException;

The import java.lang.reflect.InvokationTargetException cannot be resolved

You declare a variable like this

ClassName variableName; //or
ClassName variableName = new ClassName(); // or for primitives
ClassName variableName = ClassValue; // for Int it‘s a number, for String a String like „Hello“ etc.

Edit : It‘s Invocation, not Invokation. (Autocorrect messed me up)

Error > Unreachable catch block for InvocationTargetException. This exception is never thrown from the try statement body

And I still don’t understand, how should I decalre the canvas

Yeah, that just shows that it‘s from outside the function. In this case it‘s very likely from the not declared surface variable.

How do I declare it, like what should I use?

className varName;
className varName = new className();
or
className varName = classValue;

Also I have this in my code > Canvas canvas = (Canvas) surface.getNative();

import processing.javafx.PSurfaceFX;
import processing.core.PSurface;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.effect.Bloom;

PSurfaceFX surface;
Canvas canvas;

void setup() {
  size(800, 600);
}

void draw() {
  fill(255, 100);
rect(0, 0, width, height);

surface = (PSurfaceFX) getSurface();
canvas = (Canvas) surface.getNative();
canvas.setEffect(new Bloom());
}

Since you are going to set surface inside the Setup function, you can just declare it without a specific value. Same for canvas. And pay attention to the order in which variables are set. In this case, if canvas where to already be declared with a value outside the function, you‘d end up refering to the surface variable before it has a value.

Error > ClassCastException: processing.awt.PSurfaceAWT cannot be cast to processing.javafx.PSurfaceFX