I wrote code that worked, and then just stopped printing out a figure. below are
ID: 3595237 • Letter: I
Question
I wrote code that worked, and then just stopped printing out a figure. below are the two files that were used.
classdef Turtle
properties
% pen_paper value
x
y
heading
% pen values
pen_on_paper
% width
PEN_WIDTH1
% color
PEN_COLOR1
end
methods
function object = Turtle() % function
% make a create a object
object.x = 0;
object.y = 0;
object.heading = 90;
object.pen_on_paper = true;
object.PEN_WIDTH1 = [];
object.PEN_COLOR1 = [];
end
function object = forward(object,distance)
% distance
x2 = object.x + distance*cosd(object.heading);
y2 = object.y + distance*sind(object.heading);
if object.pen_on_paper
% draw
hold on
k = line([object.x, x2],[object.y, y2]);
k.Color = penColor;
k.penColor([1,0,0])
k.LineWidth = penWidth;
k.LineWidth = 1;
hold off
pause (0.1)
end
% location
object.x = x2;
object.y = y2;
end
function object = penWidth(object, ~)
new_width = [1,2,3,4];
object.PEN_WIDTH1 = rand(new_width);
end
function object = penColor(object,NCOLOR)
NCOLOR = ['yellow','red','blue','green','black','orange','purple'];
object.PEN_COLOR1 = rand(NCOLOR);
end
end
end
% support function
function b = square(b,side)
b = Turtle();
k = 100;
for x = 1:10
for y = 1:4
b.pen_on_paper = true;
b = b.forward(k);
b = b.rotate(90);
end
k = k - 10;
b.pen_on_paper = false;
b = b.forward(5);
b = b.rotate(90);
b = b.forward(5);
b = b.rotate(270);
k.Color = rand(PEN_COLOR1);
end
end
AND THIS IS THE 2ND ONE
for i=0:0
t = Turtle(); % create a Turtle object;
t = t.forward(100); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(100); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(100); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(100);
end
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(90); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(90); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(90); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(90);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(90);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(80); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(80); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(80); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(80);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(80);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(70); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(70); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(70); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(70);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(70);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(60); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(60); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(60); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(60);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(60);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(50); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(50); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(50); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(50);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(50);
t = t.penUp;
t = t.rotate(90);
t = t.forward(15);
t = t.rotate(90);
t = t.forward(15);
t = t.rotate(270);
t = t.penDown; bh
t = t.forward(20); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(20); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(20); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(20);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(20);
t = Turtle(); % create a Turtle object;
t = t.forward(100); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(100); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(100); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(100);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(90); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(90); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(90); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(90);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(90);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(80); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(80); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(80); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(80);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(80);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(70); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(70); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(70); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(70);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(70);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(60); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(60); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(60); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(60);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(60);
t = t.penUp;
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(90);
t = t.forward(5);
t = t.rotate(270);
t = t.penDown;
t = t.forward(50); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(50); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(50); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(50);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(50);
t = t.penUp;
t = t.rotate(90);
t = t.forward(15);
t = t.rotate(90);
t = t.forward(15);
t = t.rotate(270);
t = t.penDown;
t = t.forward(20); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(20); % drive forward 100
t = t.rotate(90); % rotate 90 deg CCW
t = t.forward(20); % drive forward 100
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(20);
t = t.rotate(90); %rotate 90 deg CCW
t = t.forward(20);
Explanation / Answer
The image you uploaded is not clear or is blurred even I zoomed it after downloading it.
Please be crystal clear about what you want to ask in the problem.
Do comment in comment section about what you actually want help in. Or ulpoad a clear image, so that it would be easy to detect the issue with the code.
Thank you.