Einzelnen Beitrag anzeigen

Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#3

Re: rechteckige Spirale durchlaufen

  Alt 17. Dez 2005, 12:00
DANKE! das ist großartig!
ok.... hab das ganze ein wenig umgeschrieben, und es funktioniert.

Delphi-Quellcode:
type PArray = array of TPoint;

function spirale(abstand,count,startstep:integer;startpunkt:tpoint;drehsinnnachrechts:boolean):PArray;
var
  richtung,i,step:integer;
  actpos:tpoint;
begin
  setlength(result,count);
  richtung:=1;
  actpos:=startpunkt;
  result[1]:=actpos;
  step:=startstep;
  for i:=1 to count-1 do begin
    case richtung of
      1: actpos.x:=actpos.x+step;
      2: actpos.y:=actpos.y+step;
      3: actpos.x:=actpos.x-step;
      4: actpos.y:=actpos.y-step;
    end;
    step:=step+abstand;
    if drehsinnnachrechts then
    begin
      richtung:=richtung+1;
      if richtung=5 then richtung:=1;
    end else begin
      richtung:=richtung-1;
      if richtung=0 then richtung:=4;
    end;
    result[i]:=actpos;
  end;
end;
end;
Aber müsste das nicht überlaufen, siehe Kommentare?

EDIT: habe den code jetzt nochmal angepasst.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat