diff options
-rw-r--r-- | fractal.cpp | 6 | ||||
-rw-r--r-- | fractal.h | 2 | ||||
-rw-r--r-- | infinite.cpp | 27 |
3 files changed, 23 insertions, 12 deletions
diff --git a/fractal.cpp b/fractal.cpp index 145886a..a911177 100644 --- a/fractal.cpp +++ b/fractal.cpp | |||
@@ -508,7 +508,7 @@ int Fractal::load(const char* filename, Fractal& fractal) | |||
508 | return 0; | 508 | return 0; |
509 | } | 509 | } |
510 | 510 | ||
511 | Fractal Fractal::random() | 511 | Fractal Fractal::random(std::string colorsfile) |
512 | { | 512 | { |
513 | Fractal fractal; | 513 | Fractal fractal; |
514 | 514 | ||
@@ -577,10 +577,10 @@ Fractal Fractal::random() | |||
577 | } | 577 | } |
578 | 578 | ||
579 | std::vector<std::string> colors; | 579 | std::vector<std::string> colors; |
580 | std::ifstream colorfile("colors.txt"); | 580 | std::ifstream colorfile(colorsfile); |
581 | if (!colorfile.is_open()) | 581 | if (!colorfile.is_open()) |
582 | { | 582 | { |
583 | std::cout << "Could not find colors.txt" << std::endl; | 583 | std::cout << "Could not find colors file" << std::endl; |
584 | exit(-1); | 584 | exit(-1); |
585 | } | 585 | } |
586 | 586 | ||
diff --git a/fractal.h b/fractal.h index af098f4..cfd39db 100644 --- a/fractal.h +++ b/fractal.h | |||
@@ -50,7 +50,7 @@ class Fractal { | |||
50 | Color get_color(double c) const; | 50 | Color get_color(double c) const; |
51 | 51 | ||
52 | static int load(const char* filename, Fractal& fractal); | 52 | static int load(const char* filename, Fractal& fractal); |
53 | static Fractal random(); | 53 | static Fractal random(std::string colorsfile); |
54 | 54 | ||
55 | double filterlevel = 0.5; | 55 | double filterlevel = 0.5; |
56 | double gamma = 2.2; | 56 | double gamma = 2.2; |
diff --git a/infinite.cpp b/infinite.cpp index a491302..1409ba2 100644 --- a/infinite.cpp +++ b/infinite.cpp | |||
@@ -439,7 +439,15 @@ int main(int argc, char** argv) | |||
439 | 439 | ||
440 | Magick::InitializeMagick(nullptr); | 440 | Magick::InitializeMagick(nullptr); |
441 | 441 | ||
442 | YAML::Node config = YAML::LoadFile("config.yml"); | 442 | if (argc != 2) |
443 | { | ||
444 | std::cout << "usage: infinite [configfile]" << std::endl; | ||
445 | return -1; | ||
446 | } | ||
447 | |||
448 | std::string configfile(argv[1]); | ||
449 | YAML::Node config = YAML::LoadFile(configfile); | ||
450 | |||
443 | twitter::auth auth; | 451 | twitter::auth auth; |
444 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); | 452 | auth.setConsumerKey(config["consumer_key"].as<std::string>()); |
445 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | 453 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); |
@@ -451,10 +459,10 @@ int main(int argc, char** argv) | |||
451 | // Parse forms file | 459 | // Parse forms file |
452 | std::map<std::string, std::vector<std::string>> groups; | 460 | std::map<std::string, std::vector<std::string>> groups; |
453 | { | 461 | { |
454 | std::ifstream datafile("forms.txt"); | 462 | std::ifstream datafile(config["forms_file"].as<std::string>()); |
455 | if (!datafile.is_open()) | 463 | if (!datafile.is_open()) |
456 | { | 464 | { |
457 | std::cout << "Could not find forms.txt" << std::endl; | 465 | std::cout << "Could not find forms file" << std::endl; |
458 | return 1; | 466 | return 1; |
459 | } | 467 | } |
460 | 468 | ||
@@ -484,11 +492,12 @@ int main(int argc, char** argv) | |||
484 | } | 492 | } |
485 | 493 | ||
486 | // Read in fonts | 494 | // Read in fonts |
495 | std::string fontsdirname = config["fonts"].as<std::string>(); | ||
487 | std::vector<std::string> fonts; | 496 | std::vector<std::string> fonts; |
488 | { | 497 | { |
489 | DIR* fontdir; | 498 | DIR* fontdir; |
490 | struct dirent* ent; | 499 | struct dirent* ent; |
491 | if ((fontdir = opendir("fonts")) == nullptr) | 500 | if ((fontdir = opendir(fontsdirname.c_str())) == nullptr) |
492 | { | 501 | { |
493 | std::cout << "Couldn't find fonts." << std::endl; | 502 | std::cout << "Couldn't find fonts." << std::endl; |
494 | return -1; | 503 | return -1; |
@@ -506,7 +515,9 @@ int main(int argc, char** argv) | |||
506 | closedir(fontdir); | 515 | closedir(fontdir); |
507 | } | 516 | } |
508 | 517 | ||
509 | verbly::data database {"data.sqlite3"}; | 518 | std::string colorsfile(config["colors"].as<std::string>()); |
519 | |||
520 | verbly::data database {config["verbly_datafile"].as<std::string>()}; | ||
510 | 521 | ||
511 | for (;;) | 522 | for (;;) |
512 | { | 523 | { |
@@ -614,7 +625,7 @@ int main(int argc, char** argv) | |||
614 | { | 625 | { |
615 | std::cout << "Generating flame fractal..." << std::endl; | 626 | std::cout << "Generating flame fractal..." << std::endl; |
616 | 627 | ||
617 | Fractal fractal = Fractal::random(); | 628 | Fractal fractal = Fractal::random(colorsfile); |
618 | std::vector<Color> irradiance(target_w*target_h*sample_rate*sample_rate, Color(0.0, 0.0, 0.0, 0.0)); | 629 | std::vector<Color> irradiance(target_w*target_h*sample_rate*sample_rate, Color(0.0, 0.0, 0.0, 0.0)); |
619 | 630 | ||
620 | double x = (double)rand()/(double)RAND_MAX*2.0-1.0; | 631 | double x = (double)rand()/(double)RAND_MAX*2.0-1.0; |
@@ -730,7 +741,7 @@ int main(int argc, char** argv) | |||
730 | // Put text on top of the fractal | 741 | // Put text on top of the fractal |
731 | std::string subaction = action; | 742 | std::string subaction = action; |
732 | std::string font = fonts[rand() % fonts.size()]; | 743 | std::string font = fonts[rand() % fonts.size()]; |
733 | if (font == "Le_Super_Type_SemiBold.ttf") | 744 | if (font.find("Le_Super_Type_SemiBold.ttf") != std::string::npos) |
734 | { | 745 | { |
735 | std::transform(std::begin(subaction), std::end(subaction), std::begin(subaction), [] (char ch) { | 746 | std::transform(std::begin(subaction), std::end(subaction), std::begin(subaction), [] (char ch) { |
736 | return std::toupper(ch); | 747 | return std::toupper(ch); |
@@ -741,7 +752,7 @@ int main(int argc, char** argv) | |||
741 | textimage.type(Magick::TrueColorMatteType); | 752 | textimage.type(Magick::TrueColorMatteType); |
742 | textimage.fillColor(Magick::Color("white")); | 753 | textimage.fillColor(Magick::Color("white")); |
743 | textimage.fontPointsize(72.0); | 754 | textimage.fontPointsize(72.0); |
744 | textimage.font("fonts/" + font); | 755 | textimage.font(fontsdirname + "/" + font); |
745 | 756 | ||
746 | auto words = verbly::split<std::list<std::string>>(subaction, " "); | 757 | auto words = verbly::split<std::list<std::string>>(subaction, " "); |
747 | std::string towrite = ""; | 758 | std::string towrite = ""; |