Registriert seit: 30. Jul 2007
156 Beiträge
Delphi 6 Personal
|
Langton Ameise
7. Okt 2008, 17:27
Hallo, ich bin dabei eine lagton Ameise zu programmieren..
(für alle, die nicht wissen, was das ist hier )
jedoch möchte ich nicht nur langweilig schwarz weiß benutzen sondern differenziertere Farben..
ich habe hier einen Code geschrieben, aber er funktioniert nicht. Das Programm mal nur 2 Pixel an, eigenltich sollte das anders aussehen...
Der Großteil des Codes ist Wiederholung, also bitte schreckt daran nicht zurück. ich wäre euch über Hilfe sehr verbunden!!
Grüße cRayZo
Delphi-Quellcode:
procedure Td.StartenClick(Sender: TObject);
var
pos: integer; //gibt an, in welche Richtung der nächste Pixel geht,
{bzw woher er dann gekommen ist
0= von oben /nach unten
1= von unten /nach oben
2= von links /nach rechts
3= von rechts /nach links }
posnewx, posnewy, posaktx, posakty: integer;
durchlauf, i: integer;
begin
durchlauf:=strtoint(Edit2.Text);
posaktx:=strtoint(xedit.Text);
posakty:=strtoint(yedit.Text);
if topbutton.Enabled=False then pos:=1; //bestimmt anfangsrichtung
if downbutton.Enabled=False then pos:=0;
if leftbutton.Enabled=False then pos:=3;
if rightbutton.Enabled=False then pos:=2;
for i:=0 to durchlauf do
begin
sleep(200);
//////
if pos=0 then //bewegt den "Malpixel" um 1 in die bestimmte richtung
begin
posnewx:=posaktx; posnewy:=posaktx+1;
end;
if pos=1 then
begin
posnewx:=posaktx; posnewy:=posaktx-1;
end;
if pos=2 then
begin
posnewx:=posaktx+1; posnewy:=posaktx;
end;
if pos=3 then
begin
posnewx:=posaktx-1; posnewy:=posaktx;
end;
if image1.Canvas.Pixels[posnewx,posnewy]=clWhite then //fragt ab, welche Farbe der neue Pixel besitzt
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= clblue; //färbt abhängig von der Richtung, aus dem er gekommen ist,
pos:=2; end; //den Pixel ein, und bestimmt neue "wanderrichtung"
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= clred;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= clyellow;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= clgreen;
pos:=0; end;
end
else
if image1.Canvas.Pixels[posnewx,posnewy]=clBlue then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C65D40;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C68450;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6AB60;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6D270;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00C65D40 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6D270;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C65D40;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C68450;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6AB60;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00C68450 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6AB60;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6D270;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C65D40;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C68450;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00C6AB60 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C68450;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6AB60;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6D270;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C65D40;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00C6D270 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C65D40;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C68450;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6AB60;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00C6D270;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=clRed then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001388;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001770;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001B58;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001F40;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00001388 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001F40;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001388;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001770;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001B58;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00001770 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001B58;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001F40;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001388;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001770;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00001B58 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001770;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001B58;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001F40;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001388;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00001F40 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001388;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001770;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001B58;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00001F40;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=clYellow then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000D4E4;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00008DCC;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000FFDC;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000A9EC;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$0000D4E4 then
begin
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000A9EC;
pos:=2; end;
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000D4E4;
pos:=3; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00008DCC;
pos:=1; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000FFDC;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$0000FFDC then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000FFDC;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000A9EC;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000D4E4;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00008DCC;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$0000D4E4 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00008DCC;
pos:=2; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000FFDC;
pos:=3; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000A9EC;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000D4E4;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$0000A9EC then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000D4E4;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00008DCC;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000FFDC;
pos:=1; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0000A9EC;
pos:=0; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=clGreen then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00025D78;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00028488;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002AB98;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002D2A8;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00025D78 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00025D78;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00028488;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002AB98;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002D2A8;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$00028488 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002D2A8;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00025D78;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00028488;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002AB98;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$0002AB98 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002AB98;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002D2A8;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00025D78;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00028488;
pos:=1; end;
end else
if image1.Canvas.Pixels[posnewx,posnewy]=$0002D2A8 then
begin
if pos=0 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00028488;
pos:=3; end;
if pos=1 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002D2A8;
pos:=2; end;
if pos=2 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $0002AB98;
pos:=0; end;
if pos=3 then begin
Image1.canvas.pixels[posnewx, posnewy]:= $00025D78;
pos:=1; end;
end;
posaktx:=posnewx; //setzt die Pixelkoordinaten auf den aktuellen Pixel
posakty:=posnewy;
sleep(100);
image1.Refresh;
//////
end;
end;
|