标题:[分享]viky滴海龟作图
只看楼主
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
 问题点数:0 回复次数:3 
[分享]viky滴海龟作图

# include <graphics.h>
#include <math.h>
#include <stdio.h>
#define UP 0
#define DOWN 1
#define pie -3.1415
typedef int penState;
typedef struct{float v,h;}aPoint;
typedef struct
{
float heading;
penState pen;
int color;
aPoint Pos;
}newTurtle;
newTurtle turtle;
void StartTurtleGraphics()
{
setcolor(2);
rectangle(10,10,630,470);
outtextxy(20,20,"my name:zky");
outtextxy(220,20,"expriment num:31057157");
outtextxy(420,20,"question num:0.3");
line(10,30,630,30);
}
void SetTurtle()
{
float x,y,h;
if(turtle.Pos.v>600)turtle.Pos.v=600;
if(turtle.Pos.v<40)turtle.Pos.v=40;
if(turtle.Pos.h<60)turtle.Pos.h=60;
if(turtle.Pos.h>440)turtle.Pos.h=440;
x=turtle.Pos.v;
y=turtle.Pos.h;
h=turtle.heading;
setcolor(turtle.color);
circle(x,y,20);
circle(x+10,y,8);
circle(x-10,y,8);
circle(x,y+10,8);
circle(x,y-10,8);
circle(x+25*cos(h*pie/180),y+25*sin(h*pie/180),5);
line(x-20*cos(h*pie/180),y-20*sin(h*pie/180),x-30*cos(h*pie/180),y-30*sin(h*pie/180));
}

void StarTurtle()
{
turtle.Pos.v=320;
turtle.Pos.h=250;
turtle.heading=0;
turtle.color=2;
turtle.pen=DOWN;
SetTurtle();
}

void PenUP()
{
turtle.pen=UP;
}

void PenDown()
{
turtle.pen=DOWN;
}

float TurtleHeading()
{
return turtle.heading;
}

aPoint*TurtlePos()
{
aPoint *a;
a=&turtle.Pos;
return a;
}

void Move(int steps)
{
int a=turtle.color;
float m,n;
m=turtle.Pos.v;
n=turtle.Pos.h;
turtle.color=0;
SetTurtle();
turtle.color=a;
turtle.Pos.v+=steps*cos(turtle.heading*pie/180);
turtle.Pos.h+=steps*sin(turtle.heading*pie/180);
SetTurtle();
if(turtle.pen)
line(m,n,turtle.Pos.v,turtle.Pos.h);
}

void Turn(float degress)
{
int a=turtle.color;
turtle.color=0;
SetTurtle();
turtle.heading+=degress;
while(turtle.heading>=360)turtle.heading-=360;
while(turtle.heading<=0)turtle.heading+=360;
turtle.color=a;
SetTurtle();

}

void MoveTTo(aPoint newPos)
{
int a=turtle.color;
float m,n;
m=turtle.Pos.v;
n=turtle.Pos.h;
turtle.color=0;
SetTurtle();
turtle.color=a;
turtle.Pos.v=newPos.v;
turtle.Pos.h=newPos.h;
SetTurtle();
if(turtle.pen)
line(m,n,turtle.Pos.v,turtle.Pos.h);
}

void TurnTTo(float angle)
{
turtle.heading=angle;
}

void SetTurtleColor(int color)
{
turtle.color=color;
}

void main()
{
int gd = DETECT, gm = 0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd, &gm, "");
StartTurtleGraphics();
StarTurtle();
Turn(30);
Move(100);
SetTurtleColor(4);
setcolor(4);
circle(turtle.Pos.v,turtle.Pos.h,30);


}

搜索更多相关主题的帖子: viky 海龟 float define typedef 
2007-06-14 23:29
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
得分:0 

where did you get that graphics.h? Still using Turbo C?

I would think the more popular compliers are MS C/C++ and g++(on Linux or Unix systems).



I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-06-15 02:50
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
得分:0 
因为我们老师要求用那个,硪也想用vc++写啊!

中環nite 燈光閃閃...
2007-06-15 12:30
herbert_1987
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:1314
专家分:0
注 册:2007-5-13
得分:0 
原来 viky 用的是 TC 可惜我不用....

人生重要的不是所站的位置,而是所朝的方向
2007-06-16 10:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-147577-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.370733 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved