Browse Source

des trucs

master
DemiSel 3 years ago
parent
commit
6f35d47d5b

+ 12
- 0
lib/Agents/Agent.hpp View File

34
 	virtual void loop();
34
 	virtual void loop();
35
 	virtual void move();
35
 	virtual void move();
36
 	virtual void paint();
36
 	virtual void paint();
37
+
38
+protected:
39
+	virtual void init();
40
+};
41
+
42
+class StraightPaintAgent : public RepaintAgent
43
+{
44
+public:
45
+	StraightPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize);
46
+
47
+protected:
48
+	virtual void init();
37
 };
49
 };
38
 
50
 
39
 class PullPaintAgent : public RepaintAgent
51
 class PullPaintAgent : public RepaintAgent

+ 3
- 1
lib/Environment/PictureEnvironment.hpp View File

23
 	std::vector<std::unique_ptr<Agent>> fAgents;
23
 	std::vector<std::unique_ptr<Agent>> fAgents;
24
 	std::list<Agent>::iterator fAgentsIterator;
24
 	std::list<Agent>::iterator fAgentsIterator;
25
 
25
 
26
-	PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow, util::Platform* iPlatform);
26
+	PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow, util::Platform* iPlatform, bool iDisplayOriginal);
27
 	void getPerception(Perception* ioPercept, int iX, int iY);
27
 	void getPerception(Perception* ioPercept, int iX, int iY);
28
 	void makeAgents(int iNumber, int iDotSize, int iMoveSize);
28
 	void makeAgents(int iNumber, int iDotSize, int iMoveSize);
29
 	void makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
29
 	void makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
30
 	void makePullPaintAgents(int iNumber, int iDotSize, int iMoveSize);
30
 	void makePullPaintAgents(int iNumber, int iDotSize, int iMoveSize);
31
+	void makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
31
 	bool paint(int iX, int iY, const sf::Color Color);
32
 	bool paint(int iX, int iY, const sf::Color Color);
32
 
33
 
33
 	sf::Uint32 getCell(int iX, int iY);
34
 	sf::Uint32 getCell(int iX, int iY);
39
 	void displayLockInput();
40
 	void displayLockInput();
40
 
41
 
41
 private:
42
 private:
43
+	bool fDisplayOriginal;
42
 	PictureEnvironment();
44
 	PictureEnvironment();
43
 };
45
 };
44
 
46
 

+ 1
- 1
src/Agents/PullPaintAgent.cpp View File

10
 	fXPos = (((double)rand() / RAND_MAX) * vWidth);
10
 	fXPos = (((double)rand() / RAND_MAX) * vWidth);
11
 	fYPos = (((double)rand() / RAND_MAX) * vHeight);
11
 	fYPos = (((double)rand() / RAND_MAX) * vHeight);
12
 
12
 
13
-	fColor = sf::Color(fEnvironment->getCell(fXPos, fYPos));
13
+	fColor = sf::Color(fEnvironment->getCellOriginal(fXPos, fYPos));
14
 }
14
 }
15
 
15
 
16
 void PullPaintAgent::move()
16
 void PullPaintAgent::move()

+ 16
- 14
src/Agents/RepaintAgent.cpp View File

4
 RepaintAgent::RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
4
 RepaintAgent::RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
5
 	Agent(iEnvironment, iDotSize, iMoveSize)
5
 	Agent(iEnvironment, iDotSize, iMoveSize)
6
 {
6
 {
7
-	int vWidth = fEnvironment->getWidth();
8
-	int vHeight = fEnvironment->getHeight();
9
-
10
-	fXPos = (((double)rand() / RAND_MAX) * vWidth);
11
-	fYPos = (((double)rand() / RAND_MAX) * vHeight);
12
-
13
-	fColor = sf::Color(fEnvironment->getCell(fXPos, fYPos));
7
+	init();
14
 
8
 
15
 	//Initalize list of possible movement vectors
9
 	//Initalize list of possible movement vectors
16
 	fMovements = std::vector<std::vector<int>>();
10
 	fMovements = std::vector<std::vector<int>>();
25
 	}
19
 	}
26
 }
20
 }
27
 
21
 
22
+void RepaintAgent::init()
23
+{
24
+	int vWidth = fEnvironment->getWidth();
25
+	int vHeight = fEnvironment->getHeight();
26
+
27
+	fXPos = (((double)rand() / RAND_MAX) * vWidth);
28
+	fYPos = (((double)rand() / RAND_MAX) * vHeight);
29
+	fColor = sf::Color(fEnvironment->getCellOriginal(fXPos, fYPos));
30
+}
31
+
28
 void RepaintAgent::move()
32
 void RepaintAgent::move()
29
 {
33
 {
34
+	//Only move on cells having a sufficiently close color
30
 	fValidMovementIndexes.clear();
35
 	fValidMovementIndexes.clear();
31
 	int tolerance = 5;
36
 	int tolerance = 5;
32
 	for (int i = 0; i < static_cast<int>(fMovements.size()); i++)
37
 	for (int i = 0; i < static_cast<int>(fMovements.size()); i++)
33
 	{
38
 	{
34
 		sf::Uint32 va = fEnvironment->getCellOriginal(fXPos + fMovements.at(i).at(0), fYPos + fMovements.at(i).at(1));
39
 		sf::Uint32 va = fEnvironment->getCellOriginal(fXPos + fMovements.at(i).at(0), fYPos + fMovements.at(i).at(1));
35
 		sf::Uint32 vb = (int)fColor.toInteger();
40
 		sf::Uint32 vb = (int)fColor.toInteger();
36
-		//std::cout << std::hex << va << " : " << std::hex << vb << "\n";
37
-		//std::cout << std::hex << (va << 8 >> 24) << " : " << (vb << 8 >> 24) << "\n";
38
-		//std::cout << abs((int)(va << 8 >> 24) - (int)(vb << 8 >> 24)) << "\n\n";
39
 		bool vcomp =
41
 		bool vcomp =
40
 			abs((int)(va >> 24) - (int)(vb >> 24)) <= tolerance &&			 //R
42
 			abs((int)(va >> 24) - (int)(vb >> 24)) <= tolerance &&			 //R
41
 			abs((int)(va << 8 >> 24) - (int)(vb << 8 >> 24)) <= tolerance && //G
43
 			abs((int)(va << 8 >> 24) - (int)(vb << 8 >> 24)) <= tolerance && //G
42
 			abs((int)(va << 16 >> 24) - (int)(vb << 16 >> 24)) <= tolerance; //B
44
 			abs((int)(va << 16 >> 24) - (int)(vb << 16 >> 24)) <= tolerance; //B
43
 
45
 
44
-		//if ((double)std::min(va, vb) / std::max(va, vb) > 0.7)
45
 		if (vcomp)
46
 		if (vcomp)
46
 		{
47
 		{
47
-			//std::cout << vcomp << "\n";
48
-			//std::string j;
49
-			//std::cin >> j;
50
 			fValidMovementIndexes.push_back(i);
48
 			fValidMovementIndexes.push_back(i);
51
 		}
49
 		}
52
 	}
50
 	}
57
 		fXPos += fCurrentMovement.at(0);
55
 		fXPos += fCurrentMovement.at(0);
58
 		fYPos += fCurrentMovement.at(1);
56
 		fYPos += fCurrentMovement.at(1);
59
 	}
57
 	}
58
+	else
59
+	{
60
+		init();
61
+	}
60
 }
62
 }
61
 
63
 
62
 void RepaintAgent::paint()
64
 void RepaintAgent::paint()

+ 32
- 0
src/Agents/StraightPaintAgent.cpp View File

1
+#include <Agents/Agent.hpp>
2
+#include <Environment/PictureEnvironment.hpp>
3
+
4
+StraightPaintAgent::StraightPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
5
+	RepaintAgent(iEnvironment, iDotSize, iMoveSize)
6
+{
7
+	init();
8
+}
9
+
10
+void StraightPaintAgent::init()
11
+{
12
+	RepaintAgent::init();
13
+
14
+	//Initalize list of possible movement vectors
15
+	fMovements = std::vector<std::vector<int>>();
16
+	if (rand() % 2)
17
+	{
18
+		for (int i = 0; i <= fMoveSize; i++)
19
+		{
20
+			fMovements.push_back({ i, 0 });
21
+			fMovements.push_back({ -i, 0 });
22
+		}
23
+	}
24
+	else
25
+	{
26
+		for (int j = 0; j <= fMoveSize; j++)
27
+		{
28
+			fMovements.push_back({ 0, j });
29
+			fMovements.push_back({ 0, -j });
30
+		}
31
+	}
32
+}

+ 36
- 8
src/Environment/PictureEnvironment.cpp View File

9
 {
9
 {
10
 }
10
 }
11
 
11
 
12
-PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow, util::Platform* iPlatform) :
12
+PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow, util::Platform* iPlatform, bool iDisplayOriginal) :
13
 	fSize(iWindow->getSize())
13
 	fSize(iWindow->getSize())
14
 {
14
 {
15
+	fDisplayOriginal = iDisplayOriginal;
15
 
16
 
16
 	fFilePath = iFilePath;
17
 	fFilePath = iFilePath;
17
 	//sf::Texture fLoadedImage;
18
 	//sf::Texture fLoadedImage;
22
 	fImage = fTextureImage.copyToImage();
23
 	fImage = fTextureImage.copyToImage();
23
 	fOriginalImage = fTextureImage.copyToImage();
24
 	fOriginalImage = fTextureImage.copyToImage();
24
 
25
 
25
-	//memccpy(&fFilePath, &iFilePath, *iFilePath., 10);
26
+	if (!fDisplayOriginal)
27
+	{
28
+		fImage.create(fImage.getSize().x, fImage.getSize().y);
29
+	}
26
 	fPlatform = iPlatform;
30
 	fPlatform = iPlatform;
27
 	fWindow = iWindow;
31
 	fWindow = iWindow;
32
+
28
 	float screenScalingFactor = fPlatform->getScreenScalingFactor(fWindow->getSystemHandle());
33
 	float screenScalingFactor = fPlatform->getScreenScalingFactor(fWindow->getSystemHandle());
29
-	fWindow->create(sf::VideoMode(800.0f * screenScalingFactor, 600.0f * screenScalingFactor), "SFML works!");
34
+
35
+	fInitialSize.x = fTextureImage.getSize().x * screenScalingFactor;
36
+	fInitialSize.y = fTextureImage.getSize().y * screenScalingFactor;
37
+
38
+	//fInitialSize.x = fTextureImage.getSize().x / 3 * screenScalingFactor;
39
+	if (fTextureImage.getSize().x > sf::VideoMode::getDesktopMode().width)
40
+	{
41
+		double vRapport = (double)sf::VideoMode::getDesktopMode().width / fTextureImage.getSize().x;
42
+		fInitialSize.x *= vRapport;
43
+		fInitialSize.y *= vRapport;
44
+	}
45
+	if (fTextureImage.getSize().y > sf::VideoMode::getDesktopMode().height)
46
+	{
47
+		double vRapport = (double)sf::VideoMode::getDesktopMode().height / fTextureImage.getSize().y;
48
+		fInitialSize.x *= vRapport;
49
+		fInitialSize.y *= vRapport;
50
+	}
51
+
52
+	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "SMA");
30
 	fPlatform->setIcon(fWindow->getSystemHandle());
53
 	fPlatform->setIcon(fWindow->getSystemHandle());
31
-	fInitialSize.x = 800.0f * screenScalingFactor;
32
-	fInitialSize.y = 600.0f * screenScalingFactor;
54
+
33
 	//fShape = sf::RectangleShape(fSize);
55
 	//fShape = sf::RectangleShape(fSize);
34
-	fShape = sf::RectangleShape(DEFAUMT_SIMZE);
56
+	fShape = sf::RectangleShape(fInitialSize);
35
 	fAgents = std::vector<std::unique_ptr<Agent>>();
57
 	fAgents = std::vector<std::unique_ptr<Agent>>();
36
 	fShape.setFillColor(sf::Color::White);
58
 	fShape.setFillColor(sf::Color::White);
37
-
38
 	fShape.setTexture(&fTextureImage);
59
 	fShape.setTexture(&fTextureImage);
39
 }
60
 }
40
 
61
 
149
 	}
170
 	}
150
 }
171
 }
151
 
172
 
173
+void PictureEnvironment::makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize)
174
+{
175
+	for (int i = 0; i < iNumber; i++)
176
+	{
177
+		fAgents.push_back(std::make_unique<StraightPaintAgent>(this, iDotSize, iMoveSize));
178
+	}
179
+}
180
+
152
 void PictureEnvironment::displayLockInput()
181
 void PictureEnvironment::displayLockInput()
153
 {
182
 {
154
 	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");
183
 	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");
161
 
190
 
162
 bool PictureEnvironment::paint(int iX, int iY, const sf::Color iColour)
191
 bool PictureEnvironment::paint(int iX, int iY, const sf::Color iColour)
163
 {
192
 {
164
-
165
 	bool doable = iX > 0 && iX < getWidth() && iY > 0 && iY < getHeight();
193
 	bool doable = iX > 0 && iX < getWidth() && iY > 0 && iY < getHeight();
166
 	if (doable)
194
 	if (doable)
167
 	{
195
 	{

+ 10
- 7
src/Main.cpp View File

7
 {
7
 {
8
 	util::Platform platform;
8
 	util::Platform platform;
9
 #if defined(_DEBUG)
9
 #if defined(_DEBUG)
10
-	std::cout << "Hello World!" << std::endl;
10
+	std::cout << "Zé Parti" << std::endl;
11
 #endif
11
 #endif
12
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
12
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
13
-	std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
14
-	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA315024.jpg";
13
+	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
14
+	std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA315024.jpg";
15
+	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
16
+	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
15
 	//std::string filepath = "content/sfml.png";
17
 	//std::string filepath = "content/sfml.png";
16
 	sf::RenderWindow window;
18
 	sf::RenderWindow window;
17
 
19
 
20
 	// Use the screenScalingFactor
22
 	// Use the screenScalingFactor
21
 
23
 
22
 	//
24
 	//
23
-
24
-	PictureEnvironment vEnvironment(filepath, &window, &platform);
25
+	bool vDisplayOriginal = false;
26
+	PictureEnvironment vEnvironment(filepath, &window, &platform, vDisplayOriginal);
25
 
27
 
26
 	//vEnvironment.makeAgents(10000, 1, 10);
28
 	//vEnvironment.makeAgents(10000, 1, 10);
27
-	vEnvironment.makeRepaintAgents(300, 20, 10);
28
-	vEnvironment.makePullPaintAgents(200, 20, 10);
29
+	vEnvironment.makeRepaintAgents(50, 30, 10);
30
+	vEnvironment.makeStraightRepaintAgents(250, 20, 15);
31
+	vEnvironment.makePullPaintAgents(50, 20, 10);
29
 	//int i = 0;
32
 	//int i = 0;
30
 	while (vEnvironment.loop())
33
 	while (vEnvironment.loop())
31
 	{
34
 	{

Loading…
Cancel
Save