Rectangle function produces blurry circles
조회 수: 13 (최근 30일)
이전 댓글 표시
Hi all, I'm making a circle filling program, and for some reason, about half of the circles produced don't have crisp borders like I want. For some reason, they're almost kind of blurry or fuzzy. How can I get rid of this behavior?

clear
clc
WIDTH = 800;
HEIGHT = 400;
testMatrix = [1, 1, 0, 0; 0, 0, 1, 1; 1, -1, 1, -1; 0, 0, 0, 0];
window = figure('Toolbar', 'none', 'Menubar', 'none',...
'Position',[300,300,WIDTH,HEIGHT], 'Resize', 'off',...
'Name', 'Circle Filling');
hold on
ax = axes('Position', [0,0,1,1], 'box', 'off');
% each circle = [x, y, r, growth, r, g, b]
circles = [round(WIDTH*rand()), round(HEIGHT*rand()), 1, 1, rand(),rand(),rand()];
growingCircles = circles(:,4) ~= 0; % mask of all circles that are currently growing
for frame = 1:250
circlesToDraw = circles(growingCircles, :); % Draw growing circles
for index = 1:size(circlesToDraw)
circle = circlesToDraw(index,:);
rectangle(ax,'Position',[circle(1:2)-circle(3), 2*circle(3), 2*circle(3)],...
'Curvature',1,'EdgeColor', circle(4:7),'FaceColor', circle(4:7))
end
ax.Color = [0,0,0];
axis([0,WIDTH,0,HEIGHT]);
indexCircles = 1:size(circles);
for circle = indexCircles(growingCircles) % test if growing circles need to stop growing
bounds = circles(circle,1:4)*testMatrix;
if sum(bounds < 0 | [WIDTH < bounds(1:2), HEIGHT < bounds(3:4)]) ~= 0
circles(circle,4) = 0;
continue
end
for testAgainst = 1:size(circles)
if circle ~= testAgainst
rSum = sum(circles([circle, testAgainst],3));
distance = sqrt(sum((circles(circle,1:2)-circles(testAgainst,1:2)).^2));
if distance < rSum +1
circles([circle, testAgainst],4) = 0;
end
end
end
end
growingCircles = circles(:,4) ~= 0; % Update growingCircles
circles(growingCircles,3) = circles(growingCircles,3) + circles(growingCircles,4); % Update Circles
% Attempt to create new circle
for index = 1:1
newPos = [round(WIDTH*rand()), round(HEIGHT*rand())];
dist = sqrt(sum(((circles(:,1:2)-newPos).^2), 2)); % Get a column vector of newPos distance to each circle
if sum(dist < circles(:,3)) == 0
circles(end+1,:) = [newPos, 1, 1, floor(10*[rand(),1-rand(),rand()])/10];
growingCircles = [growingCircles; true];
end
end
clc
fprintf('Frame: %d', frame);
pause(.001)
end
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!