turbo pascal图形输出题(一个菱形); * +++ +++ *
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/17 23:22:46
turbo pascal图形输出题(一个菱形); * +++ +++ *
program Project1;
var
TopX,TopY,LeftX,LeftY,BottomX,BottomY,x1,x2,y:Integer;
begin
TopX := 33;
TopY := 2;
LeftX := 1;
LeftY := 10;
if (LeftX > 0) and (LeftY > 0) and (TopX > 0) and (TopY > 0) and
(LeftX < TopX) and (LeftY > TopY) then
begin
{将光标定位到顶点所在行}
for y := 2 to TopY do
Writeln;
{输出菱形的上半部分}
for y := TopY to LeftY do
begin
x1 := Round(TopX - (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
x2 := Round(TopX + (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
Write('*':x2);
Write(#13);
Writeln('*':x1);
end;
{输出菱形的下半部分}
BottomX := TopX;
BottomY := LeftY * 2 - TopY;
for y := LeftY + 1 to BottomY do
begin
x1 := Round(BottomX - (BottomX - LeftX) * (y - BottomY) / (LeftY - BottomY));
x2 := Round(BottomX + (BottomX - LeftX) * (y - BottomY) / (LeftY - BottomY));
Write('*':x2);
Write(#13);
Writeln('*':x1);
end;
end;
Readln;
end.
如果你不是初学者,可以用CRT.pas单元的GotoXY直接将字符输出到屏幕指定位置,那样一个循环内就能打印全部菱形(一次输出四个点):
for y := TopY to LeftY do
begin
x1 := Round(TopX - (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
x2 := Round(TopX + (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
y1 := LeftY * 2 - y;
GotoXY(x1,y);
Write('*');
GotoXY(x2,y);
Write('*');
GotoXY(x1,y1);
Write('*');
GotoXY(x2,y1);
Write('*');
end;
再问: 不能分开的,我是初学者,就用循环做,麻烦你打一下,谢谢
再答: 什么叫“不能分开的”,我“分开”什么了? 我不是给你两个答案么,你用第一个答案就行了。您得听得懂别人说话啊...
var
TopX,TopY,LeftX,LeftY,BottomX,BottomY,x1,x2,y:Integer;
begin
TopX := 33;
TopY := 2;
LeftX := 1;
LeftY := 10;
if (LeftX > 0) and (LeftY > 0) and (TopX > 0) and (TopY > 0) and
(LeftX < TopX) and (LeftY > TopY) then
begin
{将光标定位到顶点所在行}
for y := 2 to TopY do
Writeln;
{输出菱形的上半部分}
for y := TopY to LeftY do
begin
x1 := Round(TopX - (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
x2 := Round(TopX + (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
Write('*':x2);
Write(#13);
Writeln('*':x1);
end;
{输出菱形的下半部分}
BottomX := TopX;
BottomY := LeftY * 2 - TopY;
for y := LeftY + 1 to BottomY do
begin
x1 := Round(BottomX - (BottomX - LeftX) * (y - BottomY) / (LeftY - BottomY));
x2 := Round(BottomX + (BottomX - LeftX) * (y - BottomY) / (LeftY - BottomY));
Write('*':x2);
Write(#13);
Writeln('*':x1);
end;
end;
Readln;
end.
如果你不是初学者,可以用CRT.pas单元的GotoXY直接将字符输出到屏幕指定位置,那样一个循环内就能打印全部菱形(一次输出四个点):
for y := TopY to LeftY do
begin
x1 := Round(TopX - (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
x2 := Round(TopX + (TopX - LeftX) * (y - TopY) / (LeftY - TopY));
y1 := LeftY * 2 - y;
GotoXY(x1,y);
Write('*');
GotoXY(x2,y);
Write('*');
GotoXY(x1,y1);
Write('*');
GotoXY(x2,y1);
Write('*');
end;
再问: 不能分开的,我是初学者,就用循环做,麻烦你打一下,谢谢
再答: 什么叫“不能分开的”,我“分开”什么了? 我不是给你两个答案么,你用第一个答案就行了。您得听得懂别人说话啊...