home *** CD-ROM | disk | FTP | other *** search
- /*
- ** TITLE: Turtle Graphics Commands
- ** AUTHOR: Jerry Hobart
- ** COMPUTER: IBM-PC or compatible
- ** OS: PC-DOS / MS-DOS
- ** LANGUAGE: TURBO-C 2.0
- ** PURPOSE: This packages provides functions necessary to program
- ** using TURTLE graphics with Turbo C ver 1.5 or 2.0.
- ** Many commands normally found in TURTLE graphics already
- ** have a counterpart in the Borland graphics library, and
- ** thus were not included here.
- */
-
-
- #include <math.h>
- #include <graphics.h>
-
- #define UP 0
- #define DOWN 1
-
- const double DEG2RAD=.01745329;
- double heading=0.0; /* the heading is expressed in degrees */
- /* with the following orientation: */
- /* 0 - towards top of screen */
- /* 90 - towards right side of screen */
- /* 180 - towards bottom of screen */
- /* 270 - towards left side of screen */
-
- int pen = UP; /* writing will only take place when */
- /* the pen is DOWN */
-
- double round(double x); /* function prototype */
-
- /**********************************************************************
- * function definitions *
- **********************************************************************/
-
- void setheading(double deg){
- heading=deg;
- while (heading>=360.) heading-=360.;
- while (heading<0.) heading+=360.;
- }
-
- void right (double angl){
- heading+=angl;
- while (heading>=360.) heading-=360.;
- while (heading<0.) heading+=360.;
- }
-
- void left (double angl){
- heading-=angl;
- while (heading>=360.) heading-=360.;
- while (heading<0.) heading+=360.;
- }
-
- void forward(int dist){
- int dx,dy;
-
- dx = round(dist * sin(heading * DEG2RAD));
- dy = round(- dist * cos(heading * DEG2RAD));
- if (pen == DOWN)
- linerel (dx,dy);
- else
- moverel (dx,dy);
- }
-
- void back(int dist){
- int dx,dy;
-
- dx = round(dist * sin((heading+180.)*DEG2RAD));
- dy = round(dist * cos(heading*DEG2RAD));
- if (pen == DOWN)
- linerel (dx,dy);
- else
- moverel (dx,dy);
- }
-
- void penup(void){
- pen = UP;
- }
-
- void pendown(void){
- pen = DOWN;
- }
-
- double getheading(){
- return heading;
- }
-
- int getpen(){
- return pen;
- }
-
- double round(double x){
- return floor(x + .5);
- }