소스 검색

des trucs

master
DemiSel 3 년 전
부모
커밋
6f35d47d5b

+ 12
- 0
lib/Agents/Agent.hpp 파일 보기

@@ -34,6 +34,18 @@ public:
34 34
 	virtual void loop();
35 35
 	virtual void move();
36 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 51
 class PullPaintAgent : public RepaintAgent

+ 3
- 1
lib/Environment/PictureEnvironment.hpp 파일 보기

@@ -23,11 +23,12 @@ public: // Access specifier
23 23
 	std::vector<std::unique_ptr<Agent>> fAgents;
24 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 27
 	void getPerception(Perception* ioPercept, int iX, int iY);
28 28
 	void makeAgents(int iNumber, int iDotSize, int iMoveSize);
29 29
 	void makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
30 30
 	void makePullPaintAgents(int iNumber, int iDotSize, int iMoveSize);
31
+	void makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
31 32
 	bool paint(int iX, int iY, const sf::Color Color);
32 33
 
33 34
 	sf::Uint32 getCell(int iX, int iY);
@@ -39,6 +40,7 @@ public: // Access specifier
39 40
 	void displayLockInput();
40 41
 
41 42
 private:
43
+	bool fDisplayOriginal;
42 44
 	PictureEnvironment();
43 45
 };
44 46
 

+ 1
- 1
src/Agents/PullPaintAgent.cpp 파일 보기

@@ -10,7 +10,7 @@ PullPaintAgent::PullPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, i
10 10
 	fXPos = (((double)rand() / RAND_MAX) * vWidth);
11 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 16
 void PullPaintAgent::move()

+ 16
- 14
src/Agents/RepaintAgent.cpp 파일 보기

@@ -4,13 +4,7 @@
4 4
 RepaintAgent::RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
5 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 9
 	//Initalize list of possible movement vectors
16 10
 	fMovements = std::vector<std::vector<int>>();
@@ -25,28 +19,32 @@ RepaintAgent::RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int i
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 32
 void RepaintAgent::move()
29 33
 {
34
+	//Only move on cells having a sufficiently close color
30 35
 	fValidMovementIndexes.clear();
31 36
 	int tolerance = 5;
32 37
 	for (int i = 0; i < static_cast<int>(fMovements.size()); i++)
33 38
 	{
34 39
 		sf::Uint32 va = fEnvironment->getCellOriginal(fXPos + fMovements.at(i).at(0), fYPos + fMovements.at(i).at(1));
35 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 41
 		bool vcomp =
40 42
 			abs((int)(va >> 24) - (int)(vb >> 24)) <= tolerance &&			 //R
41 43
 			abs((int)(va << 8 >> 24) - (int)(vb << 8 >> 24)) <= tolerance && //G
42 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 46
 		if (vcomp)
46 47
 		{
47
-			//std::cout << vcomp << "\n";
48
-			//std::string j;
49
-			//std::cin >> j;
50 48
 			fValidMovementIndexes.push_back(i);
51 49
 		}
52 50
 	}
@@ -57,6 +55,10 @@ void RepaintAgent::move()
57 55
 		fXPos += fCurrentMovement.at(0);
58 56
 		fYPos += fCurrentMovement.at(1);
59 57
 	}
58
+	else
59
+	{
60
+		init();
61
+	}
60 62
 }
61 63
 
62 64
 void RepaintAgent::paint()

+ 32
- 0
src/Agents/StraightPaintAgent.cpp 파일 보기

@@ -0,0 +1,32 @@
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 파일 보기

@@ -9,9 +9,10 @@ PictureEnvironment::PictureEnvironment()
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 13
 	fSize(iWindow->getSize())
14 14
 {
15
+	fDisplayOriginal = iDisplayOriginal;
15 16
 
16 17
 	fFilePath = iFilePath;
17 18
 	//sf::Texture fLoadedImage;
@@ -22,19 +23,39 @@ PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow*
22 23
 	fImage = fTextureImage.copyToImage();
23 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 30
 	fPlatform = iPlatform;
27 31
 	fWindow = iWindow;
32
+
28 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 53
 	fPlatform->setIcon(fWindow->getSystemHandle());
31
-	fInitialSize.x = 800.0f * screenScalingFactor;
32
-	fInitialSize.y = 600.0f * screenScalingFactor;
54
+
33 55
 	//fShape = sf::RectangleShape(fSize);
34
-	fShape = sf::RectangleShape(DEFAUMT_SIMZE);
56
+	fShape = sf::RectangleShape(fInitialSize);
35 57
 	fAgents = std::vector<std::unique_ptr<Agent>>();
36 58
 	fShape.setFillColor(sf::Color::White);
37
-
38 59
 	fShape.setTexture(&fTextureImage);
39 60
 }
40 61
 
@@ -149,6 +170,14 @@ void PictureEnvironment::makePullPaintAgents(int iNumber, int iDotSize, int iMov
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 181
 void PictureEnvironment::displayLockInput()
153 182
 {
154 183
 	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");
@@ -161,7 +190,6 @@ void PictureEnvironment::displayLockInput()
161 190
 
162 191
 bool PictureEnvironment::paint(int iX, int iY, const sf::Color iColour)
163 192
 {
164
-
165 193
 	bool doable = iX > 0 && iX < getWidth() && iY > 0 && iY < getHeight();
166 194
 	if (doable)
167 195
 	{

+ 10
- 7
src/Main.cpp 파일 보기

@@ -7,11 +7,13 @@ int main()
7 7
 {
8 8
 	util::Platform platform;
9 9
 #if defined(_DEBUG)
10
-	std::cout << "Hello World!" << std::endl;
10
+	std::cout << "Zé Parti" << std::endl;
11 11
 #endif
12 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 17
 	//std::string filepath = "content/sfml.png";
16 18
 	sf::RenderWindow window;
17 19
 
@@ -20,12 +22,13 @@ int main()
20 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 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 32
 	//int i = 0;
30 33
 	while (vEnvironment.loop())
31 34
 	{

Loading…
취소
저장