AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Langton Ameise

Ein Thema von cRayZo · begonnen am 7. Okt 2008 · letzter Beitrag vom 7. Okt 2008
Antwort Antwort
cRayZo

Registriert seit: 30. Jul 2007
156 Beiträge
 
Delphi 6 Personal
 
#1

Langton Ameise

  Alt 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;
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#2

Re: Langton Ameise

  Alt 7. Okt 2008, 20:07
War jetzt zu faul, deinen Code durchzugucken. Was willst du denn wann wie färben? Also nach welchen Kriterien?

Ich habs eben mal mit Schwarz-Weiß programmiert und es geht. Also falls du nicht weiterkommst, kann ich dir mal meinen QT zeigen wenn du willst. Aber ist halt wie gesagt nur mit Schwarz-Weiß (und auch ohne weiteres nicht auf mehrere Farben umstellbar).
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
cRayZo

Registriert seit: 30. Jul 2007
156 Beiträge
 
Delphi 6 Personal
 
#3

Re: Langton Ameise

  Alt 7. Okt 2008, 22:22
ja das wäre cool, ih habe es auch einmal mit schwarz weiß probiert, aber auch dort klappt es nicht...
Ich glaube bei mir ist ein Denkfehler drin..
kannst du mir vll deine Lösung mal schicken?
lg
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#4

Re: Langton Ameise

  Alt 7. Okt 2008, 23:00
Hi,

Habs mal angehängt mit Source.

Edit: Neue Version.

Gruß
Neutral General
Angehängte Dateien
Dateityp: rar langton_ameisen_109.rar (532,5 KB, 22x aufgerufen)
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#5

Re: Langton Ameise

  Alt 7. Okt 2008, 23:21
Schön in Klassen verpakt. aber warum erzeugst du das Offscreen Bitmap im Paint Ereignis jedes mal neu:
Delphi-Quellcode:
procedure TForm1.PaintBox1Paint(Sender: TObject);
var bit: TBitmap;
      p: PRGBQuad;
    i,j: Integer;
begin
  if (Field.Width = 0) or (Field.Height = 0) then
  begin
    PaintBox1.Canvas.Rectangle(Rect(0,0,PaintBox1.Width,PaintBox1.Height));
    exit;
  end;
  
  bit := TBitmap.Create;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#6

Re: Langton Ameise

  Alt 7. Okt 2008, 23:24
Zitat von Luckie:
Schön in Klassen verpakt. aber warum erzeugst du das Offscreen Bitmap im Paint Ereignis jedes mal neu:
Mh ja stimmt eigentlich... Das Anfordern des Speicherplatz beim Setzen von Width,Height des Bitmaps bei jedem Zeichnen ist eigentlich unnötig..

Ich werds verbessern. Moment.

Edit: Neue Version zwei Posts weiter oben. Offscreen Bitmap ist jetzt eine Klassenvariable.
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz