I wanted to create a circle with RGB color effect (Just like RBG color pallet) in SFML. but could not find any method to make it except using an image.
First, I Tried making a RGB rectangle (Just like RBG color pallet), I used several small Rectangles to make the effect work (let know if there’s an efficient method to do it), but now I want to make Circle, am pasting the code of Rectangle here:
#include <SFML/Graphics.hpp>
//Global Variable and define's
#define windowSize 450
#define rectSize 1.0f
int colorRange = 255;
int main()
{
//Creating new Window
sf::RenderWindow window(sf::VideoMode(windowSize, windowSize), "Colors", sf::Style::Close | sf::Style::Resize);
sf::View mainView = window.getDefaultView();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
//Close Window Code
window.close();
else if(event.type == sf::Event::Resized)
{
//View Resize Code
mainView.setSize
(
static_cast<float> (event.size.width),
static_cast<float> (event.size.height)
);
mainView.setCenter
(
static_cast<float> (event.size.width) / 2,
static_cast<float> (event.size.height)/ 2
);
}
window.setView(mainView);
}
for(int i = 0; i < colorRange; i++)
{
for(int j = 0; j < colorRange; j++)
{
sf::RectangleShape shape(sf::Vector2f(rectSize, rectSize));
shape.setPosition(sf::Vector2f(i * rectSize, j * rectSize));
shape.setFillColor(sf::Color(i, j, 127, 255));
window.draw(shape);
}
}
window.display();
window.clear(sf::Color::White);
}
return 0;
}
New contributor
Thanos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2