ソースを参照

tentatives d'opti

master
DemiSel 3年前
コミット
fe6cd39aec
5個のファイルの変更46行の追加17行の削除
  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 ファイルの表示

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

+ 5
- 2
src/Agents/Agent.cpp ファイルの表示

@@ -20,8 +20,11 @@ Agent::Agent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize)
20 20
 
21 21
 	fColor = sf::Color(vRand);
22 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 30
 void Agent::loop()

+ 14
- 4
src/Agents/PullPaintAgent.cpp ファイルの表示

@@ -15,10 +15,20 @@ PullPaintAgent::PullPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, i
15 15
 
16 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 34
 void PullPaintAgent::loop()

+ 13
- 6
src/Agents/RepaintAgent.cpp ファイルの表示

@@ -31,14 +31,17 @@ void RepaintAgent::init()
31 31
 
32 32
 void RepaintAgent::move()
33 33
 {
34
+	int vXMove;
35
+	int vYMove;
36
+	int fMovementsCount = fMovements.size();
34 37
 	//Only move on cells having a sufficiently close color
35 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 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 46
 			fValidMovementIndexes.push_back(i);
44 47
 		}
@@ -49,6 +52,7 @@ void RepaintAgent::move()
49 52
 		fCurrentMovement = fMovements.at(fValidMovementIndexes.at(vRandIndex));
50 53
 		fXPos += fCurrentMovement.at(0);
51 54
 		fYPos += fCurrentMovement.at(1);
55
+		// std::cout << "moved " << fXPos << ":" << fYPos;
52 56
 	}
53 57
 	else
54 58
 	{
@@ -70,11 +74,14 @@ void RepaintAgent::paint()
70 74
 	int vHalfBrush = fDotSize / 2;
71 75
 	int vXLoopIndex = fXPos - vHalfBrush;
72 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 83
 			fEnvironment->paint(vXLoopIndex, vYLoopIndex, fColor);
84
+			// fEnvironment->paint(vXLoopIndex, vYLoopIndex, fColor);
78 85
 			vYLoopIndex++;
79 86
 		}
80 87
 		vYLoopIndex = fYPos - vHalfBrush;

+ 12
- 4
src/Main.cpp ファイルの表示

@@ -12,7 +12,10 @@ int main()
12 12
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
13 13
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
14 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 19
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
17 20
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
18 21
 	//std::string filepath = "content/sfml.png";
@@ -32,9 +35,14 @@ int main()
32 35
 	//vEnvironment.makeRepaintAgents(50, 50, 25, 15);
33 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 46
 	//int i = 0;
39 47
 	while (vEnvironment.loop())
40 48
 	{

読み込み中…
キャンセル
保存