Something like this?
const int nofRows;
const int nofCols;
const int distance; //distance between dots
const float offset = distance/2.f;
const float height = std::sqrt(std::pow(distance,2) - std::pow(offset,2));
for (int i=0; i<nofRows; ++i){
for (int j=0; j<nofCols; ++j){
if (i%2==0) dot.setPosition(j*distance, i*height);
else dot.setPosition(j*distance+offset, i*height);
}
}
Odd rows get offset by half the distance. Gap between rows is the height of the equilateral triangles.
Have you checked the SFML Graphic tutorials to get familiar with how everything works?
Here's the above code in a basic working example
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(300, 150), "Dots");
sf::CircleShape dot(5.f);
dot.setFillColor(sf::Color::Yellow);
const int nofRows = 5; //number of rows
const int nofCols = 10; //number of columns
const int distance = 30; //distance between dots
const float offset = distance/2.f; //offset for odd rows
const float height = std::sqrt(std::pow(distance,2.f) - std::pow(offset,2.f)); //height of triangles
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
for (int i=0; i<nofRows; ++i){
for (int j=0; j<nofCols; ++j){
if (i%2==0) dot.setPosition(j*distance, i*height); //even rows
else dot.setPosition(j*distance+offset, i*height); //odd rows
window.draw(dot);
}
}
window.display();
}
return 0;
}
(had forgotten to take square root for correct height)
Good luck.