Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » EasyToUse Dynamic Color Gradiant Generator

This thread is locked; no one can reply to it. rss feed Print
EasyToUse Dynamic Color Gradiant Generator
Dennis
Member #1,090
July 2003
avatar

[EDIT]
Read the entire thread to find the newest version...;D
or if you're lazy and not interested in any background information, here are related posts:
Miran's latest version with GUI,[url http://www.allegro.cc/forums/view_thread.php?_id=518074#target]
version3 with all *fixes*(the attachment of that post)[/url]
[/EDIT]

http://homepages.compuserve.de/DennisTapier/allegroforum/COLGRAD.PNG

The above pic was created by just these few lines: :D

init_ca_list(&test1);
add_to_ca_list(&test1,POINT,0,0, 255,255,0, 500);
add_to_ca_list(&test1,POINT,639,479,0,255,0,500);
add_to_ca_list(&test1,POINT,320,240,0,0,255,500);
add_to_ca_list(&test1,GLOBAL,40,0,255,255,255,0); 
render_col_grad_to_bitmap(backb,&test1);
kill_ca_list(&test1);

Fully self documented C-sources + precompiled win32 binary(with more examples) is attached.

Share your creations by posting your own EXAMPLE BLOCKS(see inside "main" in code).8-).
[edit]
Hehe, <b>forget about those code blocks. Miran created a GUI for the thing.</b> Scroll further down, grab it and then just post your saved files for everyone to enjoy!;)
[/edit]

Have fun!

Edward Sheets
Member #4,734
June 2004
avatar

Looks good, Dennis :)

Maybe you can tweak your code to make it do some funky gradients like Phipps does in Sunny Ball :D

---

Note: carving a pentagram on the top of a container of spoiled yogurt does not summon a yogurt demon. -Kikaru

Dennis
Member #1,090
July 2003
avatar

I've downloaded SunnyBall to see them...(but i will be too tired today to check it out...yawn, will, go, to, sleep, in, a ,minute...)

[edit]
After a healthy and relaxing sleep of about 8 hours, i played through the demo version of SunnyBall(:D"Fun game Richard!":D) but i'm afraid i could not see any gradients that could not easily be created by my generator... I think it's just a matter of choosing the right bitmap dimensions and setting the correct "color attractors".:) But i might be wrong. Please specify what exact gradiants in SunnyBall you were referring to(the backdrops?,the borders?,the message windows?).

miran
Member #2,407
June 2002

Nice. I made a GUI for this thing: here (535 kB). It's based on my own attempt to figure out how Sunny Ball gfx were made (I was way off btw.) It's C++ source code + statically linked Windows binary + all the original examples :) EDIT: + some of my own examples which are also attached in one of the posts below.

EDIT: Forgot to mention it. I changed x,y and range from absolute values to relative ones typically in the range 0-1 so the gradients can be scaled more easily.

--
sig used to be here

Neil Walker
Member #210
April 2000
avatar

So how do you change any of the values, it always enters values of .5 .5 .5 no matter what you enter as the positions/range.

Neil.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

miran
Member #2,407
June 2002

First you add an attractor or two. Then select the attractor whose values you want to change. Then you type new values in with the keyboard. When you're finished typing you press enter.

--
sig used to be here

Dennis
Member #1,090
July 2003
avatar

miran said:

Nice. I made a GUI for this thing: here (529 kB).

Great miran!
I can't await to play around with it.:D Got to check it out...:):):)

miran said:

I changed x,y and range from absolute values to relative ones typically in the range 0-1 so the gradients can be scaled more easily.

Have not tried the GUI yet... i hope it's possible to enter values outside that range because the generator supports "color attractors" that are outside of the actual bitmap.;)
(btw: Changing the values to relative ones also was on my mind for future versions and improvements, looks like you've read my mind;))

miran
Member #2,407
June 2002

Yeah, it's possible to enter any value. Btw, I didn't change your code (other than to separate it into .h and .cpp files and make it compile as C++), I just added an extra layer between the GUI and your code.

Oh and attached are a few more examples :)

--
sig used to be here

Dennis
Member #1,090
July 2003
avatar

Wooohooo, Miran, I love your GUI.:) Attached is my newest creation "pearls", which is now(thanks to the cool export feature) my desktop background.8-)

crits and usability improvement suggestions(i know lots of work;D):

  • pressing "add" should also change the selected attractor to the one just added, because most time that is the one that will be edited next

  • a "duplicate" button might come in handy

  • would be cool if position could be adjusted by directly clicking the image

  • would also be cool if the used colors would be shown next to each list entry

  • a credits section "GUI by Miran Amon, gradiant algorithm by Dennis Busch"

  • option that the user can save "author" "title" "creation date" text fields into his files

After all, i think your GUI is so cool that actually the whole thing could already be considered a very useful utility.
You should add that to the depot!8-)

da_flo
Member #1,907
February 2002
avatar

I quickly read the source, and the concept is simple and yet the result is impressive ! :D

When I am less tired I'll really look at it. That might motivate me to play myself with my own graphics effect. Yeah I haven't coding in a while, that ought to make me in the mood for speedhack. :)

Dennis
Member #1,090
July 2003
avatar

Make sure you don't miss Miran's GUI for it. It really makes creation easier.;)

da_flo
Member #1,907
February 2002
avatar

Indeed. I used Miran's GUI right from the beginning. :)

I had never tried MASkinG before... I have a program based on the allegro GUI, and I'm now considering using MASkinG instead of porting it to wxWidgets. (and yeah I know, Qt4 rules too, but I got through all the hassle learning wxWidgets, so I might stick with it too :P)

[EDIT] (I hope this will be noticeable enough :-/)

Hey I had an idea to play with your gradient algorithm, Dennis. :)

I love maths and when I have a model or an algorithm, I like to generalize it and play with various parameters.

I was thinking to let the user choose the distance function used in the algorithm. We could use a distance function pointer, and let the user choose between several examples of distances, shown in a listbox.

I have some examples of classical distances in topology :
Norm 1 :

N1(x,y) = |x| + |y|

Norm 2 (euclidian distance) :

N2(x,y) = sqrt(x^2 + y^2)

Norm p :

Np(x,y) = (|x|^p + |y|^p)^(1/p)

Norm infinity :

Ninfinity(x,y) = max(|x|,|y|)

I we use only those norms, we can even use a N(p, x, y) function rather than a function pointer, passing p=-1 for Ninfinity.
The only problem is that it works easily for points, but it becomes tricky we using bars or other objects. I don't know how to compute the distance from a point to a line with non-euclidian distances.
In fact, if I work on the maths, I can perhaps find a formula for the distance to a line with Np, but it might become quite heavy.

What do you think of this idea ? :)
If I find some time, I could do a small program using those norms with points, using the allegro GUI. But if Miran of anyone is motivated to try it, don't wait for me... ;)

miran
Member #2,407
June 2002

Dennis: Updated to version 1.02. Redownload from the link in my first post! :) All your wishes have been implemented, except for number 3. That would take a bit more time (I'm lazy).

da_flo: Won't be too difficult to add. Just add another field to the CA_DESC struct, modify distance_to_ca() and update the GUI :)

--
sig used to be here

Edward Sheets
Member #4,734
June 2004
avatar

Quote:

i could not see any gradients that could not easily be created by my generator

Yeah, I was probably wrong. I was referring to the tiles and background gfx in SunnyBall. There's been speculation as to how Phipps creates those gfx. Maybe gradient is the wrong word for that effect..? Anyhow, it's probably best if we don't anger Phipps by trying to hack into his mind and emulate his methods. ;D

---

Note: carving a pentagram on the top of a container of spoiled yogurt does not summon a yogurt demon. -Kikaru

Richard Phipps
Member #1,632
November 2001
avatar

I'm constantly surprised by people's interest in the gfx engine used in Sunny Ball. I suppose I should be flattered! :)
The engine originally was intended to be used for a flip screen puzzle-platformer in the style of an old game called 'Journey to the Planets'

This was several years ago (sorry guys!), here is one of the first mock up images I did (dated 18th March 2002):

http://www.reflectedgames.com/Images/mockup_screen.png

Unfortunately there would have been a lot of art to do and I am not an artist. Perhaps some day.. :D

Anyway, the technique is not too difficult to do and pretty easy to figure out how it works IMHO. Having said that, while it is useful it does have some limitations so I wouldn't use it for many types of games.

Neil Walker
Member #210
April 2000
avatar

I guess two questions.

1. How fast is it in realtime for generating a full screen bitmap (as in does it have to be pre-rendered to a bitmap outside of any timer loop)

2. Has anyone tried doing any blending over images? I'm thinking something like this effect would be cool:

http://images.amazon.com/images/P/B000002LRJ.01._SCLZZZZZZZ_.jpg

Attached is my closest rendition

[edit]
It would be nice to be able to move the attracters up/down as I added black at the end but it never shows, I need it to be at the start.

Neil.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Dennis
Member #1,090
July 2003
avatar

da_flo:
I will examine your post more closely when i'm offline.

Richard(thanks for following the invitation):
Looking at your screenshot, i guess i know how it works:
I think you're computing gradiants on several bitmaps and then copy only
polygonal areas of them in a certain blit order to get these nicely layered, color faded screens.;)

miran said:

All your wishes have been implemented, except for number 3.

Thanks alot, i will try it out.:)

Neil said:

It would be nice to be able to move the attracters up/down as I added black at the end but it never shows, I need it to be at the start.

The position of any attractor inside the list has no effect to the result. Black never shows because of the mixing method that my attractors only evers ADDS fractions of colors. But i could invent detractors that would take away fractions of colors but then list position would matter and that would require too much work for now(i'm even more lazy than miran;)) [edit]hm...maybe list position would not matter if i let negative color values stay valid until the call to putpixel...[/edit]
On your questions:
1: depends on resolution and bitdepth(32bpp fastest, 8bpp slowest due to color conversion).
2: the current algorithm does not support that(because its not "blending" anything), but you could do it in any image manipulation programm, using the exported image.

miran
Member #2,407
June 2002

Quote:

The position of any attractor inside the list has no effect to the result. Black never shows because of the mixing method that my attractors only evers ADDS fractions of colors. But i could invent detractors that would take away fractions of colors but then list position would matter and that would require too much work for now(i'm even more lazy than miran;)

I already added the ability to move attractors up and down in the list. It's just that I disabled it (as in commented the relevant code out) because I realized the order has no effect.

As for different blenders, that would be a good idea. Having just ADD is kind of limiting, because you can't darken a part of the image. Every attractor just adds to the colour and moves it towards white. I don't know exactly how those blenders I have in my PSP work, but there are many of them: multiply, screen, dissolve, dodge, burn, overlay, hard light, soft light, etc.

Another thing that you could make is add linearity to POINT, VBAR and HBAR (I don't know if linearity is the right word). Right now the gradients are fully linear, that is, at the centre of the point you have full colour, then it fades linearly towards the edge. You'd get a lot more flexibility if you could define how fast or slow the gradinet should fade. If you know what I mean :-/ (Maybe that's what da_flo was talkin about. I'm not good at this advanced maths stuff.)

--
sig used to be here

Dennis
Member #1,090
July 2003
avatar

I think i know what you mean miran(it involves calculus, in which i'm not very good...) you want a function for each attractor that calculates its' intensity influence in relation to distance(currently this is linear because just the plain distance is calculated).
(i know i should not but i fear that particular field of math)

For a first small improvement, i will look into adding support for SUBTRACT(color "absorbers") now, so that areas can be darkened(i will implement this in a way that list positions will not matter) and the funny thing will be that the absorber will work like mixing but in the opposite direction(as in: I'm an absorber and i'm very selective about what color fractions i'll take away.:))

I think i've found a BUG:( in the FileSaving Dialog:
When i press enter inside the FileTextEditField it always(?or only if the file does not exist,but even if a proper ending .wcol is entered) assumes that the entered text is a directory and places a \ behind it and then nothing happens, pressing enter again sometimes crashes the thing(my by hand avoid crash method: Enter Text and then use mouse to press OK).

da_flo:
Maybe your suggestions would be the same as having individual intensity(distance) functions for each attractor? I'm a little puzzled.

Attached are some more simple examples and an iconized version of miran's "flair" to replace that AlexAllegator icon.

miran
Member #2,407
June 2002

I added linearity settings :) This time I did modify your code (in wcolgradgen.h and wcolgradgen.cpp) so if you work on it some more, it'd be best if you didn't loose my changes :)

About the file selector bug, I know about that, I've know abotu it for a long time. Will fix some day...

EDIT: And now version 1.04 is up. You can now place attractors by clicking on the preview. Left click moves the attractor, right click defines range. You can only move inside the image though...

--
sig used to be here

Neil Walker
Member #210
April 2000
avatar

Lovely.

Now, don't get me wrong here, but while Masking looks very pretty, the interface is crap. Unless its just a coding thing?

What I see thats wrong is the focus automatically selects a field when you go over it. so, you're typing into a box and nudge the mouse, all of a sudden you're typing into the next box! the other annoying this is whenever I select a field to start typing I always two characters of the key I've pressed.

Neil.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

miran
Member #2,407
June 2002

This is configurable. For key repeat and delay open allegro.cfg and modify the relevant fields. For example:

keyDelay = 300
keyRepeat = 150

For focus changing when mouse moves open the skin file (skins/kde2.ini) and change focus=1 to focus=2.

Btw, this is very similar as in the built-in Allegro GUI...

--
sig used to be here

Dennis
Member #1,090
July 2003
avatar

I will check your code later miran(to see if i can incorporate your changes into mine).
Unfortunately:( i was working on my new version the last few hours and thus did not see you already changed it.
(Should not be too difficult to inc your changes though as my changes do fully preserve the entire version1 codebase;D.)

(i'll just post what i have made while i was offline)
http://homepages.compuserve.de/DennisTapier/allegroforum/COLGRAD2.PNG

Showing example one of the old version plus an added ABSORBER absorbing everything(color(255,255,255)).

New version 2 is attached(sources + precompiled statically linked win32 binary).
(Check readme.txt and new comments):)

NEW Features:
-Color ABSORBER
-Effect Modifier (*experiment with this to find out how it affects the colors*)
 Where in the previous version "distance" was used to calculate the effect,
 now "effect_modifier" is used.
 It is calculated as effect_modifier = p * distance^exp.
 p and exp are set individually for each ATTRACTOR.
 (set p=1.0 and exp=1.0 to get the same behaviour as in version1)

miran
Member #2,407
June 2002

Heh, your exp in the effect modifier is my linearity :) Except I did it with a look-up table, otherwise it is too slow and I don't have the p coefficient yet.

--
sig used to be here

Dennis
Member #1,090
July 2003
avatar

Does that eliminate my need to look at your code?;)



Go to: