How can i do that?
1 view (last 30 days)
Show older comments
a. Ask the user for the length of the edge.
b. Define the axes of the chart according to the entered edge length.
c. Draw the square with the origin points (0,0) and step intervals in 0.5 units.
D. Then draw the edges in a straight line. (For example, if the user enters the number 20
You should get the image in the picture below.)
The drawing should have a star as above
how can i do that?
5 Comments
Accepted Answer
Jan
on 24 Mar 2021
Edited: Jan
on 24 Mar 2021
a = input('Bir sayi giriniz=');
figure;
axes('NextPlot', 'add', ... % as: hold on
'XLim', [-1, a+1], 'YLim', [-1, a+1], ...
'DefaultLineMarkerSize', 3); % More compact code
Delay = 0.05;
for b = 0:0.5:a
plot(b, 0, '*k')
pause(Delay)
end
for b = 0:0.5:a
plot(0, b, '*k')
plot(a, b, '*k')
pause(Delay)
end
for b = 0:0.5:a
plot(b, a, '*k')
pause(Delay)
end
4 Comments
Walter Roberson
on 24 Mar 2021
Edited: Walter Roberson
on 24 Mar 2021
In order to draw a thinner line, you will need a monitor that is higher resolution, as you are already drawing a line that is only 1 physical pixel thick, unless you happen to be displaying on an iPhone or similar very-high-resolution display.
get(0, 'ScreenPixelsPerInch')
get(0, 'ScreenSize')
get(0, 'MonitorPositions')
1/2 point is (1/72)/2 inches, multiply by (99 pixels per inch) = 0.6875 pixels
Reference: "The plot above uses the default MATLAB line width of 0.5 points."https://blogs.mathworks.com/steve/2019/02/22/making-your-plot-lines-thicker/ (Steve was part of the MATLAB graphics implementation team)
More Answers (1)
Walter Roberson
on 23 Mar 2021
You need six loop phases.
- draw the bottom stars left to right
- draw stars up on the left and right simultaneously
- draw stars on the top from left to right
- draw the line on the bottom from left to right, with shorter pause than you use for the stars
- draw the line up from the bottom on left and right simultaneously, using a shorter pause than for the stars
- draw the line across the top from left to right, using a shorter pause than for the stars
I already showed you in a previous post how to draw animated lines of stars using plot() with '*k' and drawing with different changing limits.
I already showed you in a previous post how to draw animated lines using plot with '-k' and different changing limits.
You already knew about hold on, and about pause()
I already showed you in a previous post how to change the drawing limits over time.
You already have all the tools you need to solve this.
There are some advanced techniques to make the drawing more efficient. You could look at animatedline() for example.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!