Browse Source

randomness almost done?

master
Joshua Moerman 14 years ago
parent
commit
0ab0acd86b
  1. 32
      Attractor.cpp
  2. 11
      AwesomeAttractor.cbp
  3. 2
      Logger.hpp
  4. 7
      Projector.cpp
  5. 2
      Projector.hpp
  6. 3
      main.cpp

32
Attractor.cpp

@ -22,8 +22,36 @@ Attractor::Attractor(const std::string& filename) : kernel(0), projector(0) {
} }
Attractor::Attractor(){ Attractor::Attractor(){
LogError("Not implemented yet (random attractor)\n"); stfu::node kernel_node;
exit(1); switch(rand()%5){
case 0:
kernel_node.value("type") = "lorenz";
kernel_node.value("dimensions") = "3";
break;
case 1:
kernel_node.value("type") = "polynomial";
kernel_node.value("dimensions") = std::string() + (char)(rand()%3 + '2');
break;
case 2:
kernel_node.value("type") = "polynomial a";
kernel_node.value("dimensions") = "3";
break;
case 3:
kernel_node.value("type") = "logistic";
kernel_node.value("dimensions") = std::string() + (char)(rand()%3 + '2');
break;
case 4:
kernel_node.value("type") = "unravel";
kernel_node.value("dimensions") = "3";
break;
}
kernel = AttractorKernel::createAttractorKernel(kernel_node);
stfu::node projector_node;
projector_node.value("dimensions") = "2";
projector = Projector::createProjector(projector_node, projector_node);
} }
Attractor::~Attractor() { Attractor::~Attractor() {

11
AwesomeAttractor.cbp

@ -52,6 +52,9 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-Wno-unknown-pragmas" /> <Add option="-Wno-unknown-pragmas" />
</Compiler> </Compiler>
<Linker>
<Add library="png" />
</Linker>
<Unit filename="Attractor.cpp" /> <Unit filename="Attractor.cpp" />
<Unit filename="Attractor.hpp" /> <Unit filename="Attractor.hpp" />
<Unit filename="AttractorKernel.cpp" /> <Unit filename="AttractorKernel.cpp" />
@ -67,9 +70,7 @@
<Unit filename="attractors/testLorenz.stf" /> <Unit filename="attractors/testLorenz.stf" />
<Unit filename="attractors/testPolynomial.stf" /> <Unit filename="attractors/testPolynomial.stf" />
<Unit filename="attractors/testUnravel.stf" /> <Unit filename="attractors/testUnravel.stf" />
<Unit filename="canvae/PNG.cpp"> <Unit filename="canvae/PNG.cpp" />
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="canvae/PNG.hpp"> <Unit filename="canvae/PNG.hpp">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>
@ -89,9 +90,7 @@
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="myMath.hpp" /> <Unit filename="myMath.hpp" />
<Unit filename="ostream_helpers.h" /> <Unit filename="ostream_helpers.h" />
<Unit filename="pngwriter/pngwriter.cc"> <Unit filename="pngwriter/pngwriter.cc" />
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="pngwriter/pngwriter.h"> <Unit filename="pngwriter/pngwriter.h">
<Option target="&lt;{~None~}&gt;" /> <Option target="&lt;{~None~}&gt;" />
</Unit> </Unit>

2
Logger.hpp

@ -15,7 +15,7 @@ extern int verbose;
if ( verbose >= 1 ) printf(s, ##__VA_ARGS__); if ( verbose >= 1 ) printf(s, ##__VA_ARGS__);
#define LogError(s, ...) \ #define LogError(s, ...) \
if ( verbose >= 0 ) { printf("%s, %d: ", __FILE__, __LINE__); printf(s, ##__VA_ARGS__); } if ( verbose >= 0 ) { printf("%s, %s(), %d: ", __FILE__, __func__, __LINE__); printf(s, ##__VA_ARGS__); }

7
Projector.cpp

@ -53,8 +53,11 @@ void Projector::plot(const double* point) {
#include "projectors/Normalizer.hpp" #include "projectors/Normalizer.hpp"
Projector* Projector::createProjector(stfu::node const& projector, stfu::node const& system) { Projector* Projector::createProjector(stfu::node& projector, stfu::node& system) {
Projector* output = new Normalizer(3); const std::string attractorDimension = projector.getValue("dimensions");
const unsigned int dimension = atoi(attractorDimension.c_str());
Projector* output = new Normalizer(dimension);
return output; return output;
} }

2
Projector.hpp

@ -33,7 +33,7 @@ public:
void plot(const double* point); void plot(const double* point);
// factory function // factory function
static Projector* createProjector(stfu::node const& projector, stfu::node const& system); static Projector* createProjector(stfu::node& projector, stfu::node& system);
}; };
#endif // PROJECTOR_HPP #endif // PROJECTOR_HPP

3
main.cpp

@ -1,8 +1,8 @@
#include "Logger.hpp" #include "Logger.hpp"
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
#include <valarray>
#include <cstring> #include <cstring>
#include <cstdlib>
#include "Attractor.hpp" #include "Attractor.hpp"
#include "Canvas.hpp" #include "Canvas.hpp"
@ -40,6 +40,7 @@ int main(int argc, char* argv[]) {
unsigned int iterations = DEFAULT_ITERATIONS; unsigned int iterations = DEFAULT_ITERATIONS;
unsigned int width = DEFAULT_WIDTH; unsigned int width = DEFAULT_WIDTH;
unsigned int height = DEFAULT_HEIGHT; unsigned int height = DEFAULT_HEIGHT;
srand(time(0));
if(argc <= 1) { if(argc <= 1) {
showHelpText(); showHelpText();