draw() function seems to draw background by default

12 views
Skip to first unread message

Jackson

unread,
Oct 2, 2021, 8:05:02 AM10/2/21
to PraxisLIVE discussion group
Hi all, I'm still very much a beginner (2 years with Processing) at this, so if this is a silly question my apologies.

A lot of Processing sketches I like require the background() function to be called once during setup(), and never again. This makes anything drawn in the draw() function start to accumulate over time like a long exposure on a camera.

I've tried the same thing with PraxisLIVE, and I can't seem to stop the output from drawing a black background every frame. If I have a white rectangle in setup(), it is drawn over by the first frame.

I've tried the clear() function to no avail, although I didn't really think it would work anyway.
From what I can tell, either the draw() function inherits this behaviour or the output code draws a background every frame before the input is drawn.

I'm really liking how PraxisLIVE works with Processing code, and I'd like to stick with praxis for my live music - if I can get past this initial hitch.


Neil C Smith

unread,
Oct 2, 2021, 8:15:03 AM10/2/21
to Praxis LIVE software discussion group
Hi,

On Sat, 2 Oct 2021 at 13:05, Jackson <jackson....@gmail.com> wrote:
> Hi all, I'm still very much a beginner (2 years with Processing) at this, so if this is a silly question my apologies.

Welcome! There are no silly questions, just incomplete documentation! :-)

> A lot of Processing sketches I like require the background() function to be called once during setup(), and never again. This makes anything drawn in the draw() function start to accumulate over time like a long exposure on a camera.
...
> From what I can tell, either the draw() function inherits this behaviour or the output code draws a background every frame before the input is drawn.

This is a deliberate difference between Processing and PraxisLIVE.
Because we support having many different components (nodes), each with
their own "sketches", keeping the background would involve keeping a
copy of the output of every single component. Instead, we recycle
surfaces through the pipeline - the output surface gets reused later
down the pipe.

So, to get the effect you want, you need an input port, and to connect
the output to it as well to create a feedback loop.

Code-wise you want

@In(1) PImage in;

public void draw() {
image(in, 0, 0);
// rest of draw
}

This has lots of additional advantages. You can feedback over
multiple nodes, alter how you render the previous frame (eg. position,
opacity), and add FX nodes in the feedback loop.

> I'm really liking how PraxisLIVE works with Processing code, and I'd like to stick with praxis for my live music - if I can get past this initial hitch.

Good to know! Do share what you make with it. Also, as well as here,
you can get help at https://gitter.im/praxis-live/support

Best wishes,

Neil

Jackson

unread,
Oct 2, 2021, 9:45:07 AM10/2/21
to PraxisLIVE discussion group
Thanks Neil, your explanation makes a lot of sense.

I didn't know that feedback loops were even an option, that's a pretty neat trick that'll I'll certainly add to my toolkit.

I ended up using the tint() method inside of a P2D node to allow for changing the opacity of the PImage.
I'm not sure if there is an equivalent Java method that can be called in a regular custom video node.

I'll certainly share what I make and get the word out about such a great piece of software!

Thanks again for your help.
Jackson.

Neil C Smith

unread,
Oct 2, 2021, 10:29:52 AM10/2/21
to Praxis LIVE software discussion group
On Sat, 2 Oct 2021 at 14:45, Jackson <jackson....@gmail.com> wrote:
> I didn't know that feedback loops were even an option, that's a pretty neat trick that'll I'll certainly add to my toolkit.

Yes, it's useful .. and fun!

> I ended up using the tint() method inside of a P2D node to allow for changing the opacity of the PImage.
> I'm not sure if there is an equivalent Java method that can be called in a regular custom video node.

Kind of - in regular custom video nodes you have
https://docs.praxislive.org/coding-video/#blend-modes Some of those
use shaders (difference, bitxor) but will fall back to software if
it's not a full screen image, so watch for that.

Also see the source code for video:composite Which also shows you how
to write code that adds an alpha channel to the input.

> I'll certainly share what I make and get the word out about such a great piece of software!

Thanks! Always good to hear people are enjoying it.

Best wishes,

Neil
Reply all
Reply to author
Forward
0 new messages