How can i do that?

3 visualizaciones (últimos 30 días)
ukulele
ukulele el 22 de Mzo. de 2021
Comentada: Jan el 24 de Mzo. de 2021
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 comentarios
Jan
Jan el 24 de Mzo. de 2021
@ukulele: It is still not clear what you are exactly asking for.
It is possible that you get an answer if you post your current code and ask a specific question concerning the next step.
Jan
Jan el 24 de Mzo. de 2021
@ukulele: Please do not remove the contents of your question after an answer has been posted. The nature of this forum is sharing problems and solutions. The deleting of the text of a question makes the answer meaningless. Therefore this is considered as an impolite act.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 24 de Mzo. de 2021
Editada: Jan el 24 de Mzo. de 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 comentarios
Walter Roberson
Walter Roberson el 24 de Mzo. de 2021
Editada: Walter Roberson el 24 de Mzo. de 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')
ans = 99
get(0, 'ScreenSize')
ans = 1×4
1 1 1920 1200
get(0, 'MonitorPositions')
ans = 1×4
1 1 1920 1200
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)
Jan
Jan el 24 de Mzo. de 2021
@ukulele: Please post the code you have tried. How do you check ifg the line is thin? For me the standard width of 0.5 is exactly 1 pixel on my monitor. It is impossible to draw a thinner line.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 23 de Mzo. de 2021
You need six loop phases.
  1. draw the bottom stars left to right
  2. draw stars up on the left and right simultaneously
  3. draw stars on the top from left to right
  4. draw the line on the bottom from left to right, with shorter pause than you use for the stars
  5. draw the line up from the bottom on left and right simultaneously, using a shorter pause than for the stars
  6. 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.

Community Treasure Hunt

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

Start Hunting!

Translated by