1
General / Re: Problem with storing generated pixel locations
« on: April 17, 2016, 08:56:40 pm »
Thank you very much ShadowMouse! I'm trying get into algorithm making, but this I just couldn't figure out.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I'm fairly sure the problem is knowing which pixels have been modified, not modifying the pixels themselves, in which case, I think you are going about it wrong. If you want to make pixels expanding out from the centre, just make a diamond shape of different sizes around the central pixel. e.g. first you start with a pixel x,y then you make a loop that does (x+1,y),(x-1,y),(x,y+1),(x,y-1), then make a loop that does (x+2,y),(x+1,y+1),(x,y+2),(x-1,y+1),(x-2,y),(x-1,y-1),(x,y-2),(x+1,y-1), etc.
EDIT: unless of course you do actually want to store all modified pixels and have the function go on forever as each one modifies all the ones around it, which will never stop.
#include "SFML\Graphics.hpp"
#include <random>
#include <ctime>
int main() {
srand(time(NULL));
sf::RenderWindow TestingWindow(sf::VideoMode(100, 100), "Testing Window");
sf::Image img;
sf::Texture txt;
sf::Sprite spr;
int x = 1, y = 1, z;
while (y < 100){
while (x < 100) {
z = rand() % 2 + 1;
if (z == 1) {
img.setPixel(x, y, sf::Color::Black);
}
else {
img.setPixel(x, y, sf::Color::Black);
}
x++;
}
x = 1; y++;
}
txt.loadFromImage(img);
spr.setTexture(txt);
while (TestingWindow.isOpen())
{
sf::Event event;
while (TestingWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed)
TestingWindow.close();
}
TestingWindow.clear();
TestingWindow.draw(spr);
TestingWindow.display();
}
}
Even though I answered your question (twice), I'm feeling generous.I'm so stupid. Thanks anyways for the help, hope this works wel XD.(click to show/hide)
if (Sprite[i].getTexture() == Texture) {
//code
}