Witam
Mam problem, muszę wyznaczyć pozycje XY dla kolumny z liczby, liczby dodają się od 0 do 165 a wielkość grida do 15x11
Napisałem nie do końca taka procedurę, na pewno by działała, ale jest za długa i brzydka.
US nr kratki
if (US >= 16) and (US <= 30) then begin
result.X := (US) - 15;
result.Y := 2;
end;
if (US >= 31) and (US <= 45) then begin
result.X := (US) - 30;
result.Y := 3;
end;
if (US >= 46) and (US <= 60) then begin
result.X := (US) - 45;
result.Y := 4;
end;
itd.
Też próbowałem (dla grida 5x5 ) z :
if US <= 5 then begin
result.X := US;
result.Y := 1;
end;
if US >= 6 then begin
result.X := US mod 5;
result.Y := US div 4;
end;
if (US = 10) or (US = 15) or (US = 20) or (US = 25) then
result.X := 5 ;
if (US = 6) or (US = 11) Then
result.Y := result.Y + 1;
if (US = 20) or (US = 25) Then
result.Y := result.Y - 1;
end;
Ale też nie jest za dobrze
Jest jakiś algorytm żeby szybko i dobrze to obliczyć?
Dzięki.