Graphic blending

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Graphic blending

Post by n.allan » Wed Apr 15, 2015 8:32 am

I have a card with around 1000 graphic polygons. I would like to let the user change the backgroundColor of the card to enable a "night mode" such as a dark grey or black background. Is there any way to use the inbuilt blending modes to change the colours of the polygons if they match the background colour so they are visble?

For example if i have black polygons, they would not be visible on a black background. I could iterate through each polygon and do an "if" statement on each polygon colour but this would introduce a noticable lag and my polygon count can be higher. I am simply looking for a more efficient way.

I don't suppose the if statement would be a deal breaker because the user is only likely to switch between "day" mode and "night" mode twice a day :wink:

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Graphic blending

Post by n.allan » Wed Apr 15, 2015 3:00 pm

OK I have found a solution that will work OK for my purpose.

If I group the graphics together and set the "ink" of the group to something such as "notSrcXor" all the graphics in the group will basically be a "negative" of the card background colour. ie a white graphic will turn black on a white card background and vice versa.

I shall have to have a play with this feature as graphics are not really my thing.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Graphic blending

Post by FourthWorld » Wed Apr 15, 2015 4:43 pm

If all the polygons are the same color you may even be able to use a single plugin - their points can be discontiguous.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Graphic blending

Post by n.allan » Wed Apr 15, 2015 5:36 pm

They are various colours and some are non continuous. The colours are pretty important for my application though. Perhaps a better idea would be to limit the users choice of background to only black or white. Then I could do something like...

If the foregroundColour of grc "grcPolygon" is "black" then set the ink of grc "grcPolygon" to "notSrcXor"

If I do this on creation of the graphic, the white lines will be black on a black background but other colours would remain preserved.

Using the notsrcxor ink on a group renders all colours quite goofy in the group. My greens are purple etc.... not cool.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Graphic blending

Post by FourthWorld » Wed Apr 15, 2015 7:21 pm

If you set the lockScreen to true before iterating through your graphics changes you should be able to do that for a thousand objects in about 1/10th of a second.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Graphic blending

Post by n.allan » Wed Apr 15, 2015 9:04 pm

Yes 207 ms here for 1000 if statements using lock screen

I'm not sure how long that would be on an android device or a raspberry pi etc.... plus I would like to have more graphics.

A 10th of a second here and there starts to add up. The sole purpose of my app, after all, is not simply to render 1000 polygons, I'm always looking for small optimizations in every function to squeeze as much performance as possible.

Post Reply

Return to “Multimedia”