Browse Source

tentatives d'opti

master
DemiSel 3 years ago
parent
commit
fe6cd39aec
5 changed files with 46 additions and 17 deletions
  1. 2
    1
      lib/Agents/Agent.hpp
  2. 5
    2
      src/Agents/Agent.cpp
  3. 14
    4
      src/Agents/PullPaintAgent.cpp
  4. 13
    6
      src/Agents/RepaintAgent.cpp
  5. 12
    4
      src/Main.cpp

+ 2
- 1
lib/Agents/Agent.hpp View File

15
 	int fMoveSize;
15
 	int fMoveSize;
16
 	int fXPos;
16
 	int fXPos;
17
 	int fYPos;
17
 	int fYPos;
18
-
18
+	int fEnvWidth;
19
+	int fEnvHeight;
19
 	Agent();
20
 	Agent();
20
 	Agent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize);
21
 	Agent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize);
21
 	virtual void loop();
22
 	virtual void loop();

+ 5
- 2
src/Agents/Agent.cpp View File

20
 
20
 
21
 	fColor = sf::Color(vRand);
21
 	fColor = sf::Color(vRand);
22
 	//fColor = sf::Color(((rand() % fColor.Red.toInteger())));
22
 	//fColor = sf::Color(((rand() % fColor.Red.toInteger())));
23
-	fXPos = iEnvironment->getWidth() / 2;
24
-	fYPos = iEnvironment->getHeight() / 2;
23
+	fEnvWidth = iEnvironment->getWidth();
24
+	fEnvHeight = iEnvironment->getHeight();
25
+
26
+	fXPos = fEnvWidth / 2;
27
+	fYPos = fEnvHeight / 2;
25
 }
28
 }
26
 
29
 
27
 void Agent::loop()
30
 void Agent::loop()

+ 14
- 4
src/Agents/PullPaintAgent.cpp View File

15
 
15
 
16
 void PullPaintAgent::move()
16
 void PullPaintAgent::move()
17
 {
17
 {
18
-	double vRand = rand() % (fMoveSize + 1);
19
-	fXPos += vRand - fMoveSize / 2;
20
-	vRand = rand() % (fMoveSize + 1);
21
-	fYPos += vRand - fMoveSize / 2;
18
+	int vNewPosX = -1;
19
+	int vNewPosY = -1;
20
+	int vMoveIndex = ((((double)rand() / RAND_MAX) * (fMovements.size() - 1)));
21
+	vNewPosX = fXPos + fMovements.at(vMoveIndex).at(0);
22
+	vNewPosY = fYPos + fMovements.at(vMoveIndex).at(1);
23
+	while (vNewPosX < 0 || vNewPosX > fEnvWidth || vNewPosX < 0 || vNewPosY > fEnvHeight)
24
+	{
25
+		vMoveIndex = ((((double)rand() / RAND_MAX) * (fMovements.size() - 1)));
26
+		vNewPosX = fXPos + fMovements.at(vMoveIndex).at(0);
27
+		vNewPosY = fYPos + fMovements.at(vMoveIndex).at(1);
28
+	}
29
+
30
+	fXPos = vNewPosX;
31
+	fYPos = vNewPosY;
22
 }
32
 }
23
 
33
 
24
 void PullPaintAgent::loop()
34
 void PullPaintAgent::loop()

+ 13
- 6
src/Agents/RepaintAgent.cpp View File

31
 
31
 
32
 void RepaintAgent::move()
32
 void RepaintAgent::move()
33
 {
33
 {
34
+	int vXMove;
35
+	int vYMove;
36
+	int fMovementsCount = fMovements.size();
34
 	//Only move on cells having a sufficiently close color
37
 	//Only move on cells having a sufficiently close color
35
 	fValidMovementIndexes.clear();
38
 	fValidMovementIndexes.clear();
36
-	for (int i = 0; i < static_cast<int>(fMovements.size()); i++)
39
+	for (int i = 0; i < static_cast<int>(fMovementsCount); i++)
37
 	{
40
 	{
38
-		int vXMove = fMovements.at(i).at(0);
39
-		int vYMove = fMovements.at(i).at(1);
41
+		vXMove = fXPos + fMovements.at(i).at(0);
42
+		vYMove = fYPos + fMovements.at(i).at(1);
40
 		if (
43
 		if (
41
-			colorCloseEnough(fEnvironment->getCellOriginal(fXPos + vXMove, fYPos + vYMove)) && fEnvironment->getCell(fXPos + vXMove, fYPos + vYMove) != fColor.toInteger())
44
+			vXMove > 0 && vYMove > 0 && vXMove < fEnvWidth && vYMove < fEnvHeight && fEnvironment->getCell(vXMove, vYMove) != fColor.toInteger() && colorCloseEnough(fEnvironment->getCellOriginal(vXMove, vYMove)))
42
 		{
45
 		{
43
 			fValidMovementIndexes.push_back(i);
46
 			fValidMovementIndexes.push_back(i);
44
 		}
47
 		}
49
 		fCurrentMovement = fMovements.at(fValidMovementIndexes.at(vRandIndex));
52
 		fCurrentMovement = fMovements.at(fValidMovementIndexes.at(vRandIndex));
50
 		fXPos += fCurrentMovement.at(0);
53
 		fXPos += fCurrentMovement.at(0);
51
 		fYPos += fCurrentMovement.at(1);
54
 		fYPos += fCurrentMovement.at(1);
55
+		// std::cout << "moved " << fXPos << ":" << fYPos;
52
 	}
56
 	}
53
 	else
57
 	else
54
 	{
58
 	{
70
 	int vHalfBrush = fDotSize / 2;
74
 	int vHalfBrush = fDotSize / 2;
71
 	int vXLoopIndex = fXPos - vHalfBrush;
75
 	int vXLoopIndex = fXPos - vHalfBrush;
72
 	int vYLoopIndex = fYPos - vHalfBrush;
76
 	int vYLoopIndex = fYPos - vHalfBrush;
73
-	while (vXLoopIndex < (fXPos + vHalfBrush))
77
+	int vXMaxIndex = fXPos + vHalfBrush;
78
+	int vYMaxIndex = fYPos + vHalfBrush;
79
+	while (vXLoopIndex < (vXMaxIndex))
74
 	{
80
 	{
75
-		while (vYLoopIndex < fYPos + vHalfBrush)
81
+		while (vYLoopIndex < (vYMaxIndex))
76
 		{
82
 		{
77
 			fEnvironment->paint(vXLoopIndex, vYLoopIndex, fColor);
83
 			fEnvironment->paint(vXLoopIndex, vYLoopIndex, fColor);
84
+			// fEnvironment->paint(vXLoopIndex, vYLoopIndex, fColor);
78
 			vYLoopIndex++;
85
 			vYLoopIndex++;
79
 		}
86
 		}
80
 		vYLoopIndex = fYPos - vHalfBrush;
87
 		vYLoopIndex = fYPos - vHalfBrush;

+ 12
- 4
src/Main.cpp View File

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";
13
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
14
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA315024.jpg";
14
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA315024.jpg";
15
-	std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\14.jpg";
15
+	// std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\14.jpg";
16
+	// std::string filepath = "C:\\Users\\cash\\Pictures\\Capture.PNG";
17
+	// std::string filepath = "E:\\Fichiers\\Images\\PRE2020\\Photos\\Voyage\\Maroc\\P8253306.png";
18
+	std::string filepath = "E:\\Fichiers\\Images\\PRE2020\\Photos\\Voyage\\Maroc\\P8253294.png";
16
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
19
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
17
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
20
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
18
 	//std::string filepath = "content/sfml.png";
21
 	//std::string filepath = "content/sfml.png";
32
 	//vEnvironment.makeRepaintAgents(50, 50, 25, 15);
35
 	//vEnvironment.makeRepaintAgents(50, 50, 25, 15);
33
 	//vEnvironment.makeStraightRepaintAgents(1000, 25, 15, 50);
36
 	//vEnvironment.makeStraightRepaintAgents(1000, 25, 15, 50);
34
 
37
 
35
-	vEnvironment.makeRepaintAgents(50, 15, 8, 15);
36
-	vEnvironment.makeStraightRepaintAgents(1000, 15, 8, 50);
37
-	//vEnvironment.makePullPaintAgents(50, 20, 10);
38
+	vEnvironment.makeRepaintAgents(20, 100, 100, 15);
39
+	// vEnvironment.makeRepaintAgents(200, 40, 40, 15);
40
+	// vEnvironment.makeStraightRepaintAgents(20, 80, 80, 100);
41
+	// vEnvironment.makeRepaintAgents(1, 50, 50, 15);
42
+	// vEnvironment.makeStraightRepaintAgents(1000, 2, 8, 50);
43
+	// vEnvironment.makeStraightRepaintAgents(1000, 15, 8, 50);
44
+	// vEnvironment.makePullPaintAgents(4, 80, 80);
45
+	// vEnvironment.makePullPaintAgents(100, 50, 50);
38
 	//int i = 0;
46
 	//int i = 0;
39
 	while (vEnvironment.loop())
47
 	while (vEnvironment.loop())
40
 	{
48
 	{

Loading…
Cancel
Save