From 3bc878e63d709bbe41307c154c7ca4aee9486237 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 13 Mar 2018 16:58:07 -0400 Subject: Whitespace changes --- infinite.cpp | 210 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/infinite.cpp b/infinite.cpp index 1409ba2..37c4d72 100644 --- a/infinite.cpp +++ b/infinite.cpp @@ -15,13 +15,13 @@ class fill_blanks { private: verbly::data& database; - + public: fill_blanks(verbly::data& database) : database(database) { - + } - + verbly::filter parse_selrestrs(verbly::frame::selrestr selrestr) { switch (selrestr.get_type()) @@ -30,11 +30,11 @@ class fill_blanks { { return verbly::filter{}; } - + case verbly::frame::selrestr::type::singleton: { verbly::noun n; - + if (selrestr.get_restriction() == "concrete") { n = database.nouns().with_singular_form("physical entity").limit(1).run().front(); @@ -137,10 +137,10 @@ class fill_blanks { } else { return verbly::filter{}; } - + return verbly::filter{n, !selrestr.get_pos()}; } - + case verbly::frame::selrestr::type::group: { verbly::filter ret; @@ -149,12 +149,12 @@ class fill_blanks { std::transform(std::begin(selrestr), std::end(selrestr), std::back_inserter(ret), [&] (verbly::frame::selrestr sr) { return parse_selrestrs(sr); }); - + return ret; } } } - + void visit(verbly::token& it) { switch (it.get_type()) @@ -166,20 +166,20 @@ class fill_blanks { if (!tkn.is_complete()) { visit(tkn); - + break; } } - + break; } - + case verbly::token::type::fillin: { switch (it.get_fillin_type()) { case verbly::token::fillin_type::participle_phrase: - { + { for (;;) { verbly::verb v = database.verbs().has_frames().random().limit(1).run().front(); @@ -190,30 +190,30 @@ class fill_blanks { { return true; } - + if (f.parts()[0].get_type() != verbly::frame::part::type::noun_phrase) { return true; } - + if (f.parts()[0].get_role() != "Agent") { return true; } - + if (f.parts()[1].get_type() != verbly::frame::part::type::verb) { return true; } - + return false; }); - + if (filtered.empty()) { continue; } - + verbly::frame fr = filtered[rand() % filtered.size()]; verbly::token utter; for (auto part : fr.parts()) @@ -226,11 +226,11 @@ class fill_blanks { { continue; } - + if (part.get_synrestrs().count("adjp") == 1) { utter << verbly::token{verbly::token::fillin_type::adjective_phrase}; - + continue; } else if ((part.get_synrestrs().count("be_sc_ing") == 1) || (part.get_synrestrs().count("ac_ing") == 1) @@ -239,7 +239,7 @@ class fill_blanks { || (part.get_synrestrs().count("oc_ing") == 1)) { utter << verbly::token{verbly::token::fillin_type::participle_phrase}; - + continue; } else if ((part.get_synrestrs().count("poss_ing") == 1) || (part.get_synrestrs().count("possing") == 1) @@ -247,12 +247,12 @@ class fill_blanks { { utter << verbly::token{"their"}; utter << verbly::token{verbly::token::fillin_type::participle_phrase}; - + continue; } else if (part.get_synrestrs().count("genitive") == 1) { utter << verbly::token{"their"}; - + continue; } else if (part.get_synrestrs().count("adv_loc") == 1) { @@ -262,12 +262,12 @@ class fill_blanks { } else { utter << verbly::token{"there"}; } - + continue; } else if (part.get_synrestrs().count("refl") == 1) { utter << verbly::token{"themselves"}; - + continue; } else if ((part.get_synrestrs().count("sc_to_inf") == 1) || (part.get_synrestrs().count("ac_to_inf") == 1) @@ -276,18 +276,18 @@ class fill_blanks { || (part.get_synrestrs().count("oc_to_inf") == 1)) { utter << verbly::token{verbly::token::fillin_type::infinitive_phrase}; - + continue; } else if (part.get_synrestrs().count("oc_bare_inf") == 1) { verbly::token tkn{verbly::token::fillin_type::infinitive_phrase}; tkn.set_extra(1); - + utter << tkn; - + continue; } - + auto selrestrs = fr.roles()[part.get_role()]; auto query = database.nouns().limit(1).random().is_not_proper().full_hyponym_of(parse_selrestrs(selrestrs)); verbly::noun n = query.run().front(); @@ -302,36 +302,36 @@ class fill_blanks { utter << verbly::token{"a"}; } } - + if (part.get_synrestrs().count("plural") == 1) { utter << verbly::token{n, verbly::token::noun_inflection::plural}; } else { utter << verbly::token{n}; } - + if (part.get_synrestrs().count("acc_ing") == 1) { utter << verbly::token{verbly::token::fillin_type::participle_phrase}; } - + break; } - + case verbly::frame::part::type::verb: { utter << verbly::token{v, verbly::token::verb_inflection::ing_form}; - + break; } - + case verbly::frame::part::type::literal_preposition: { utter << verbly::token{part.get_choices()[rand() % part.get_choices().size()]}; - + break; } - + case verbly::frame::part::type::selection_preposition: { auto query = database.prepositions(); @@ -340,69 +340,69 @@ class fill_blanks { query.in_group(preprestr); } utter << verbly::token{query.random().limit(1).run().front()}; - + break; } - + case verbly::frame::part::type::adjective: { utter << verbly::token{verbly::token::fillin_type::adjective_phrase}; - + break; } - + case verbly::frame::part::type::adverb: { utter << verbly::token{verbly::token::fillin_type::adverb_phrase}; - + break; } - + case verbly::frame::part::type::literal: { utter << verbly::token{part.get_literal()}; - + break; } } } - + it = utter; - + break; } - + break; } - + case verbly::token::fillin_type::adjective_phrase: { verbly::token phrase; - + if (rand() % 4 == 0) { phrase << verbly::token{verbly::token::fillin_type::adverb_phrase}; } - + if (rand() % 2 == 0) { phrase << verbly::token{verbly::token::fillin_type::participle_phrase}; } else { phrase << verbly::token{database.adjectives().random().limit(1).run().front()}; } - + it = phrase; - + break; } - + case verbly::token::fillin_type::adverb_phrase: { it = verbly::token{database.adverbs().random().limit(1).run().front()}; - + break; } - + case verbly::token::fillin_type::infinitive_phrase: { verbly::token utter; @@ -410,22 +410,22 @@ class fill_blanks { { utter << verbly::token{"to"}; } - + utter << verbly::token{database.verbs().random().limit(1).run().front()}; - + it = utter; - + break; } default: { it = verbly::token{"*the reality of the situation*"}; - + break; } } - + break; } } @@ -436,9 +436,9 @@ int main(int argc, char** argv) { srand(time(NULL)); rand(); rand(); rand(); rand(); - + Magick::InitializeMagick(nullptr); - + if (argc != 2) { std::cout << "usage: infinite [configfile]" << std::endl; @@ -453,9 +453,9 @@ int main(int argc, char** argv) auth.setConsumerSecret(config["consumer_secret"].as()); auth.setAccessKey(config["access_key"].as()); auth.setAccessSecret(config["access_secret"].as()); - + twitter::client client(auth); - + // Parse forms file std::map> groups; { @@ -475,7 +475,7 @@ int main(int argc, char** argv) { line.pop_back(); } - + if (newgroup) { curgroup = line; @@ -490,7 +490,7 @@ int main(int argc, char** argv) } } } - + // Read in fonts std::string fontsdirname = config["fonts"].as(); std::vector fonts; @@ -518,23 +518,23 @@ int main(int argc, char** argv) std::string colorsfile(config["colors"].as()); verbly::data database {config["verbly_datafile"].as()}; - + for (;;) { // Generate the text std::cout << "Generating text..." << std::endl; - + std::string action = "{FORM}"; int tknloc; while ((tknloc = action.find("{")) != std::string::npos) { std::string token = action.substr(tknloc+1, action.find("}")-tknloc-1); - + std::string canontkn; std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) { return std::toupper(ch); }); - + std::string result; if (canontkn == "NOUN") { @@ -560,7 +560,7 @@ int main(int argc, char** argv) auto hem2 = database.nouns().with_singular_form("western hemisphere").limit(1).run().front(); verbly::filter region{hem1, hem2}; region.set_orlogic(true); - + result = database.nouns().full_part_holonym_of(region).random().limit(1).run().front().singular_form(); } else if (canontkn == "LANGUAGE") { @@ -586,7 +586,7 @@ int main(int argc, char** argv) result = group[rand() % group.size()]; std::cout << canontkn << ": " << group.size() << std::endl; } - + std::string finalresult; if (islower(token[0])) { @@ -600,12 +600,12 @@ int main(int argc, char** argv) { word[0] = std::toupper(word[0]); } - + finalresult = verbly::implode(std::begin(words), std::end(words), " "); } else { finalresult = result; } - + action.replace(tknloc, action.find("}")-tknloc+1, finalresult); } @@ -616,32 +616,32 @@ int main(int argc, char** argv) double target_w = 1280; double target_h = 800; double sample_rate = 3; - + Magick::Image image(Magick::Geometry(target_w, target_h), "black"); image.type(Magick::TrueColorMatteType); - + double coverage = 0.0; while (coverage < 0.05) { std::cout << "Generating flame fractal..." << std::endl; - + Fractal fractal = Fractal::random(colorsfile); std::vector irradiance(target_w*target_h*sample_rate*sample_rate, Color(0.0, 0.0, 0.0, 0.0)); double x = (double)rand()/(double)RAND_MAX*2.0-1.0; - double y = (double)rand()/(double)RAND_MAX*2.0-1.0; + double y = (double)rand()/(double)RAND_MAX*2.0-1.0; double c = (double)rand()/RAND_MAX; - + double widthmul = fractal.width/target_w*zoom; double heightmul = fractal.height/target_w*zoom; double widthmul2 = widthmul * 2.0; double heightmul2 = heightmul * 2.0; - + int maxrad = 0; for (int i=0; i<50000000; i++) { fractal.sample(x, y, c); - + int fx = (x+widthmul)/widthmul2*target_w*sample_rate; int fy = (y+heightmul)/heightmul2*target_h*sample_rate; @@ -652,14 +652,14 @@ int main(int argc, char** argv) double alph = irr.a; irr *= 0.5; irr.a = alph; - + if (irr.a > maxrad) { maxrad = irr.a; } } } - + image.modifyImage(); Magick::Pixels view(image); Magick::PixelPacket* pixels = view.get(0, 0, target_w, target_h); @@ -692,15 +692,15 @@ int main(int argc, char** argv) } } } - + if (freq_max > 0) { covered++; } - + freq_avg *= (white * fractal.filterlevel)/(sample_rate * sample_rate); color_avg *= (fractal.filterlevel/(sample_rate*sample_rate)); - + double alph = k1 * std::log(1+white*freq_avg*k2)/(std::log(10*white*freq_max)); double alphg = pow(alph, 1.0/fractal.gamma); if (alph <= fractal.gammathresh) @@ -708,36 +708,36 @@ int main(int argc, char** argv) double frac = alph / fractal.gammathresh; alphg = (1-frac)*alph*pow(fractal.gammathresh, 1.0/fractal.gamma - 1.0) + frac*alphg; } - + double ls = vibrancy*alphg/alph; Color finc = color_avg * ls; finc.a = 1.0; - + if (finc.r > 1.0) { finc *= (1.0 / finc.r); } - + if (finc.g > 1.0) { finc *= (1.0 / finc.g); } - + if (finc.b > 1.0) { finc *= (1.0 / finc.b); } - + *pixels++ = Magick::ColorRGB(finc.r, finc.g, finc.b); } } - + coverage = ((double)covered/(double)(target_w*target_h)); std::cout << coverage << " coverage" << std::endl; - + view.sync(); } - + // Put text on top of the fractal std::string subaction = action; std::string font = fonts[rand() % fonts.size()]; @@ -747,13 +747,13 @@ int main(int argc, char** argv) return std::toupper(ch); }); } - + Magick::Image textimage(Magick::Geometry(target_w, target_h), "transparent"); textimage.type(Magick::TrueColorMatteType); textimage.fillColor(Magick::Color("white")); textimage.fontPointsize(72.0); textimage.font(fontsdirname + "/" + font); - + auto words = verbly::split>(subaction, " "); std::string towrite = ""; std::string curline = ""; @@ -770,21 +770,21 @@ int main(int argc, char** argv) towrite += " " + words.front(); curline = temp; } - + words.pop_front(); } - + textimage.annotate(towrite, Magick::CenterGravity); textimage.opacity(((double)MaxRGB) * 0.8); image.composite(textimage, 0, 0, Magick::OverCompositeOp); - + image.magick("jpg"); - + Magick::Blob outputimg; image.write(&outputimg); - + std::cout << "Generated image!" << std::endl << "Tweeting..." << std::endl; - + std::string tweetText; size_t tweetLim = 140 - client.getConfiguration().getCharactersReservedPerMedia() - client.getUser().getScreenName().length() - 6; if (action.length() > tweetLim) @@ -793,12 +793,12 @@ int main(int argc, char** argv) } else { tweetText = "\"" + action + "\" --@" + client.getUser().getScreenName(); } - + try { long media_id = client.uploadMedia("image/jpeg", (const char*) outputimg.data(), outputimg.length()); client.updateStatus(tweetText, {media_id}); - + std::cout << "Done!" << std::endl << "Waiting..." << std::endl << std::endl; } catch (const twitter::twitter_error& e) { -- cgit 1.4.1