Posts: 650
Threads: 26
Joined: Aug 2004
I was saw this webpage: http://rel.betterwebber.com/mytutes/3dtu...apter3.htm
And towards the bottom it showed how to make a color gradient.
But the link to the bas was broken. It there some other tutorial I could find?
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Posts: 1,845
Threads: 44
Joined: Aug 2002
I used to do it this way a few years ago (from NeoLib v1.6b):
Code: SUB neoPalGradient (StartCol AS INTEGER, StartR AS INTEGER, StartG AS INTEGER, StartB AS INTEGER, EndCol AS INTEGER, EndR AS INTEGER, EndG AS INTEGER, EndB AS INTEGER)
'makes a gradient from StartCol to EndCol with the specified colours
' StartCol = gradient start color (0-255)
' StartR = gradient start red amount (0-63)
' StartG = gradient start green amount (0-63)
' StartB = gradient start blue amount (0-63)
' EndCol = gradient end color (0-255)
' EndR = gradient end red amount (0-63)
' EndG = gradient end green amount (0-63)
' EndB = gradient end blue amount (0-63)
noCols = EndCol - StartCol
nowR# = StartR
nowG# = StartG
nowB# = StartB
stepR# = CDBL(EndR - StartR) / noCols
stepG# = CDBL(EndG - StartG) / noCols
stepB# = CDBL(EndB - StartB) / noCols
FOR I = StartCol TO EndCol
neoPalSetCol I, INT(nowR#), INT(nowG#), INT(nowB#)
nowR# = nowR# + stepR#
nowG# = nowG# + stepG#
nowB# = nowB# + stepB#
IF nowR# >= 63 THEN nowR# = 63
IF nowG# >= 63 THEN nowG# = 63
IF nowB# >= 63 THEN nowB# = 63
IF nowR# <= 0 THEN nowR# = 0
IF nowG# <= 0 THEN nowG# = 0
IF nowB# <= 0 THEN nowB# = 0
NEXT I
END SUB
Code: SUB neoPalSetCol (ColorNumber AS INTEGER, Red AS INTEGER, Green AS INTEGER, Blue AS INTEGER)
'sets a specified colour to a color
' ColorNumber = color to change (0-255)
' Red = amount of red (0-63)
' Green = amount of green (0-63)
' Blue = amount of blue (0-63)
OUT &H3C8, ColorNumber
OUT &H3C9, Red
OUT &H3C9, Green
OUT &H3C9, Blue
END SUB
It's the functions for making a palette in the 13h 256 color mode.
Hope this is more or less what you wanted...
Posts: 650
Threads: 26
Joined: Aug 2004
see thats the thing, im not really sure how to use it. maybe you could post an example? im sure i could figure it out then
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Posts: 3,288
Threads: 167
Joined: Nov 2001
Try Phatcode.net
Articles->graphics->rel
Same chapter. :*)
Posts: 1,845
Threads: 44
Joined: Aug 2002
Quote:see thats the thing, im not really sure how to use it. maybe you could post an example? im sure i could figure it out then
After you set your paletted mode, you can call my function like: - neoPalGradient StartCol AS INTEGER, StartR AS INTEGER, StartG AS INTEGER, StartB AS INTEGER, EndCol AS INTEGER, EndR AS INTEGER, EndG AS INTEGER, EndB AS INTEGER[/code]
Where StartCol is the color index where the gradient should begin, EndCol is the color index where the gradient should end. So infact on Rel's picture
the start the first gradient is 0, and the end is 15. For the second gradient it's 16 to 31. (Because each gradient is 16 pixels long in Rel's pic).
The StartR, StartG, StartB indicate the color components Red Green and Blue (0-63) of the starting color at the StartCol index. If your first color in the gradient is black, set it to 0,0,0 if it's white set it to 63,63,63 for example.
EndR, EndG and EndB are the same as StartR/G/B but define the color the gradient should end with.
So if you want a gradient from black to bright yellow on color indexes 0 to 15 you can call it like
neoPalGradient 0, 0, 0, 0, 15, 63, 63, 0
See my reply to rel about rel's gradient code.
Quote:Try Phatcode.net
Articles->graphics->rel
Same chapter. :*)
I've looked at this gradient generation formula as well. It seems he and I use different algorithms for generating gradients. I took it simple and effective and chose linear transition.
Rel on the other hand (being the fantastic 3D guru ) chose for trigonometric transition with a specular component.
It should generate something similar, but Rel's is obviously more difficult for the people not having had trigonometry (let alone matrix algebra for the rest lol).
Oh well, choose for yourself
Posts: 3,288
Threads: 167
Joined: Nov 2001
With that gradient? Nope. Linear. The maxlcolors are even in data staements :*)
No trig.
The plasma did but not that grad. :*)
Posts: 1,845
Threads: 44
Joined: Aug 2002
I didn't say you made that palette using trig. It looks very linear. I said that the palette code Dio was looking for in 3dcolors.bas is not very linear:
Code: CONST PI = 3.14159265358979#
SUB PhongPal (Ra!, Rd!, Rs!, Ga!, Gd!, Gs!, Ba!, Bd!, Bs!, N%, col1%, col2%)
Range% = col2% - col1%
Angle! = PI / 2!
AngleStep! = (PI / 2!) / Range%
FOR i% = col1% TO col2%
CosineOfAngle! = COS(Angle!)
Diffuse! = Rd! * CosineOfAngle!
Specular! = Rs! * (CosineOfAngle! ^ N%)
red% = Ra! + Diffuse! + Specular!
Diffuse! = Gd! * CosineOfAngle!
Specular! = Gs! * (CosineOfAngle! ^ N%)
green% = Ga! + Diffuse! + Specular!
Diffuse! = Bd! * CosineOfAngle!
Specular! = Bs! * (CosineOfAngle! ^ N%)
blue% = Ba! + Diffuse! + Specular!
IF red% > 63 THEN red% = 63
IF green% > 63 THEN green% = 63
IF blue% > 63 THEN blue% = 63
IF red% < 0 THEN red% = 0
IF green% < 0 THEN green% = 0
IF blue% < 0 THEN blue% = 0
OUT &H3C8, i%
OUT &H3C9, red%
OUT &H3C9, green%
OUT &H3C9, blue%
Angle! = Angle! - AngleStep!
NEXT
END SUB
And when I run it most of the colors are white
Posts: 650
Threads: 26
Joined: Aug 2004
relsoft, those examples are pretty neat to look at but im not the kinda person who can just look at code and see what i need. don't get me wrong, i really appreciate both of you help, but something very simple like:
Code: SCREEN 13
c = -1
DO
FOR x = 0 to 255
c = c + 1
LINE (x, 0)-(x, 199), c
NEXT
except with the fading colors. very simple. i hate to be a trouble and all. Thanks so far!
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Posts: 2,765
Threads: 138
Joined: Nov 2002
not really what you were looking for but it's fun to play with =P
Code: screenres 255,255,32
for v1=0 to 255
for v2=0 to 255
for v3=0 to 255
pset (v2,v3),rgb(v1,v2,v3)
next v3
next v2
next v1
sleep
in the rgb(v1,v2,v3) just switch the v's to get different results. like rgb(v1,v3,v2) ect ect.
EDIT: (for FB only)
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 1,272
Threads: 36
Joined: Feb 2003
Ok, here's some code that reproduces that image as precisely as I can manage.
I tried to make it as simple as possible. Code: defint a-z
declare sub fadeFromBlackToColor (red, green, blue)
screen 13
out 968, 0 ' Start at the beginning of the palette
fadeFromBlackToColor 63, 63, 63
fadeFromBlackToColor 63, 0, 0
fadeFromBlackToColor 0, 63, 0
fadeFromBlackToColor 0, 0, 63
fadeFromBlackToColor 0, 63, 63
fadeFromBlackToColor 63, 63, 0
fadeFromBlackToColor 63, 0, 63
fadeFromBlackToColor 31, 23, 63
fadeFromBlackToColor 63, 0, 43
fadeFromBlackToColor 15, 63, 19
fadeFromBlackToColor 43, 44, 63
fadeFromBlackToColor 63, 44, 19
fadeFromBlackToColor 23, 63, 43
fadeFromBlackToColor 55, 63, 35
fadeFromBlackToColor 43, 24, 51
fadeFromBlackToColor 63, 24, 11
' Draw the palette in a 16x16 grid:
c = 0
for y = 0 to 15
for x = 0 to 15
line (x * 10, y * 10)-step(9, 9), c, bf
c = c + 1
next x
next y
sleep
end
' Set the next 16 colors on the palette to a gradient from
' black to (red, green, blue). Each ranges from 0 to 63.
sub fadeFromBlackToColor (red, green, blue)
for i = 0 to 15
out 969, (red * i) \ 15
out 969, (green * i) \ 15
out 969, (blue * i) \ 15
next i
end sub
|