1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| uses types, math, unit4colors;
{ TForm1 }
//// http://www.festra.com/wwwboard/messages/12892.html ////
var
FG: array of array of TColor;
BG: array of array of TColor;
FG2: array of array of TColor;
RDM: array of array of TColor;
procedure TForm1.FormCreate(Sender: TObject);
var
Col, Row: integer;
begin
// Set the sizes of the arrays
SetLength(FG, Grid.ColCount, Grid.RowCount);
SetLength(BG, Grid.ColCount, Grid.RowCount);
// Initialize with default colors
for Col := 0 to Grid.ColCount - 1 do begin
for Row := 0 to Grid.RowCount - 1 do begin
FG[Col, Row] := clBlack;
BG[Col, Row] := clWhite;
end;
end;
// original dessus
// mes ajouts dessous
coeff := trkbCoeff.Position;
grid2.RowCount:=16;
// Set the sizes of the arrays
SetLength(FG2, Grid2.ColCount, Grid2.RowCount);
SetLength(RDM, Grid2.ColCount, Grid2.RowCount);
// Initialize with default colors
for Col := 0 to Grid2.ColCount - 1 do
for Row := 0 to Grid2.RowCount - 1 do
case Col of
0:FG2[Col, Row] := jpRGBtoColor(255, Row*16, 0); // rouge -> jaune
1:FG2[Col, Row] := jpRGBtoColor(255-Row*16, 255, 0); // jaune -> vert
2:FG2[Col, Row] := jpRGBtoColor(0, 255, Row*16); // vert -> cyan
3:FG2[Col, Row] := jpRGBtoColor(0, 255-Row*16, 255); // cyan -> bleu
4:FG2[Col, Row] := jpRGBtoColor(Row*16, 0, 255); // bleu -> magenta
5:FG2[Col, Row] := jpRGBtoColor(255, 0, 255-Row*16); // magenta -> rouge
6:FG2[Col, Row] := jpRGBtoColor(Row*16, Row*16, Row*16);// N->Blanc
end;
PrepareRandom;
end;
procedure TForm1.gridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
S: string;
begin
S := Grid.Cells[ACol, ARow];
// Fill rectangle with colour
Grid.Canvas.Brush.Color := BG[ACol, ARow];
Grid.Canvas.FillRect(aRect);
// Next, draw the text in the rectangle
Grid.Canvas.Font.Color := FG[ACol, ARow];
Grid.Canvas.TextOut(aRect.Left + 2, aRect.Top + 2, S);
end;
procedure TForm1.gridClick(Sender: TObject);
var
Col, Row: integer;
Color1, Color2, Color3: byte;
begin
Col := Grid.Col;
Row := Grid.Row;
// Calculate contrasting random colours
Color1 := 200 + Random(56);
Color2 := 200 + Random(56);
Color3 := 100 + Random(156);
BG[Col, Row] := RGBtoColor(Color1, Color2, Color3);
FG[Col, Row] := RGBtoColor(255 - Color3, 255 - Color1, 255 - Color2);
// Set the text to be displayed
Grid.Cells[Col, Row] := 'clicked';
end;
//// http://www.festra.com/wwwboard/messages/12892.html ////
////////////////////////////////////////////////////////////////////////////////
procedure TForm1.PrepareRandom;
var
Col, Row: integer;
begin
Randomize;
SetLength(RDM, Grid2.ColCount, Grid2.RowCount);
// Initialize with default colors
for Col := 0 to Grid2.ColCount - 1 do
for Row := 0 to Grid2.RowCount - 1 do
RDM[Col, Row] := random(16777216);
end;
procedure TForm1.grid2PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
begin
with grid2 do with Canvas do
case rdgMode.ItemIndex of
0: begin Brush.Color := FG2[aCol, aRow]; FillRect(CellRect(aCol, aRow)); end;
1: begin Brush.Color := RDM[aCol, aRow]; FillRect(CellRect(aCol, aRow)); end;
end;
end;
procedure TForm1.rdgModeClick(Sender: TObject);
begin
grid2.Repaint;
end;
procedure TForm1.trkbCoeffChange(Sender: TObject);
begin
coeff := trkbCoeff.Position; grid2.Repaint;
end;
procedure TForm1.btnNewRndClick(Sender: TObject);
begin
SetLength(RDM, 0, 0); PrepareRandom; grid2.Repaint;
end;
function CalculeLwithWiwaxia(R,G,B: byte):integer;
var
tmp: float;
begin
tmp := trunc( ( 0.297 * power((R + 14),2.4))
+ ( power((G + 14),2.4))
+ ( 0.101 * power((B + 14),2.4)) );
Result := round(tmp / 10000);
end;
procedure TForm1.grid2DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
function ContrastedColor(InColor: TColor): TColor;
var
H,S,L, Ltmp: float;
R,G,B: byte;
begin
jpColorToHSL(InColor, H,S,L);
jpColorToRGB(InColor, R,G,B);
Ltmp:=CalculeLwithWiwaxia(R,G,B);
if (Ltmp <= coeff) then L := 1 else L := 0;
Result := myHSLtoColor(H,S,L);
end;
begin
with grid2.Canvas do begin
Font.Color := ContrastedColor(Brush.Color);
TextOut(grid2.CellRect(aCol, aRow).Left+10, grid2.CellRect(aCol, aRow).Top+4, 'test');
end;
end; |
Partager