[bb] Colours By Name by Streaksy [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:39

Previous topic - Next topic

BlitzBot

Title : Colours By Name
Author : Streaksy
Posted : 1+ years ago

Description : Instead of using:
Color 152,141,121
ClsColor 152,141,121


You can now use:
Colour "Magenta"
ClsColour "Burgundy"

(The UK spelling instead of the US spelling.  Easily changed if you don't like it.)

You can supply a brightness aswell.  255 is normal.  Less than that is dark, higher than that is light.  I guess it goes 0-512.  eg. Colour "Red",150

That's useful for the 3D effects on window edges etc., when you want to easily get the lighter/darker equivelents of a colour.

I love my colour list for some reason.  I've nurtured it for a long time. :P
At the start of the code is a constant, Colour_Demo.  If it's set to one, when you run it, you get a colour chart.  If not, the program runs as normal.  It's all arranged as an includable.

It's best to keep the colour chart code in to use as a reference.  Compiled EXEs won't have the code for it anyway as IFs that involve a constant dont get their contents compiled if it the result is false.

I first started on this like 2 years ago because I made a GUI library with colour dialogues to choose the interface's colours etc.  Now I just keep it as a bit of fun mostly that might come in handy.  I've enjoyed making the list and getting the colours right.  

There's a bunch of other colour fuctions aswell.

Edit: Just realised I still had the RGB2HSB code in.  I think it was by `jfk EO-11110'.  I took it out because it's not mine.  (It's great code and if you want it it's in the Algorithms section of the code archives.)
. [/i]

Code :
Code (blitzbasic) Select
Const Colour_Demo=1         ;run this bb with this const set
as 1 to see the colour chart


Const ColourLibPresent=1

Global BGcolR=-1,BGcolG=-1,BGcolB=-1

Global Colours,MaxColours=200
Dim ColourName$(MaxColours)
Dim ColourLen(MaxColours)
Dim ColourR(MaxColours)
Dim ColourG(MaxColours)
Dim ColourB(MaxColours)
Dim ColourRGB(MaxColours)

Global sat#,lumin#,hue# ;returned by RGB2HSB()

AddColour "Blue"                  ,65,95,255
AddColour "Red"                   ,215,25,25
AddColour "Yellow"                ,255,215,55
AddColour "Green"                 ,75,215,35
AddColour "Orange"                ,245,131,25
AddColour "Brown"                 ,85,45,25
AddColour "Pink"                  ,255,125,165
AddColour "Purple"                ,122,0,100
AddColour "Cyan"                  ,85,195,255
AddColour "Aqua"                  ,85,215,135
AddColour "Indigo"                ,100,38,204
AddColour "Violet"                ,145,65,255
AddColour "Magenta"               ,238,2,128
AddColour "Fuchsia"               ,210,0,90
AddColour "Lilac"                 ,190,150,250
AddColour "Lavender"              ,160,150,250
AddColour "Teal"                  ,0,167,160
AddColour "Turquoise"             ,0,210,170
AddColour "Mauve"                 ,186,126,150
AddColour "Beige"                 ,209,196,174
AddColour "Jade"                  ,53,133,85
AddColour "Cream"                 ,240,225,170
AddColour "Taupe"                 ,174,159,138
AddColour "Buff"                  ,76,86,80
AddColour "Peach"                 ,255,180,80
AddColour "Nutmeg"                ,128,100,70
AddColour "Plum"                  ,70,14,54
AddColour "Salmon"                ,229,107,83
AddColour "Burgundy"              ,65,5,34
AddColour "Tan"                   ,190,130,80
AddColour "Olive"                 ,97,108,53
AddColour "Chestnut"              ,92,32,16
AddColour "Navy Blue"             ,0,38,73
AddColour "Sky Blue"              ,105,135,245
AddColour "Lemon"                 ,255,255,55
AddColour "Lime"                  ,5,205,5
AddColour "Hot Pink"              ,245,0,200
AddColour "Mint"                  ,172,255,172
AddColour "Walnut"                ,163,129,79
AddColour "Coral"                 ,252,125,95
AddColour "Cherry"                ,175,0,30
AddColour "Maroon"                ,88,28,33
AddColour "Azure"                 ,13,119,183
AddColour "Cedar"                 ,163,43,64
AddColour "Safron"                ,255,180,0
AddColour "Crimson"               ,95,0,10
AddColour "Scarlet"               ,135,15,15
AddColour "Royal Purple"          ,70,0,90
AddColour "Slate"                 ,56,59,63
AddColour "Khaki"                 ,154,130,94
AddColour "Oatmeal"               ,215,200,150
AddColour "Raspberry"             ,155,15,65
AddColour "Mahogany"              ,54,22,0
AddColour "Heather"               ,125,85,105
AddColour "Avocado"               ,198,192,116
AddColour "Pea Green"             ,98,143,57
AddColour "Wine"                  ,122,11,56
AddColour "Watermellon"           ,236,91,89
AddColour "Sand"                  ,177,139,88
AddColour "Candy Pink"            ,255,85,195
AddColour "Chocolate"             ,73,50,34
AddColour "Grape"                 ,140,170,100
AddColour "Flamingo"              ,255,62,138
AddColour "Terracotta"            ,225,115,70
AddColour "Auburn"                ,75,23,9
AddColour "Rose"                  ,229,144,150
AddColour "Mustard"               ,200,180,20
AddColour "Caramel"               ,170,110,0
AddColour "Honey"                 ,235,170,46
AddColour "Parchment"             ,225,196,149
AddColour "Kiwi"                  ,112,156,45
AddColour "Cucumber"              ,190,210,99
AddColour "Vanilla"               ,249,241,143
AddColour "Almond"                ,187,167,140
AddColour "Clay"                  ,143,131,114
AddColour "Banana"                ,249,242,80
AddColour "Strawberry"            ,255,95,55
AddColour "Spice"                 ,210,80,0
AddColour "Sorbet"                ,185,85,85
AddColour "Cargo"                 ,100,92,73
AddColour "Milkshake"             ,255,155,175
AddColour "Velvet"                ,171,39,78
AddColour "Amaranth"              ,130,45,90
AddColour "Tomato"                ,203,58,19
AddColour "Amethyst"              ,145,85,165
AddColour "Curry"                 ,165,140,20
AddColour "Butter"                ,254,251,174
AddColour "Toffee"                ,165,85,35
AddColour "Burlap"                ,150,110,60
AddColour "Willow"                ,45,190,100
AddColour "Highlight"             ,225,250,40
AddColour "Menthol"               ,145,255,195
AddColour "Lemon Curd"            ,234,222,116
AddColour "Citrus"                ,255,150,0
AddColour "Buttermilk"            ,255,255,214
AddColour "Moss"                  ,75,90,30
AddColour "Basalt"                ,66,66,55
AddColour "Girly Pink"            ,246,146,217
AddColour "Blush"                 ,255,55,55
AddColour "Morocco"               ,180,40,0
AddColour "Glamour Girl"          ,200,0,140
AddColour "Herbal"                ,100,140,100
AddColour "Soft Blue"             ,55,85,175
AddColour "Tiger Lily"            ,231,60,9
AddColour "Brick"                 ,121,47,36
AddColour "White Chocolate"       ,255,255,193
AddColour "Sour Yellow"           ,225,250,80
AddColour "Soft Orange"           ,255,135,65
AddColour "Denim"                 ,135,165,232
AddColour "Deep Pink"             ,200,80,144
AddColour "Vivid Purple"          ,165,5,255
AddColour "Silver Grey"           ,155,155,177
AddColour "Warm Pink"             ,226,90,110
AddColour "Mud"                   ,125,70,25
AddColour "Desert Camo"           ,190,150,80
AddColour "Cheese"                ,236,185,73
AddColour "Grass"                 ,112,149,38
AddColour "Soft Pink"             ,215,105,125
AddColour "Fern"                  ,40,130,0
AddColour "Gloom"                 ,50,70,60
AddColour "Night Blue"            ,65,65,120
AddColour "Sea Storm"             ,60,100,120
AddColour "Slime"                 ,125,195,35
AddColour "Glow Stick"            ,205,250,100
AddColour "Airy Blue"             ,100,130,150
AddColour "Natural Green"         ,104,125,55
AddColour "Sandstone"             ,115,115,70
AddColour "Bright Blue"           ,185,195,255
AddColour "Bright Green"          ,175,255,135
AddColour "Toxic Yellow"          ,155,155,0
AddColour "Toad"                  ,59,62,40
AddColour "Swamp"                 ,43,48,38
AddColour "Neutral Blue"          ,5,65,85
AddColour "Caucasia"              ,215,170,130
AddColour "Homey"                 ,124,77,59
AddColour "Twilight"              ,28,28,44
AddColour "Sycamore"              ,105,90,40
AddColour "Volcanic"              ,44,28,28
AddColour "Fire"                  ,255,90,14
AddColour "Ice"                   ,125,220,255
AddColour "Troll"                 ,28,44,28
AddColour "Poison"                ,125,250,40
AddColour "Dark Aqua"             ,29,104,100
AddColour "Fog"                   ,139,164,140
AddColour "Metalic"               ,153,172,160
AddColour "Mineral"               ,192,192,160
AddColour "White"                 ,255,255,255
AddColour "Light Grey"            ,165,165,165
AddColour "Grey"                  ,122,122,122
AddColour "Dark Grey"             ,65,65,65
AddColour "Charcoal"              ,24,24,24
AddColour "Opaque Black"          ,2,2,2

AddColour "Light Blue"            ,115,145,255
AddColour "Light Red"             ,255,35,35
AddColour "Light Yellow"          ,255,225,95
AddColour "Light Green"           ,115,255,85
AddColour "Light Orange"          ,255,171,75
AddColour "Light Brown"           ,125,85,55
AddColour "Light Pink"            ,255,175,205
AddColour "Light Purple"          ,152,70,170

AddColour "Dark Blue"             ,35,30,100
AddColour "Dark Red"              ,115,15,15
AddColour "Dark Yellow"           ,155,115,22
AddColour "Dark Green"            ,39,107,19
AddColour "Dark Orange"           ,145,71,17
AddColour "Dark Brown"            ,42,23,17
AddColour "Dark Pink"             ,165,75,99
AddColour "Dark Purple"           ,62,0,50

AddColour "Black"                 ,0,0,0
AddColour "System Red"            ,255,0,0
AddColour "System Green"          ,0,255,0
AddColour "System Yellow"         ,255,255,0
AddColour "System Blue"           ,0,0,255
AddColour "System Magenta"        ,255,0,255
AddColour "System Cyan"           ,0,255,255


If Colour_Demo Then
ofx=18
ofy=15
sp=10
w=133;230
h=20;33
;Graphics 1280,1024,32,1
Graphics 1024,768,32,2
SetBuffer BackBuffer()
SetFont LoadFont("tahoma",18) ; lucida console 21
ClsColour "khaki"
Repeat
Cls
mmsx=MouseX()
mmsy=MouseY()
mmd2=MouseDown(2)
x=ofx
y=ofy
For c=1 To colours
colour c
If mmd2=0 Then Rect x,y,w,h,1:Colour c,150:Text x+(w/2)-1,y+1+(h/2),colourname(c),1,1:Colour c,160; Color 0,0,0
Rect x,y,w,h,0
Rect x+1,y+1,w-2,h-2,0
If mmd2=0 Then Colour c,390
Text x+(w/2),y+(h/2)-1,colourname(c),1,1

If mmsx=>x And mmsy=>y And mmsx=<x+w And mmsy=<y+h Then Rect x,y,w,h,0:If MouseDown(1) Then ClsColor colourr(c),colourg(c),colourb(c)
y=y+h+sp:If y+h>GraphicsHeight() Then y=ofy:x=x+w+sp
Next
Flip
Until KeyHit(1)
End
EndIf



Global maxremcols=100,remcolat=0
Dim remcolr(maxremcols)
Dim remcolg(maxremcols)
Dim remcolb(maxremcols)
Global cremred,cremgreen,cremblue


Dim alut(600,3) ;MIXCOLOURS()
Local r
For r=1 To 600
c=r
If c>255 c=255
alut(r,1) = (c And 255) Shl 16
alut(r,2) = (c And 255) Shl 8
alut(r,3) = (c And 255)
Next




Function RememberColour()
cremred=ColorRed()
cremgreen=ColorGreen()
cremblue=ColorBlue()
If remcolat=maxremcols Then Return
remcolat=remcolat+1
remcolr(remcolat)=cremred
remcolg(remcolat)=cremgreen
remcolb(remcolat)=cremblue
End Function

Function RecallColour()
If remcolat=0 Then Color cremred,cremgreen,cremblue:Return
Color remcolr(remcolat),remcolg(remcolat),remcolb(remcolat)
remcolat=remcolat-1
End Function



Function Alpha(hue)
Return (hue And $FF000000) Shr 24
End Function

Function Red(hue)
Return (hue And $00FF0000) Shr 16
End Function

Function Green(hue)
Return (hue And $0000FF00) Shr 8
End Function

Function Blue(hue)
Return (hue And $000000FF)
End Function

Function ARGB(A,R,G,B)
Return RGBA(r,g,b,a)
End Function

Function RGBA(R,G,B,A=255)
If a<0 Then Return (R*256*256)+(g*256)+b
Return A Shl 24 Or R Shl 16 Or G Shl 8 Or B; Shl 0
End Function

Function MixColours(col1,col2,a#)
Local na#,rr1,gg1,bb1,rr2,gg2,bb2
na#=a
a=1-a
rr1=((col1 Shr 16) And 255) *a
gg1=((col1 Shr 8) And 255) *a
bb1=(col1 And 255) *a
rr2=((col2 Shr 16) And 255) *na
gg2=((col2 Shr 8) And 255) *na
bb2=(col2 And 255) *na
Return $ff000000 Or aLut(rr1+rr2,1) Or aLut(gg1+gg2,2) Or aLut(bb1+bb2,3)
End Function



Function AddColour(N$,R,G,B)
If colours=maxcolours Then RuntimeError "Too many colours."
Colours=Colours+1
ColourName$(Colours)=N$
Colourlen(Colours)=Len(N$)
colourr(colours)=r
colourg(colours)=g
colourb(colours)=b
colourRGB(colours)=rgba(r,g,b,255)
End Function

Function FindColour(n$)
n=Lower(n):l=Len(n)
For t=1 To colours
If colourlen(t)+l Then If n=Lower(colourname(t)) Then Return t
Next
End Function

Function Colour(n$,bri=255) ;bri goes from 0 to 512 ... 255 is normal!
t=Int(n)
If t=0 Then t=findcolour(n)
If bri=255 Then Color colourr(t),colourg(t),colourb(t):Return t
If bri<255 Then Color (colourr(t)*bri)/255,(colourg(t)*bri)/255,(colourb(t)*bri)/255:Return t
If bri>255 Then tw#=bri-255:tw=tw/255:Color cbetween(colourr(t),255,tw#),cbetween(colourg(t),255,tw#),cbetween(colourb(t),255,tw#):Return t
Return t
End Function
Function cBetween#(v1#,v2#,t#):dif#=v2-v1
Return v1+(dif*t)
End Function



Function CLSColour(n$,bri=255) ;bri goes from 0 to 512 ... 255 is normal!
t=Int(n)
If t=0 Then t=FindColour(n)
If bri=255 Then ClsColor colourr(t),colourg(t),colourb(t):Return t
If bri<255 Then ClsColor (colourr(t)*bri)/255,(colourg(t)*bri)/255,(colourb(t)*bri)/255:Return t
If bri>255 Then tw#=bri-255:tw=tw/255:ClsColor cbetween(colourr(t),255,tw#),cbetween(colourg(t),255,tw#),cbetween(colourb(t),255,tw#):Return t
Return t
End Function



Function SetBGColour(col$):bgcolour col:End Function

Function BGColour(col$)
If Lower(c)="transparent" Then bgcolr=-1:bgcolb=-1:bgcolg=-1
c=FindColour(col)
BGcolR=colourr(c)
BGcolG=colourg(c)
BGcolB=colourb(c)
End Function


Function CStringWidth(tx$)
getting=1
For t=1 To Len(tx)
c$=Mid(tx,t,1)
If c="{" Then getting=0
If c="}" Then getting=1:c=""
If getting Then tx2$=tx2+c
Next
Return StringWidth(tx2)
End Function









Function CText(x,y,tx$,cx=0,cy=0)
Local cod$,cod1$,cod2$
rd=ColorRed():gr=ColorGreen():bl=ColorBlue()
rd3=bgcolr:gr3=bgcolg:bl3=bgcolb
If cx Then x=x-(CStringWidth(tx$)/2)
If cy Then y=y-(FontHeight()/2)
getting=1
For t=1 To Len(tx)
c$=Mid(tx,t,1)
If c="{" Then getting=0:c=""
If c="}" Then
getting=1
c="":cod1$="":cod2$=""
If Len(cod)>4 Then cod1$=Upper(Left(cod,4)):cod2=Right(cod,Len(cod)-4)
If cod1="COL:" Then Colour cod2
If cod1="BGC:" Then BGColour cod2
cod=""
EndIf
If getting Then
If bgcolr>-1 Or bgcolg>-1 Or bgcolb>-1 Then rd2=ColorRed():gr2=ColorGreen():bl2=ColorBlue():Color bgcolr,bgcolg,bgcolb:Rect x,y,StringWidth(c),FontHeight(),1:Color rd2,gr2,bl2
Text x,y,c:x=x+StringWidth(c)
EndIf
If getting=0 Then cod$=cod+c$
Next
bgcolr=rd3:bgcolg=gr3:bgcolb=bl3
Color rd,gr,bl
End Function


Comments :


Zeke(Posted 1+ years ago)

 Hi, some of your codes are very usefull.. but unfortunately code is to blitz3d..... BUT this is so easy to convert bmax code.. so, Thanks.


_PJ_(Posted 1+ years ago)

 Wow, how long did that take to wriote out all the colours??? :)If it helps, to make it easier to identify some 'common' aRGB Hex values, I made a few of my own. These were specifically for use with the Blitzsys.dll DLLColor... functions:
Const COL_WHITE% = 16777215
Const COL_BLACK% = 16777216

Const COL_RED = 255
Const COL_GREEN=65280
Const COL_BLUE=16711680

Const COL_YELLOW= 65535
Const COL_CYAN=16776960
Const COL_MAGENTA=16711935

Const COL_ORANGE=32303
Const COL_EMERALD=65408
Const COL_AMETHYST=16711808
Const COL_SAPPHIRE=16744448
Const COL_RUBY=8388863
Const COL_AQUA=8453888

Const COL_VIOLET=16744576
Const COL_APPLE=8454016
Const COL_STRAWBERRY=8421631
Const COL_BANANA=8454143
Const COL_PINK=16744703
Const COL_ICE=16777088

Const COL_FLESH=8438015
Const COL_GOLD=49407

Const COL_LEAF=32768
Const COL_BERRY=128

Const COL_BLOOD=63
Const COL_CERULEAN=12615680
Const COL_WOOD=12615680

Const COL_CHARCOAL=4144959
Const COL_LEAD=8421504
Const COL_STEEL=10526880
Const COL_SILVER=12632256



Bobysait(Posted 1+ years ago)

 nice stuff !a litle improvment for the demo-> use an image to grab colours, so we don't draw rects every frameIf Colour_Demo Then
ofx=18
ofy=15
sp=10
w=133
h=20
Graphics 1024,768,0,2
SetBuffer BackBuffer()
SetFont LoadFont("tahoma",18) ; lucida console 21

; draw colours to an image
Local ColoursImg = CreateImage(1024,768)
CLSColour "black"
SetBuffer ImageBuffer(ColoursImg)
x=ofx
y=ofy
For c=1 To Colours
Colour c
Rect x,y,w,h,1:Colour c,150:Text x+(w/2)-1,y+1+(h/2),ColourName(c),1,1:Colour c,160
Rect x,y,w,h,0
Rect x+1,y+1,w-2,h-2,0
Colour c,390
Text x+(w/2),y+(h/2)-1,ColourName(c),1,1
y=y+h+sp:If y+h>GraphicsHeight() Then y=ofy:x=x+w+sp
Next
SetBuffer BackBuffer()

CLSColour "khaki"
Repeat
Cls
DrawImage ColoursImg,0,0
mmsx=MouseX()
mmsy=MouseY()
mmd2=MouseDown(2)
x=ofx
y=ofy
For c=1 To Colours
If RectsOverlap(x,y,w,h,mmsx,mmsy,1,1) Then Colour c,390:Rect x,y,w,h,0:If MouseDown(1) Then CLSColour ColourName(c);ClsColor ColourR(c),ColourG(c),ColourB(c)
y=y+h+sp:If y+h>GraphicsHeight() Then y=ofy:x=x+w+sp
Next
Flip
Until KeyHit(1)
FreeImage ColoursImg
End
EndIf



Jesse(Posted 1+ years ago)

 I did something similar to what you did but for Bmax. I got all of the valid html colors and converted the to an object:Type Tcolor
Field _Red :Int
Field _Green :Int
Field _Blue :Int
Field _Alph :Float

Const INDIANRED:Int =0
Const LIGHTCORAL:Int =1
Const SALMON:Int =2
Const DARKSALMON:Int =3
Const CRIMSON:Int =5
Const Red:Int =6
Const FIREBRICK:Int =7
Const DARKRED:Int =8

'Pink colors

Const PINK:Int =10
Const LIGHTPINK:Int =11
Const HOTPINK:Int =12
Const DEEPPINK:Int =13
Const MEDIUMVIOLETRED:Int =14
Const PALEVIOLETRED:Int =15

'Orange colors

Const LIGHTSALMON:Int =17
Const CORAL:Int =18
Const TOMATO:Int =19
Const ORANGERED:Int =20
Const DARKORANGE:Int =21
Const ORANGE:Int =22

'Yellow colors

Const GOLD:Int =24
Const YELLOW:Int =25
Const LIGHTYELLOW:Int =26
Const LEMONCHIFFON:Int =27
Const LIGHTGOLDENRODYELLOW:Int =28
Const PAPAYAWHIP:Int =29
Const MOCCASIN:Int =30
Const PEACHPUFF:Int =31
Const PALEGOLDENROD:Int =32
Const KHAKI:Int =33
Const DARKKHAKI:Int =34

'Purple colors

Const LAVENDER:Int =36
Const THISTLE:Int =37
Const PLUM:Int =38
Const VIOLET:Int =39
Const ORCHID:Int =40
Const FUCHSIA:Int =41
Const MAGENTA:Int =42
Const MEDIUMORCHID:Int =43
Const MEDIUMPURPLE:Int =44
Const AMETHYST:Int =45
Const BLUEVIOLET:Int =46
Const DARKVIOLET:Int =47
Const DARKORCHID:Int =48
Const DARKMAGENTA:Int =49
Const PURPLE:Int =50
Const INDIGO:Int =51
Const SLATEBLUE:Int =52
Const DARKSLATEBLUE:Int =53

'Green colors

Const GREENYELLOW:Int =56
Const CHARTREUSE:Int =57
Const LAWNGREEN:Int =58
Const LIME:Int =59
Const LIMEGREEN:Int =60
Const PALEGREEN:Int =61
Const LIGHTGREEN:Int =62
Const MEDIUMSPRINGGREEN:Int =63
Const SPRINGGREEN:Int =64
Const MEDIUMSEAGREEN:Int =65
Const SEAGREEN:Int =66
Const FORESTGREEN:Int =67
Const Green:Int =68
Const DARKGREEN:Int =69
Const YELLOWGREEN:Int =70
Const OLIVEDRAB:Int =71
Const OLIVE:Int =72
Const DARKOLIVEGREEN:Int =73
Const MEDIUMAQUAMARINE:Int =74
Const DARKSEAGREEN:Int =75
Const LIGHTSEAGREEN:Int =76
Const DARKCYAN:Int =77
Const TEAL:Int =78

'Blue colors

Const AQUA:Int =80
Const CYAN:Int =81
Const LIGHTCYAN:Int =82
Const PALETURQUOISE:Int =83
Const AQUAMARINE:Int =84
Const TURQUOISE:Int =85
Const MEDIUMTURQUOISE:Int =86
Const DARKTURQUOISE:Int =87
Const CADETBLUE:Int =88
Const STEELBLUE:Int =89
Const LIGHTSTEELBLUE:Int =90
Const POWDERBLUE:Int =91
Const LIGHTBLUE:Int =92
Const SKYBLUE:Int =93
Const LIGHTSKYBLUE:Int =94
Const DEEPSKYBLUE:Int =95
Const DODGERBLUE:Int =96
Const CORNFLOWERBLUE:Int =97
Const MEDIUMSLATEBLUE:Int =98
Const ROYALBLUE:Int =99
Const Blue:Int =100
Const MEDIUMBLUE:Int =101
Const DARKBLUE:Int =102
Const NAVY:Int =103
Const MIDNIGHTBLUE:Int =104

'Brown colors

Const CORNSILK:Int =106
Const BLANCHEDALMOND:Int =107
Const BISQUE:Int =108
Const NAVAJOWHITE:Int =109
Const WHEAT:Int =110
Const BURLYWOOD:Int =111
Const _TAN:Int =112
Const ROSYBROWN:Int =113
Const SANDYBROWN:Int =114
Const GOLDENROD:Int =115
Const DARKGOLDENROD:Int =116
Const PERU:Int =117
Const CHOCOLATE:Int =118
Const SADDLEBROWN:Int =119
Const SIENNA:Int =120
Const BROWN:Int =121
Const MAROON:Int =122

'White colors

Const WHITE:Int =124
Const SNOW:Int =125
Const HONEYDEW:Int =126
Const MINTCREAM:Int =127
Const AZURE:Int =128
Const ALICEBLUE:Int =129
Const GHOSTWHITE:Int =130
Const WHITESMOKE:Int =131
Const SEASHELL:Int =132
Const BEIGE:Int =133
Const OLDLACE:Int =134
Const FLORALWHITE:Int =135
Const IVORY:Int =136
Const ANTIQUEWHITE:Int =137
Const LINEN:Int =138
Const LAVENDERBLUSH:Int =139
Const MISTYROSE:Int =140

'Grey colors

Const GAINSBORO:Int =142
Const LIGHTGREY:Int =143
Const SILVER:Int =144
Const DARKGRAY:Int =145
Const GRAY:Int =146
Const DIMGRAY:Int =147
Const LIGHTSLATEGRAY:Int =148
Const SLATEGRAY:Int =149
Const DARKSLATEGRAY:Int =150
Const BLACK:Int =151

Function Create:Tcolor(r:Int,g:Int,b:Int,A:Int = 255)
Local c:Tcolor = New Tcolor
c._Red = r
c._Green = g
c._Blue = b
c._alph = a
Return c
End Function

Method init(r:Int,g:Int,b:Int,a:Int = 1.0)
_red = r
_green = b
_blue = b
_alph = a
End Method

Method set()
SetAlpha _alph
SetColor _Red,_Green,_Blue
End Method

Method get()
_alph = GetAlpha()
GetColor _Red,_Green,_Blue
End Method

Function change(c:Int)
Select c
Case INDIANRED
SetColor 205, 92, 92
Case LIGHTCORAL
SetColor 240, 128, 128
Case SALMON
SetColor 250, 128, 114
Case DARKSALMON
SetColor 233, 150, 122
Case LIGHTSALMON
SetColor 255, 160, 122
Case CRIMSON
SetColor 220, 20, 60
Case Red
SetColor 255, 0, 0
Case FIREBRICK
SetColor 178, 34, 34
Case DARKRED
SetColor 139, 0, 0
'Pink colors
Case PINK
SetColor 255, 192, 203
Case LIGHTPINK
SetColor 255, 182, 193
Case HOTPINK
SetColor 255, 105, 180
Case DEEPPINK
SetColor 255, 20, 147
Case MEDIUMVIOLETRED
SetColor 199, 21, 133
Case PALEVIOLETRED
SetColor 219, 112, 147
'Orange colors
Case LIGHTSALMON
SetColor 255, 160, 122
Case CORAL
SetColor 255, 127, 80
Case TOMATO
SetColor 255, 99, 71
Case ORANGERED
SetColor 255, 69, 0
Case DARKORANGE
SetColor 255, 140, 0
Case ORANGE
SetColor 255, 165, 0
'Yellow colors
Case GOLD
SetColor 255, 215, 0
Case YELLOW
SetColor 255, 255, 0
Case LIGHTYELLOW
SetColor 255, 255, 224
Case LEMONCHIFFON
SetColor 255, 250, 205
Case LIGHTGOLDENRODYELLOW
SetColor 250, 250, 210
Case PAPAYAWHIP
SetColor 255, 239, 213
Case MOCCASIN
SetColor 255, 228, 181
Case PEACHPUFF
SetColor 255, 218, 185
Case PALEGOLDENROD
SetColor 238, 232, 170
Case KHAKI
SetColor 240, 230, 140
Case DARKKHAKI
SetColor 189, 183, 107
'Purple colors
Case LAVENDER
SetColor 230, 230, 250
Case THISTLE
SetColor 216, 191, 216
Case PLUM
SetColor 221, 160, 221
Case VIOLET
SetColor 238, 130, 238
Case ORCHID
SetColor 218, 112, 214
Case FUCHSIA
SetColor 255, 0, 255
Case MAGENTA
SetColor 255, 0, 255
Case MEDIUMORCHID
SetColor 186, 85, 211
Case MEDIUMPURPLE
SetColor 147, 112, 219
Case AMETHYST
SetColor 153, 102, 204
Case BLUEVIOLET
SetColor 138, 43, 226
Case DARKVIOLET
SetColor 148, 0, 211
Case DARKORCHID
SetColor 153, 50, 204
Case DARKMAGENTA
SetColor 139, 0, 139
Case PURPLE
SetColor 128, 0, 128
Case INDIGO
SetColor 75, 0, 130
Case SLATEBLUE
SetColor 106, 90, 205
Case DARKSLATEBLUE
SetColor 72, 61, 139
Case MEDIUMSLATEBLUE
SetColor 123, 104, 238
'Green colors
Case GREENYELLOW
SetColor 173, 255, 47
Case CHARTREUSE
SetColor 127, 255, 0
Case LAWNGREEN
SetColor 124, 252, 0
Case LIME
SetColor 0, 255, 0
Case LIMEGREEN
SetColor 50, 205, 50
Case PALEGREEN
SetColor 152, 251, 152
Case LIGHTGREEN
SetColor 144, 238, 144
Case MEDIUMSPRINGGREEN
SetColor 0, 250, 154
Case SPRINGGREEN
SetColor 0, 255, 127
Case MEDIUMSEAGREEN
SetColor 60, 179, 113
Case SEAGREEN
SetColor 46, 139, 87
Case FORESTGREEN
SetColor 34, 139, 34
Case Green
SetColor 0, 128, 0
Case DARKGREEN
SetColor 0, 100, 0
Case YELLOWGREEN
SetColor 154, 205, 50
Case OLIVEDRAB
SetColor 107, 142, 35
Case OLIVE
SetColor 128, 128, 0
Case DARKOLIVEGREEN
SetColor 85, 107, 47
Case MEDIUMAQUAMARINE
SetColor 102, 205, 170
Case DARKSEAGREEN
SetColor 143, 188, 143
Case LIGHTSEAGREEN
SetColor 32, 178, 170
Case DARKCYAN
SetColor 0, 139, 139
Case TEAL
SetColor 0, 128, 128
'Blue colors
Case AQUA
SetColor 0, 255, 255
Case CYAN
SetColor 0, 255, 255
Case LIGHTCYAN
SetColor 224, 255, 255
Case PALETURQUOISE
SetColor 175, 238, 238
Case AQUAMARINE
SetColor 127, 255, 212
Case TURQUOISE
SetColor 64, 224, 208
Case MEDIUMTURQUOISE
SetColor 72, 209, 204
Case DARKTURQUOISE
SetColor 0, 206, 209
Case CADETBLUE
SetColor 95, 158, 160
Case STEELBLUE
SetColor 70, 130, 180
Case LIGHTSTEELBLUE
SetColor 176, 196, 222
Case POWDERBLUE
SetColor 176, 224, 230
Case LIGHTBLUE
SetColor 173, 216, 230
Case SKYBLUE
SetColor 135, 206, 235
Case LIGHTSKYBLUE
SetColor 135, 206, 250
Case DEEPSKYBLUE
SetColor 0, 191, 255
Case DODGERBLUE
SetColor 30, 144, 255
Case CORNFLOWERBLUE
SetColor 100, 149, 237
Case MEDIUMSLATEBLUE
SetColor 123, 104, 238
Case ROYALBLUE
SetColor 65, 105, 225
Case Blue
SetColor 0, 0, 255
Case MEDIUMBLUE
SetColor 0, 0, 205
Case DARKBLUE
SetColor 0, 0, 139
Case NAVY
SetColor 0, 0, 128
Case MIDNIGHTBLUE
SetColor 25, 25, 112
'Brown colors
Case CORNSILK
SetColor 255, 248, 220
Case BLANCHEDALMOND
SetColor 255, 235, 205
Case BISQUE
SetColor 255, 228, 196
Case NAVAJOWHITE
SetColor 255, 222, 173
Case WHEAT
SetColor 245, 222, 179
Case BURLYWOOD
SetColor 222, 184, 135
Case _TAN
SetColor 210, 180, 140
Case ROSYBROWN
SetColor 188, 143, 143
Case SANDYBROWN
SetColor 244, 164, 96
Case GOLDENROD
SetColor 218, 165, 32
Case DARKGOLDENROD
SetColor 184, 134, 11
Case PERU
SetColor 205, 133, 63
Case CHOCOLATE
SetColor 210, 105, 30
Case SADDLEBROWN
SetColor 139, 69, 19
Case SIENNA
SetColor 160, 82, 45
Case BROWN
SetColor 165, 42, 42
Case MAROON
SetColor 128, 0, 0
'White colors
Case WHITE
SetColor 255, 255, 255
Case SNOW
SetColor 255, 250, 250
Case HONEYDEW
SetColor 240, 255, 240
Case MINTCREAM
SetColor 245, 255, 250
Case AZURE
SetColor 240, 255, 255
Case ALICEBLUE
SetColor 240, 248, 255
Case GHOSTWHITE
SetColor 248, 248, 255
Case WHITESMOKE
SetColor 245, 245, 245
Case SEASHELL
SetColor 255, 245, 238
Case BEIGE
SetColor 245, 245, 220
Case OLDLACE
SetColor 253, 245, 230
Case FLORALWHITE
SetColor 255, 250, 240
Case IVORY
SetColor 255, 255, 240
Case ANTIQUEWHITE
SetColor 250, 235, 215
Case LINEN
SetColor 250, 240, 230
Case LAVENDERBLUSH
SetColor 255, 240, 245
Case MISTYROSE
SetColor 255, 228, 225
'Grey colors
Case GAINSBORO
SetColor 220, 220, 220
Case LIGHTGREY
SetColor 211, 211, 211
Case SILVER
SetColor 192, 192, 192
Case DARKGRAY
SetColor 169, 169, 169
Case GRAY
SetColor 128, 128, 128
Case DIMGRAY
SetColor 105, 105, 105
Case LIGHTSLATEGRAY
SetColor 119, 136, 153
Case SLATEGRAY
SetColor 112, 128, 144
Case DARKSLATEGRAY
SetColor 47, 79, 79
Case BLACK
SetColor 0, 0, 0
End Select
End Function
End Type



Streaksy(Posted 1+ years ago)

 Bobysait: Yeah I could have done that but have you seen what happens when you left + right click on a colour? ;DJesse: Thats cool but I put all the colour codes in an array because I might want to call upon the colours in a way other than simply changing setting the current drawing colour.  But yeh it's handy isn't it ;D


Bobysait(Posted 1+ years ago)

 I had not tested the Right click :) very usefull ^^so let'go for a 2-frame image  ^^If Colour_Demo Then
ofx=18
ofy=15
sp=10
w=133
h=20
Graphics 1024,768,0,2
SetBuffer BackBuffer()
SetFont LoadFont("tahoma",18) ; lucida console 21

; draw colours to an image
Local ColoursImg = CreateImage(1024,768,2)
CLSColour "black"
For frame = 0 To 1
SetBuffer ImageBuffer(ColoursImg,frame)
x=ofx
y=ofy
For c=1 To Colours
Colour c
If frame=0 Then Rect x,y,w,h,1:Colour c,150:Text x+(w/2)-1,y+1+(h/2),ColourName(c),1,1:Colour c,160
Rect x,y,w,h,0
Rect x+1,y+1,w-2,h-2,0
If frame=0 Then Colour c,390
Text x+(w/2),y+(h/2)-1,ColourName(c),1,1
y=y+h+sp:If y+h>GraphicsHeight() Then y=ofy:x=x+w+sp
Next
Next
SetBuffer BackBuffer()

frame=0
CLSColour "khaki"
Repeat
Cls
mmsx=MouseX()
mmsy=MouseY()
mmd2=MouseDown(2)
x=ofx
y=ofy
DrawImage ColoursImg,0,0,mmd2
For c=1 To Colours
If RectsOverlap(x,y,w,h,mmsx,mmsy,1,1)
Colour c,390:Rect x,y,w,h,0 : If MouseDown(1) Then CLSColour ColourName(c)
Exit ; exit if mouseover
EndIf
y=y+h+sp:If y+h>GraphicsHeight() Then y=ofy:x=x+w+sp
Next
Flip
Until KeyHit(1)
FreeImage ColoursImg
End
EndIf
@Jesse : Maybe a [ codebox ] [ /codebox ] is more discret ...


Jesse(Posted 1+ years ago)

 Treaksy, I wasn't trying to show it of as being a better example but that maybe it would help with color declarations for others and maybe even combine both to make it more complete. yours do have several advantages.@bobysait, I know what you mean. I was just trying to, irresponsibly, show it off.fixed now


Streaksy(Posted 1+ years ago)

 Not showing off either :P  Just explain why it is how it is


Bobysait(Posted 1+ years ago)

 just a small joke for Streaksy :on your keyboard,  you'll fine a smart key with 2 arrows ( one going left, one going right )you could use it to indent a bit your code :P


Streaksy(Posted 1+ years ago)

 funny thing is i actually have my own style of indentation.  when i see indented code it seems all spread out to me.. i like sections of code all clustered together.  just suits the way i think of it.  when i see something good in the code archives and use it i actually, in most cases, remove all the indentation.  just a foible :P


Subirenihil(Posted 1+ years ago)

 @MaliceUsing hexidecimal notation for your color constants would be much easier to read and edit (as long as you understand hex).;For example, when dealing with colors:
Const COL_ICE = $00FFFF80
;is easier to interpret than
Const COL_ICE = 16777088
;Just remember that it goes Alpha (when used for textures), Blue, Green, Red.  2 Hex digits per component.