-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (77 loc) · 2.42 KB
/
main.cpp
File metadata and controls
83 lines (77 loc) · 2.42 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
82
83
//
// main.cpp
// Pigon
//
// Created by Squeege on 11/13/18.
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Constants.h"
int main( )
{
// creates the window
sf::RenderWindow window(sf::VideoMode(1280,1080), "Pigon" );
window.setFramerateLimit(60);
// prints dimensions of the window
std::printf("The Window Size is: %i %i", window.getSize().x,window.getSize().y);
std::cout << "\nSpace: Restart Drawing\n\nUp Arrow: Increase Framerate(Max: 60)\n\nDown Arrow: Decrease Framerate";
// creates the points which we need inorder to write the lines
sf::CircleShape decagon(400.f, 10);
decagon.move(window.getSize().x / 2, window.getSize().y / 2);
int i = 1;
int framerate = 60;
// code running in the window
while(window.isOpen())
{
// handle all events
sf::Event event;
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
window.close();
break;
}
}
// Restarts Drawing
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
i = 0;
window.clear();
}
// Slows Framerate
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
if(framerate > 1)
{
--framerate;
window.setFramerateLimit(framerate);
}
}
// Speeds up framerate, change the if statement to desired frame cap
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
if(framerate < 60)
{
++framerate;
window.setFramerateLimit(framerate);
}
}
// Uncomment to see framerate speeds
//std::printf("\n Framerate: %i", framerate);
// draws lines
if(i < 1000)
{
sf::Vertex a(decagon.getPoint(getDigit(i)), colors[getDigit(i)]);
sf::Vertex b(decagon.getPoint(getDigit(i+1)), colors[getDigit(i+1)]);
b.position.x += rand()%randomWidth - randomWidth / 2;
b.position.y += rand()%randomHeight - randomHeight / 2;
const sf::Vertex line[2] = {a, b};
window.draw(line, 2, sf::Lines);
i++;
}
// displays frames
window.display();
}
return 0;
}