Simba Code:
type
TGrid = record
bounds: TBox;
pixels: Integer;
end;
procedure createGrid;
var
TPA: TPointArray;
b: TBox;
boxes: array of TGrid;
area, bmp, h, i, numOfBoxes, w, x, y: Integer;
str: String;
begin
FindColors(TPA, 1034847, 709, 133, 756, 181);
b := GetTPABounds(TPA);
with b do
begin
//b := IntToBox(x1 - 2, y1 - 2, x2 + 2, y2 + 2);
w := x2 - x1;
h := y2 - y1;
WriteLn('Width = '+IntToStr(w));
WriteLn('Height = '+IntToStr(h));
area := w * h;
WriteLn('Area = '+IntToStr(area));
bmp := BitmapFromString(w, h, '');
CopyClientToBitmap(bmp, x1, y1, x2, y2);
for x := 0 to w do
for y := 0 to h do
FastSetPixel(bmp, x, y, clBlack);
for i := 0 to High(TPA) do
FastSetPixel(bmp, TPA[i].x - x1, TPA[i].y - y1, clWhite);
numOfBoxes := 4;
SetLength(boxes, (numOfBoxes * numOfBoxes));
for i := 0 to (numOfBoxes * numOfBoxes) - 1 do
boxes[i].bounds := IntToBox(Round(x1 + ((i mod numOfBoxes) * ((x2 - x1) / numOfBoxes))),
Round(y1 + ((i div numOfBoxes) * ((y2 - y1) / numOfBoxes))),
Round(x1 + ((x2 - x1) / numOfBoxes) + ((i mod numOfBoxes) * ((x2 - x1) / numOfBoxes))),
Round(y1 + ((y2 - y1) / numOfBoxes) + ((i div numOfBoxes) * ((y2 - y1) / numOfBoxes))));
end;
SetTargetBitmap(bmp);
SaveBitmap(bmp, ScriptPath+'b.bmp');
getbitmapsize(bmp, w, h);
writeln(inttostr(Fastgetpixel(bmp, 0,11)));
terminatescript;
for i := 0 to High(boxes) do
begin
with boxes[i].bounds do
begin
writeln(inttostr(x1)+', '+Inttostr(y1)+', '+inttostr(x2)+', '+Inttostr(y2));
writeln(inttostr(i * 5)+', '+inttostr(( i div numOfBoxes ) * 7)+', '+inttostr((i * 5) + 5)+', '+inttostr((( i div numOfBoxes ) * 7) + 7));
boxes[i].pixels := CountColor(clWhite, i * 5, ( i div numOfBoxes ) * 7, (i * 5) + 5, (( i div numOfBoxes ) * 7) + 7);
end;
str := str + IntToStr(boxes[i].pixels)+', ';
end;
WriteLn(str);
end;