-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaling.cpp
More file actions
66 lines (55 loc) · 1.51 KB
/
Scaling.cpp
File metadata and controls
66 lines (55 loc) · 1.51 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
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
int main()
{
// Window size
const int WIDTH = 800;
const int HEIGHT = 600;
// Scaling parameters
float scaleX = 1.0f;
float scaleY = 1.0f;
float scaleSpeed = 0.01f;
bool scalingUp = true;
// Create the window
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Scaling Example");
// Game loop
while (window.isOpen())
{
// Handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
// Update scaling
if (scalingUp)
{
scaleX += scaleSpeed;
scaleY += scaleSpeed;
if (scaleX >= 2.0f)
scalingUp = false;
}
else
{
scaleX -= scaleSpeed;
scaleY -= scaleSpeed;
if (scaleX <= 1.0f)
scalingUp = true;
}
// Clear the window
window.clear(sf::Color::Black);
// Draw a rectangle with scaling
sf::RectangleShape rectangle(sf::Vector2f(200.0f, 100.0f));
rectangle.setPosition(WIDTH / 2.0f, HEIGHT / 2.0f);
rectangle.setOrigin(100.0f, 50.0f);
rectangle.setScale(scaleX, scaleY);
rectangle.setFillColor(sf::Color::Red);
window.draw(rectangle);
// Update the window
window.display();
// Add a delay
sf::sleep(sf::milliseconds(100));
}
return 0;
}