How to add more squares on the checkerboard inscribed inside of a circle

1 Ansicht (letzte 30 Tage)
width=input('Enter a positive number: ');
disp(' ');
while width<0
width=input('Enter a positive number: ');
disp(' ');
end
dimension=input('Input an integer greater than 1: ');
disp(' ');
while (dimension<=1)
dimension=input('Input an integer greater than 1: ');
end
reorint=0;
while reorint==0
if isreal(dimension)&&rem(dimension,1)==0
reorint=1;
else
dimension=input('Input an integer greater than 1: ');
reorint=0;
end
end
fprintf(1,'\n');
color1=input('Enter 1st color:red(r), yellow(y), green(g), black(k), blue(b), magenta(m), white(w), cyan(c): ','s');
color2=input('Enter different 2nd color:red(r), yellow(y), green(g), black(k), blue(b), magenta(m), white(w), cyan(c): ','s');
N=4; %SQUARE
R=width; %SQUARE SIZE
Phase=pi/4;
theta=zeros(1,N);
for k=1:N+1
theta(k)=2*pi*(k-1)/N;
end
x1=R*cos(theta+Phase)/sqrt(2);
y1=R*sin(theta+Phase)/sqrt(2);
plot(x1,y1);
fill(x1,y1,color1);
hold;
x2=R*cos(theta+Phase)/sqrt(2)+R;
y2=R*sin(theta+Phase)/sqrt(2);
plot(x2,y2);
fill(x2,y2,color2);
This is my code so far. I was wondering how I could make the checkerboard with more squares instead of just two. The input 'dimension' is how many squares both sides of the checker board are going to be. I know that I have to use a loop but I don't know how I'd do it. Thank you in advance!

Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by