#local North = 0; #local South = Ymax; #local East = Xmax; #local West = 0; #local V = NMax-n; #local Perimeter = abs(South-North)*2+abs(East-West)*2; #while(V >= Perimeter) #local V = V-Perimeter; #local South = South-1; #local East = East-1; #local North = North+1; #local West = West+1; #local Perimeter = abs(South-North)*2+abs(East-West)*2; #end #debug concat( "N:", str(North,0,0), " E:",str(East,0,0), " S:", str(South,0,0), " W:",str(West,0,0)," P:",str(Perimeter,0,0)," V:",str(V,0,0),"\n") #if((East > West)&(South > North)) #if(V <= (East-West)) #declare j = North; #declare i = V+West; #else #local V = V -(East-West+1); #if( V <= (South-North-1)) #declare i = East; #declare j = North+1+V; #else #local V = V - (South-North); #if(V <= (East-West-1)) #declare j = South; #declare i = East-V-1; #else #local V = V - (East-West); #declare j = South-V-1; #declare i = West; #end #end #end #else #if(East > West) #declare j = min(North,South+1); #declare i = min(West,East+1)+V; #else #declare i = min(West,East+1); #declare j = min(North,South+1)+V; #end #end #break