-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree2.cpp
50 lines (39 loc) · 1016 Bytes
/
tree2.cpp
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
#include <iostream>
#include <cmath>
#include <SFML/Graphics.hpp>
using namespace std;
sf::RenderWindow window(sf::VideoMode(800,800), "Tree");
void start(float inix, float iniy, float degree, float length)
{
if (length < 1.0f) return;
else
{
float newlength=0.67f * length;
float finx = inix + (newlength * (float)cos(degree * (3.14 / 180.0f)));
float finy = iniy + (newlength * (float)sin(degree * (3.14 / 180.0f)));
sf::Vertex line[]= {
sf::Vertex(sf::Vector2f(inix, iniy)),
sf::Vertex(sf::Vector2f(finx, finy))
};
start(finx, finy, degree+60.0f, newlength);
start(finx, finy, degree-30.0f, newlength);
window.draw(line, 2, sf::Lines);
//line.setFillColor(sf::Color::Blue);
//window.display(); // Uncomment for animation
}
}
int main()
{
window.clear();
start(400, 799, -90, 350);
window.display();
sf::Event event;
while (window.isOpen())
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) window.close();
}
}
return 0;
}