-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtle.h
122 lines (101 loc) · 3.22 KB
/
turtle.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef TURTLE_GRAPHICS_H
#define TURTLE_GRAPHICS_H
#define _USE_MATH_DEFINES
#include <raylib.h>
#include <cmath>
#include <stdexcept>
class Turtle {
private:
Vector2 position; // Turtle's position.
float angle = 0; // Current heading.
Color penColor = BLACK; // Color of lines.
unsigned int penSpeed = 2; // Turtle's speed.
bool isPenDown = true; // Whether or not to put pen down.
float penSize = 1; // Size of lines.
int ScreenWidth; // Width of draw window.
int ScreenHeight; // Height of draw window.
RenderTexture2D framebuffer; // A frame buffer that stores the state of the previous frame.
Color bgColor = RAYWHITE;
// Linear interpolation function.
float lerp(float a, float b, float t);
// Draws the contents of the frame buffer to the screen.
void drawbuffer(Vector2 position);
public:
// `ScreenWidth`, `ScreenHeight`, `FPS`, `LogLevel` parameters can be set during initialization.
Turtle(int ScreenWidth = 800, int ScreenHeight = 600, int FPS = 60, int LogLevel = 7);
~Turtle();
// Set the frame rate.
void SetFPS(const int FPS);
// Set the log level.
void SetLogLevel(const int LogLevel);
// Set the turtle's movement speed, minimum 0, maximum 5.
void speed(unsigned int speed);
// Lift the pen and move the turtle after execution without lines.
void penup();
// Drop the pen which allows the turtle to draw lines while moving.
void pendown();
// Resize the pen.
void pensize(float size);
// Adjust pen-color.
void color(Color color);
// Adjust background-color.
void bgcolor(Color color);
// Go forward.
void forward(float distance);
// Go back.
void back(float distance);
// Turn left.
void left(float degrees);
// Turn right.
void right(float degrees);
// Set position.
void setxy(Vector2 position);
// Set x position.
void setx(float x);
// Set y position.
void sety(float y);
// Set turtle's heading.
void setheading(float angle);
// Go back to center and set heading to right.
void home();
// Clear all traces left by the turtle on the screen.
void clear();
// Clear the screen and reset the turtle's position and orientation.
void reset();
// Get turtle's current position.
Vector2 getPosition() const;
// Get turtle's current heading.
float heading() const;
// Keep the window open.
void done();
};
class TurtleAlgorithms : public Turtle {
public:
void task_A1(int, int);
void task_A2(int, int);
void task_A3(int, int);
void task_A4(int, int);
void task_A5(int, int);
void task_A6(int, int);
void task_A7(int, int);
void task_A8(int, int);
void task_A9(int, int);
void task_A10(int, int);
void task_A11(int, int);
void task_A12(int, int);
void task_A13(int, int);
void task_B1(int, int);
void task_B2(int, int);
void task_B3(int, int);
void task_B4(int, int);
void task_B5(int, int);
void task_B6(int, int);
void task_B7(int, int);
void task_B8(int, int);
void task_C1(int, int);
void task_C2(int, int);
void task_C3(int, int);
void task_C6(int, int);
void task_C7(int, int);
};
#endif // TURTLE_GRAPHICS_H