Author Topic: Random Colors  (Read 1881 times)

0 Members and 1 Guest are viewing this topic.

Offline Iq Unlimited

  • Flagrunner
  • ****
  • Posts: 864
  • mr. foobar2000
Random Colors
« on: July 22, 2008, 07:33:30 pm »
Script Name: Random Color Script
Script Description: A function that generates a random hexidecimal. To impliment it into your script, just put the function at the top of the script and at any WriteConsole() that you want random Colors just put RandomColor in the location where the color is.
Original Author(s): Iq-Unlimited
Core Version: 2.6.3
Code: (Just some snippets, not the whole script)
Code: [Select]
function RandomColor: longint;
var
Ran, i: byte;
Cchr: array [1..6] of char;
CharColor: string;
begin
for i := 1 to 6 do begin
Ran := Random(1, 15);
case Ran of
1: begin
Cchr[i] := '1';
end;
2: begin
Cchr[i] := '2';
end;
3: begin
Cchr[i] := '3';
end;
4: begin
Cchr[i] := '4';
end;
5: begin
Cchr[i] := '5';
end;
6: begin
Cchr[i] := '6';
end;
7: begin
Cchr[i] := '7';
end;
8: begin
Cchr[i] := '8';
end;
9: begin
Cchr[i] := '9';
end;
10: begin
Cchr[i] := 'A';
end;
11: begin
Cchr[i] := 'B';
end;
12: begin
Cchr[i] := 'C';
end;
13: begin
Cchr[i] := 'D';
end;
14: begin
Cchr[i] := 'E';
end;
15: begin
Cchr[i] := 'F';
end;
end;
end;
CharColor := Cchr[1]+Cchr[2]+Cchr[3]+Cchr[4]+Cchr[5]+Cchr[6];
Result := strtoint('$'+CharColor);
end;
« Last Edit: July 22, 2008, 09:27:24 pm by Iq Unlimited »

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
Re: Random Colors
« Reply #1 on: July 22, 2008, 08:23:30 pm »
man... there's a very eazy way to do it... I think my soluttion is quite simple, but it works.
Code: [Select]
function CRandom():longint;
begin
    result:=rgb(random(0,256),random(0,256),random(0,256));
end;
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade

Offline Iq Unlimited

  • Flagrunner
  • ****
  • Posts: 864
  • mr. foobar2000
Re: Random Colors
« Reply #2 on: July 22, 2008, 08:48:26 pm »
And then convert it to a hexidecimal, that's the whole point of this, to make a random hexidecimal.

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Random Colors
« Reply #3 on: July 23, 2008, 02:03:23 am »
And then convert it to a hexidecimal, that's the whole point of this, to make a random hexidecimal.
Mind explaining why would one rather complicate things and generate a random hex color instead of simply using As de Espada's method, if the ultimate purpose of it was to get an opaque color?

And here's a slightly more elegant version of RandomColor, out of boredom.

Offline Iq Unlimited

  • Flagrunner
  • ****
  • Posts: 864
  • mr. foobar2000
Re: Random Colors
« Reply #4 on: July 23, 2008, 03:15:45 am »
Mind explaining why would one rather complicate things and generate a random hex color instead of simply using As de Espada's method, if the ultimate purpose of it was to get an opaque color?

for WriteConsole's Hex color, I would use As de Espada's for DrawText or something that uses RGB.
« Last Edit: July 23, 2008, 03:20:40 am by Iq Unlimited »

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Random Colors
« Reply #5 on: July 23, 2008, 01:38:10 pm »
Mind explaining why would one rather complicate things and generate a random hex color instead of simply using As de Espada's method, if the ultimate purpose of it was to get an opaque color?

for WriteConsole's Hex color, I would use As de Espada's for DrawText or something that uses RGB.
they both use integers ::)

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
Re: Random Colors
« Reply #6 on: July 23, 2008, 05:13:52 pm »
I found that my function can be used in WriteConsole and in DrawText. Maybe it's already in hexadecimal...
where else could you use a random collor?
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade