Posted: Fri Jan 25, 2008 8:02 pm Post subject: Gradient Module
Last night I worked tirelessly to perfect gradient colours. As some may remember from a topic that I have cited in my source. I turned what I have gotten so far into a module. It can do various things, although I plan for quite a few more features for future releases.
Here is an example of the module at work:
It is fairly simple. So far there are 3 commands.
Gradient.Box(X1, Y1, X2, Y2, LeftColor, RightColor : int, Ratio : real) - This has a linear gradient.
Gradient.BoxUp(X1, Y1, X2, Y2, TopColor, BottomColor : int, Ratio : real) - This has a vertical linear gradient.
Gradient.Oval(X, Y, Radius, OuterColor, InnerColor : int, Ratio : real) - This is has a radial gradient.
The Oval has to be perfectly round until I figure out some more stuff. Also The ratio is still experimental. Ratio is the parameter that controls the prominence of each color. The lower it is the more the right side will be prominent.
It's not perfect, but it's a start. I will be adding more features gradually and releasing them in this thread. I hope you like it, and find a use for it.
Please feel free to give any suggestions or, feature ideas. Module and examples included.
When i ran this.
the colour becomes imperfect after few key strokes.
I found that after maxcolour gets greater than around 1000
Turing can no longer return a proper number for the colour. (at least on my computer),
the program itself is awesome, it filled a gap in the standard turing features.
good job!
Mackie
Posted: Fri Jan 25, 2008 10:54 pm Post subject: Re: Gradient Module
Ok, I'm currently working out that glitch. It seems just so odd to me though. I don't see any reason why it is happening. Thanks for pointing it out though. It actually helps a lot, because thats something I wouldn't have tried.
StealthArcher
Posted: Sat Jan 26, 2008 12:41 am Post subject: RE:Gradient Module
I think I'll put my brain to work, and add some stuff.
ericfourfour
Posted: Sat Jan 26, 2008 12:55 am Post subject: RE:Gradient Module
Turing might be limited to a certain amount of colour ids. Once it gets to that limit, it has to pick the closest to what you requested.
StealthArcher
Posted: Sat Jan 26, 2008 1:01 am Post subject: RE:Gradient Module
Yeah, I would know, seeing as in my HBM converter I have to have separate procs for red blue and green grdients.
fishtastic
Posted: Sat Jan 26, 2008 2:35 pm Post subject: RE:Gradient Module
if maxcolour > 1023 then
turing stops returning proper colour number.
this is same when you use Pic.New in turing.
Turing allow you to create new colours or preload pictures but only up to a certain num, this is why turing never included gradient drawing.
only if you can somehow destroy the created colours....
StealthArcher
Posted: Sat Jan 26, 2008 2:45 pm Post subject: Re: Gradient Module
Or make Calculatecolor use RGB.SetColor Instead like so (255,RBeg,GBeg,BBeg) then result 255. Voila, never runs out of colors.
I'll upload some changes and improvements I've made tonight.
Sponsor Sponsor
ericfourfour
Posted: Sat Jan 26, 2008 3:31 pm Post subject: RE:Gradient Module
RGB.SetColour modifies what it bases everything off of. If you use RGB.SetColour, you will have to change how you use whatdotcolour, and all of the other colour related functions.
Really, Turing is the problem. The memory manager for colours was poorly designed. There is a Free procedure for pictures, fonts, etc. The RGB module does not have a Free procedure. When HoltSoft designed the module they should have allowed atleast 2^16 instead of 2^10 colour ids.
fishtastic
Posted: Sat Jan 26, 2008 3:56 pm Post subject: Re: Gradient Module
got it. I was so stupid..
simply replace this
Turing:
function CalculateColor (StartColor, EndColor :int, Ratio :real):int
% Variables used to store inputed colors Seperate RGB values. var StartRED, StartGREEN, StartBLUE, EndRED, EndGREEN, EndBLUE :real
% Figures out and stores values from the two inputed values. RGB.GetColour(StartColor, StartRED, StartGREEN, StartBLUE) RGB.GetColour(EndColor, EndRED, EndGREEN, EndBLUE)
% Calculates and declares values used for the result. var RED :real:= StartRED * Ratio + EndRED *(1 - Ratio) var GREEN :real:= StartGREEN * Ratio + EndGREEN *(1 - Ratio) var BLUE :real:= StartBLUE * Ratio + EndBLUE *(1 - Ratio)
% Output Results RGB.SetColour(RED, GREEN, BLUE) end CalculateColor
with this
Turing:
function CalculateColor (StartColor, EndColor :int, Ratio :real):int
% Variables used to store inputed colors Seperate RGB values. var StartRED, StartGREEN, StartBLUE, EndRED, EndGREEN, EndBLUE :real
% Figures out and stores values from the two inputed values. RGB.GetColour(StartColor, StartRED, StartGREEN, StartBLUE) RGB.GetColour(EndColor, EndRED, EndGREEN, EndBLUE)
% Calculates and declares values used for the result. var RED :real:= StartRED * Ratio + EndRED *(1 - Ratio) var GREEN :real:= StartGREEN * Ratio + EndGREEN *(1 - Ratio) var BLUE :real:= StartBLUE * Ratio + EndBLUE *(1 - Ratio)
% Output Results RGB.SetColour(255, RED, GREEN, BLUE) result255 end CalculateColor
then you can have as many colours as you want.
Mackie
Posted: Sat Jan 26, 2008 4:21 pm Post subject: Re: Gradient Module
Oh wow! how did I miss that before! It seems so simple now. -_- +10 Bits!(For Fishtastic and StealthArcher)
Mackie
Posted: Sat Jan 26, 2008 7:15 pm Post subject: Re: Gradient Module
New Features!
Ok, I just implemented some new features:
Gradient.Star (X, Y, Size, Outer Color, Inner Color : int, Ratio : real) - This can only be drawn as a perfect star for now, The Size is added on to the X and Y to create the second coordinates, it's not like an Oval or a Box.
Gradient.MapleLeaf (X, Y, Size, Outer Color, Inner Color : int, Ratio : real) - This is identical to the Star. Except it's a maple leaf instead.
alpha.tu - This is a separate module, that I am building on to the gradient module with, it allows for adjustable opacity of an object. In it's current version it can't do much, it has a few levels of opacity that work, and it can be moved like a sprite. It's extremely slow right now. I have it set up in the file 'example_alpha.t' which shows the best results I have gotten so far. Bare with me as this is just out of the starting blocks.
Posted: Sat Jan 26, 2008 11:39 pm Post subject: Re: Gradient Module
Now I must mess with it, for you opacity is screwed, have no fear, Commodore StealthArbvious is here!
Mackie
Posted: Sat Jan 26, 2008 11:59 pm Post subject: RE:Gradient Module
Haha, I'm trying some serious math on my end. I have gotten an opacity range of 0.0 - 0.3 working perfectly. 0 being solid, and 0.3 being sort of kind of translucent. I just grouped that in with the newest release, as a sort of preview of what's to come.
*cough*
To be done list:
- Alpha Channel. (in beta)
- Selectable gradient styles for ever shape.
- Corner gradient style.(Beta)
- Conical gradient style.
- Reflective Linear gradient style.
- Fix the ratio glitch. (R&D)
- Make shapes radial gradients able to have both a width and height.(R&D)
*cough*
ericfourfour
Posted: Sun Jan 27, 2008 12:42 am Post subject: Re: Gradient Module
The alpha channel is really just a ratio of the foreground to the background. So with an alpha value of 1.0, it will be 100% foreground. With an alpha channel of 0.5, it will be 50% foreground, 50% background. This is not too difficult to do.
I'm going to use my getColour function for simplicities sake:
Turing:
fcn getColour (clr1, clr2 :int, ratio :real):int var r1, g1, b1, r2, g2, b2 :real RGB.GetColour(clr1, r1, g1, b1) RGB.GetColour(clr2, r2, g2, b2) var r :real:= r1 * ratio + r2 *(1 - ratio) var g :real:= g1 * ratio + g2 *(1 - ratio) var b :real:= b1 * ratio + b2 *(1 - ratio) resultRGB.AddColour(r, g, b) end getColour
Now all I have to do is make a function that gets the colour of a pixel (the background colour) and calls the getColour function with that and the specified foreground colour:
Turing:
fcn getAlpaColour (x, y, clr :int, ratio :real):int result getColour (clr, View.WhatDotColour(x, y), ratio) end getAlpaColour
That wasn't too difficult. Here is an example program using the above code: