Turtle functions, where to start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * \file turtle.h
 * \brief contains the interface for a turtle graphics object.
 *
 * This file contains the interface for a simple turtle class (for graphics).
 * Note that \code initwindow(width, height) \endcode must be called before
 * any \c turtles are used.
 */

#include "graphics2.h"

/**
* \brief A turtle graphics class.
*
* This class assumes that \code initwindow(width, height) \endcode
* has already been called to open a drawing window on the screen.
*/
class Turtle {
public:
	/**
     * Constructs a turtle at (\c x, \c y) with the pen currently in the up
	 * position.  The color of the pen is given by \c color.
     *
     * \param x the initial x coordinate for the turtle
     * \param y the initial y coordinate for the turtle
     * \param color the color of the turtle's pen
     */
	Turtle(int x, int y, int color);

	/**
	 * Moves the turtle up 10 pixels (drawing a line if the pen is down).
	 */
	void move_up();

	/**
	 * Moves the turtle down 10 pixels (drawing a line if the pen is down).
	 */
	void move_down();

	/**
	 * Moves the turtle left 10 pixels (drawing a line if the pen is down).
	 */
	void move_left();

	/**
	 * Moves the turtle right 10 pixels (drawing a line if the pen is down).
	 */
	void move_right();

	/**
	 * Sets the pen in the down position (touching the paper).
	 */
	void pen_up();

	/**
	 * Sets the pen in the up position (not touching the paper).
	 */
	void pen_down();

private:
	// ADD PRIVATE DATA FIELDS HERE!!!
	int xpos;
	int ypos;
	bool pendown;


};



Where do i start with the move_up() function???????? Would i change the Y variable or do i do sommething diffrent. im really confused.
Last edited on
You're going to need to give us more information than that. What kind of graphics library are you using?
graphics2.h?
Sorry... that doesn't help us much.

Are you using SDL, SFML, Irrlicht, OGRE, CrystralSpace...?

-Albatross
lol im a beginner i dont know what any of that is. im using visual studio............ i have to define the classes listed above. i was just curious how i would define the move_up function. if i could just adjust the Y variable?
graphics2.h File Reference
A file containing the function headers for some non-object oriented graphics functions. More...

Go to the source code of this file.

Enumerations
enum colors {
BLACK, BLUE, GREEN, CYAN,
RED, MAGENT, BROWN, LIGHTGRAY,
DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN,
LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE
}
the various colors that can be used when drawing shapes

More...

enum fill_styles {
EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL,
SLASH_FILL, BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL,
XHATCH_FILL, INTERLEAVE_FILL, WIDE_DOT_FILL, CLOSE_DOT_FILL,
USER_FILL
}
the various styles for filling in shapes

More...

Functions
void bar (int left, int top, int right, int bottom)
draws a filled-in rectangle.

void closegraph (void)
closes the grapics window

void ellipse (int x, int y, int stangle, int endangle, int xradius, int yradius)
Draws an empty ellipse.

void fillellipse (int x, int y, int xradius, int yradius)
Draws a filled-in ellipse.

int getch (void)
returns the ASCII value of the character typed by the user.

void initwindow (int width, int height)
opens a graphics window that is width pixels wide by height pixels high

void line (int x1, int y1, int x2, int y2)
draws a line

void rectangle (int left, int top, int right, int bottom)
Draws an empty rectangle.

void setcolor (int col)
Sets the color with which to draw.

void setfillstyle (int pattern, int color)
sets the fill style for filled in shapes


--------------------------------------------------------------------------------
Detailed Description
This function contains the headers for a number of non-object oriented graphics functions. You should not need to look at nor edit this file. Only those parts of the file that you might need to use have been documented.


--------------------------------------------------------------------------------

Enumeration Type Documentation
enum colors

These are the various colors that can be used in the graphics window. Anytime a color is needed, one of these constants should be used.

Enumerator:
BLACK
BLUE
GREEN
CYAN
RED
MAGENT
BROWN
LIGHTGRAY
DARKGRAY
LIGHTBLUE
LIGHTGREEN
LIGHTCYAN
LIGHTRED
LIGHTMAGENTA
YELLOW
WHITE

enum fill_styles

These are the various patterns that can be used to fill in rectangles (bar) and ellipses.

Enumerator:
EMPTY_FILL
SOLID_FILL
LINE_FILL
LTSLASH_FILL
SLASH_FILL
BKSLASH_FILL
LTBKSLASH_FILL
HATCH_FILL
XHATCH_FILL
INTERLEAVE_FILL
WIDE_DOT_FILL
CLOSE_DOT_FILL
USER_FILL


--------------------------------------------------------------------------------

Function Documentation
void bar ( int left,
int top,
int right,
int bottom
)

Draws a filled-in, rectangular, two-dimensional bar. The bar is filled using the current fill pattern and fill color. The upper left and lower right corners of the rectangle are given by (left, top) and (right, bottom), respectively.

Parameters:
left the x coordinate of the top left corner.
top the y coordinate of the top left corner.
right the x coordinate of the bottom right corner.
bottom the y coordinate of the bottom right corner.

void closegraph ( void )

This function closes the graphics window previously opened with a call to

initwindow(width, height)
void ellipse ( int x,
int y,
int stangle,
int endangle,
int xradius,
int yradius
)

Draws an elliptical arc in the current drawing color with its center at (x,y) and the horizontal and vertical axes given by xradius and yradius, respectively. The ellipse travels from stangle to endangle. If stangle equals 0 and endangle equals 360, the call to ellipse draws a complete ellipse. The angle for ellipse is reckoned counterclockwise, with 0 degrees at 3 o'clock, 90 degrees at 12 o'clock, and so on.

Parameters:
x the x cordinate of the center of the ellipse
y the y cordinate of the center of the ellipse
stangle the start angle for drawing the ellipse (use 0)
endangle the end angle for drawing the ellipse (use 360)
xradius the distance from the center to the rightmost point of the ellipse.
yradius the distance from the center to the topmost point of the ellipse.

void fillellipse ( int x,
int y,
int xradius,
int yradius
)

Draws an ellipse using (x,y) as a center point and xradius and yradius as the horizontal and vertical axes, and fills it with the current fill color and fill pattern.

Parameters:
x the x cordinate of the center of the ellipse
y the y cordinate of the center of the ellipse
xradius the distance from the center to the rightmost point of the ellipse.
yradius the distance from the center to the topmost point of the ellipse.

int getch ( void )

This function waits for the user to hit a key in the graphics window and returns the ASCII value of the character typed by the user. Note that the graphics window must have focus when the key is pressed in order for this function to receive the keypress event.

Returns:
the ASCII value of character typed in at the keyboard.
void initwindow ( int width,
int height
)

When this function is called, a graphics window that is width pixels wide by height pixels high is opened on the screen. Note that this function must be called before any draw functions are called. Also, you may need to play with the sizes because the boarder of the window is probably included in the size. In other words, the /c height includes the window bar at the top, so you will most likely have fewer than that may pixels availble to use for drawing.

Parameters:
width the width of the new window in pixels
height the height of the new window in pixels

void line ( int x1,
int y1,
int x2,
int y2
)

This function draws a line on the screen from (x1, y1) to (x2, y2) in the current color

Parameters:
x1 the x coordinate of the first point
y1 the y coordinate of the first point
x2 the x coordinate of the second point
y2 the y coordinate of the second point

void rectangle ( int left,
int top,
int right,
int bottom
)

Draws a rectangle using the current drawing color. The upper left and lower right corners of the rectangle are given by (left, top) and (right, bottom), respectively.

Parameters:
left the x coordinate of the top left corner.
top the y coordinate of the top left corner.
right the x coordinate of the bottom right corner.
bottom the y coordinate of the bottom right corner.

void setcolor ( int col )

Sets the color with which to draw.

Parameters:
col the new color to use for drawing. You should use one of the colors as defined by the enumeration colors.

void setfillstyle ( int pattern,
int color
)

Sets the current fill pattern and fill color. Note: The EMPTY_FILL style is like a solid fill using the current background color (which is set by setbkcolor).

Parameters:
pattern the pattern to use
color the color to use
We couldn't tell you, to be honest. I don't know if changing the y alone is enough, or if you would want to do graphics processing there as well, or what. We have no idea how the system works and without any name to go on we can't look it up.

ADDITION: Okay well it seems you have all the information there; what you do with the move_up() function seems mostly up to you unless the assignment has given you any other specifics you haven't mentioned. You'll just need to make sure you worry about if the "pen" is down or not when you move.
Last edited on
The <graphics2.h> is yet another version of the old MS/Borland DOS graphics library. It gives simple primatives like lines, polygons, arcs and circles, etc.


To "move up" you need to follow the directions:
Moves the turtle up 10 pixels (drawing a line if the pen is down).


So your function would work something like this:

1
2
3
4
5
if (the pen is down)
  {
  draw a line from (xpos, ypos) to (xpos, ypos - 10)
  }
ypos = ypos - 10

All of your functions will work similarly. The difference is simply how to draw the line.

Remember, to draw a line use the line() function.

Good luck!
Topic archived. No new replies allowed.