home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip: Shareware for Win 95
/
Chip-Shareware-Win95.bin
/
ostatni
/
delphi
/
delphi1
/
anipal.exe
/
PALS.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1995-09-05
|
5KB
|
189 lines
{
Project: Palette
Company: Word in Action
Copyright (C) 1995 by Jay Giganti. All Rights Reserved.
File : Pals.Pas
Author : Jay Giganti
Overview: To Modify the color palette and display a road to nowhere
}
unit Pals;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Panel1: TPanel;
Image1: TImage;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function GetPalette: HPALETTE; override;
procedure CreatePal;
procedure PaintImg;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const
Entries = 256;
Clrs = Trunc(Entries / 4);
var
CurPal : Array[0..Entries-1] of TPALETTEENTRY;
hPal : HPalette;
hOldPal : HPalette;
{==============================================================================
CreatePal
==============================================================================}
procedure TForm1.CreatePal;
var
nCntr : Integer;
pPal : PLOGPALETTE;
lSize : LongInt;
begin
lSize := sizeof(TLogPalette) + Entries * sizeof(TPaletteEntry);
pPal := MemAlloc(lSize);
pPal^.palVersion := $300;
pPal^.palNumEntries := Entries;
{$R-}
for nCntr := 0 to Clrs do
begin
{ Set up the shades of Gray }
pPal^.palPalEntry[nCntr].peRed := nCntr + 128;
pPal^.palPalEntry[nCntr].peGreen := nCntr + 128;
pPal^.palPalEntry[nCntr].peBlue := nCntr + 128;
pPal^.palPalEntry[nCntr].peFlags := PC_RESERVED;
{ Set up the shades of Red }
pPal^.palPalEntry[nCntr + Clrs].peRed := nCntr + 128;
pPal^.palPalEntry[nCntr + Clrs].peGreen := 0;
pPal^.palPalEntry[nCntr + Clrs].peBlue := 0;
pPal^.palPalEntry[nCntr + Clrs].peFlags := PC_RESERVED;
{ Set up the shades of Green }
pPal^.palPalEntry[nCntr + Clrs*2].peRed := 0;
pPal^.palPalEntry[nCntr + Clrs*2].peGreen := nCntr + 128;
pPal^.palPalEntry[nCntr + Clrs*2].peBlue := 0;
pPal^.palPalEntry[nCntr + Clrs*2].peFlags := PC_RESERVED;
{ Set up the shades of Blue }
pPal^.palPalEntry[nCntr + Clrs*3].peRed := 0;
pPal^.palPalEntry[nCntr + Clrs*3].peGreen := 0;
pPal^.palPalEntry[nCntr + Clrs*3].peBlue := nCntr + 128;
pPal^.palPalEntry[nCntr + Clrs*3].peFlags := PC_RESERVED;
end;
for nCntr := 0 to Entries - 1 do
CurPal[nCntr] := pPal^.palPalEntry[nCntr];
{$R+}
hPal := CreatePalette(pPal^);
FreeMem(pPal, lSize);
end;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Width := 640;
Height := 480;
CreatePal;
PaintImg;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SelectPalette(Image1.Canvas.Handle, hOldPal, FALSE);
RealizePalette(Image1.Canvas.Handle);
DeleteObject(hPal);
end;
function TForm1.GetPalette: HPALETTE;
begin
Result := hPal;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
Pal : TPALETTEENTRY;
nCntr : Integer;
begin
Pal := CurPal[0];
for nCntr := 0 to Entries - 2 do
CurPal[nCntr] := CurPal[nCntr + 1];
CurPal[nCntr+1] := Pal;
AnimatePalette(hPal, 0, Entries, CurPal);
end;
procedure TForm1.PaintImg;
var
Clr : LongInt;
y,
x1,
clrS,
clrE,
x2 : Integer;
wReal : WORD;
begin
clrS := 21;
clrE := 22;
x1 := ClientWidth DIV 2;
x2 := x1;
Clr := clrS;
hOldPal := SelectPalette(Image1.Canvas.Handle, hPal, FALSE);
wReal := RealizePalette(Image1.Canvas.Handle);
Panel1.Caption:= Format('Realized %u Entries out of %u',
[wReal, Entries]);
Image1.Canvas.Brush.Color := PaletteIndex(1);
Image1.Canvas.FillRect(Rect(0, 0, Image1.Width, Image1.Height));
for y := 120 to ClientHeight - 120 do
begin
Image1.Canvas.Pen.Color := PaletteIndex(Clr);
Image1.Canvas.MoveTo(x1, y);
Image1.Canvas.LineTo(x2, y);
Dec(x1);
if x1 < 0 then
x1 := 0;
Inc(x2);
if (x2 > ClientWidth) then
x2 := ClientWidth;
Inc(Clr);
if (clr > Entries - clrE) then
Clr := ClrS;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := not Timer1.Enabled;
end;
end.