close all;
clc;
fontSize = 15;
numberOfsquares = 150000;
squareInsideValue = 0;
circleOutsideValue = 1;
circleInsideValue = 1;
squareWidth = 12;
imageWidth = 500;
imageHeight = 500;
circleRadius = 250;
ourImage = circleOutsideValue * ones(imageHeight, imageWidth);
[x, y] = meshgrid(1:imageWidth, 1:imageHeight);
ourImage((x - imageWidth/2).^2 + (y - imageHeight/2).^2 <= circleRadius.^2) = circleInsideValue;
for k = 1 : numberOfsquares
y1 = randi(imageHeight, 1);
x1 = randi(imageWidth, 1);
y2 = y1 + squareWidth - 1;
x2 = x1 + squareWidth - 1;
if sqrt((x1 - imageWidth/2)^2 + (y1 - imageHeight/2)^2) > circleRadius
continue;
end
if sqrt((x1 - imageWidth/2)^2 + (y2 - imageHeight/2)^2) > circleRadius
continue;
end
if sqrt((x2 - imageWidth/2)^2 + (y1 - imageHeight/2)^2) > circleRadius
continue;
end
if sqrt((x2 - imageWidth/2)^2 + (y2 - imageHeight/2)^2) > circleRadius
continue;
end
if ourImage(y1, x1) == squareInsideValue
continue;
end
if ourImage(y1, x2) == squareInsideValue
continue;
end
if ourImage(y2, x1) == squareInsideValue
continue;
end
if ourImage(y2, x2) == squareInsideValue
continue;
end
ourImage(y1:y2, x1:x2) = squareInsideValue;
end
figure(2), clf(2);
imshow(ourImage);
xlim([170 195])
ylim([330 342.5])