I've started learning C++ using Microsoft Visual Studio. I'm decided to create a simple GUI program that creates a "snowflake" wherever the user clicks on the screen. Seeing as how this is my first C++ program, I would greatly appreciate feedback on any aspect of my code.
snowflakes.cpp
// Includes //
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
// Declare function //
void snowflakes();
/**
* Creates a snowflake where the user clicks on the screen.
**/
void snowflakes() {
const int WIDTH = 1280;
const int HEIGHT = 960;
sf::RenderWindow render_window(
sf::VideoMode(WIDTH, HEIGHT), "Snowflakes"
);
sf::Event event;
sf::Image image;
sf::Mouse mouse;
image.create(WIDTH, HEIGHT, sf::Color::Black);
sf::Texture texture;
while (render_window.isOpen()) {
while (render_window.pollEvent(event)) {
if (event.type == sf::Event::EventType::Closed) {
render_window.close();
} else if (event.type == sf::Event::MouseButtonPressed) {
int mouse_x = mouse.getPosition(render_window).x;
int mouse_y = mouse.getPosition(render_window).y;
std::cout << mouse_x << " " << mouse_y << std::endl;
image.setPixel(mouse_x, mouse_y, sf::Color::White);
// Get random size of snowflake //
int size = (rand() % 20) + 10;
for (int i = 1; i < size; i++) {
image.setPixel(mouse_x + i, mouse_y, sf::Color::White);
image.setPixel(mouse_x - i, mouse_y, sf::Color::White);
image.setPixel(mouse_x, mouse_y + i, sf::Color::White);
image.setPixel(mouse_x, mouse_y - i, sf::Color::White);
image.setPixel(mouse_x + i, mouse_y + i, sf::Color::White);
image.setPixel(mouse_x - i, mouse_y - i, sf::Color::White);
image.setPixel(mouse_x + i, mouse_y - i, sf::Color::White);
image.setPixel(mouse_x - i, mouse_y + i, sf::Color::White);
}
}
}
texture.loadFromImage(image);
sf::Sprite dots(texture);
render_window.clear();
render_window.draw(dots);
render_window.display();
}
}
int main() {
// Start program //
snowflakes();
}
drawSnowflake
method in there. The how is clearly well done, but the what seems a bit missing in action. \$\endgroup\$