forked from berea-college-csc236/Koch-class-MASTER
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKoch-class-main.cpp
More file actions
81 lines (68 loc) · 1.6 KB
/
Koch-class-main.cpp
File metadata and controls
81 lines (68 loc) · 1.6 KB
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
/* Author: Jesse W. Walker
* Derived from Jan Pearce's Python code at
http://cs.berea.edu/courses/csc226/tasks/koch.py
*/
#include "CTurtle.hpp"
namespace ct = cturtle;
class koch {
public:
koch(ct::Turtle& turtle, int order, int size, int x, int y, ct::Color color)
: turtleRef(turtle) {
this->order = order;
this->size = size;
this->x = x;
this->y = y;
this->color = color;
moveto();
}
koch(ct::Turtle& turtle) : turtleRef(turtle) {
this->order = 3;
this->size = 200;
this->x = -250;
this->y = 0;
this->color = { "black" };
moveto();
}
void moveto() {
turtleRef.penup();
turtleRef.goTo(x, y);
turtleRef.pendown();
}
void draw_koch(int newOrder, int newSize) {
const int ANGLES[] = { 60, -120, 60, 0 };
turtleRef.pencolor(color);
if (newOrder == 0) {
turtleRef.forward(newSize);
}
else {
for (int i = 0; i < 4; i++) {
draw_koch(newOrder - 1, newSize / 3);
turtleRef.left(ANGLES[i]);
}
}
}
inline void draw_koch() {
draw_koch(order, size);
}
void snowflake() {
for (int i = 0; i < 3; i++) {
draw_koch();
turtleRef.right(120);
}
}
private:
int order;
int size;
int x;
int y;
ct::Color color;
ct::Turtle& turtleRef;
};
int main() {
ct::TurtleScreen scr;
ct::Turtle turtle(scr);
koch k(turtle);
k.snowflake();
scr.exitonclick();
return 0;
}