diff options
Diffstat (limited to 'infinite.cpp')
-rw-r--r-- | infinite.cpp | 210 |
1 files 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 @@ | |||
15 | class fill_blanks { | 15 | class fill_blanks { |
16 | private: | 16 | private: |
17 | verbly::data& database; | 17 | verbly::data& database; |
18 | 18 | ||
19 | public: | 19 | public: |
20 | fill_blanks(verbly::data& database) : database(database) | 20 | fill_blanks(verbly::data& database) : database(database) |
21 | { | 21 | { |
22 | 22 | ||
23 | } | 23 | } |
24 | 24 | ||
25 | verbly::filter<verbly::noun> parse_selrestrs(verbly::frame::selrestr selrestr) | 25 | verbly::filter<verbly::noun> parse_selrestrs(verbly::frame::selrestr selrestr) |
26 | { | 26 | { |
27 | switch (selrestr.get_type()) | 27 | switch (selrestr.get_type()) |
@@ -30,11 +30,11 @@ class fill_blanks { | |||
30 | { | 30 | { |
31 | return verbly::filter<verbly::noun>{}; | 31 | return verbly::filter<verbly::noun>{}; |
32 | } | 32 | } |
33 | 33 | ||
34 | case verbly::frame::selrestr::type::singleton: | 34 | case verbly::frame::selrestr::type::singleton: |
35 | { | 35 | { |
36 | verbly::noun n; | 36 | verbly::noun n; |
37 | 37 | ||
38 | if (selrestr.get_restriction() == "concrete") | 38 | if (selrestr.get_restriction() == "concrete") |
39 | { | 39 | { |
40 | n = database.nouns().with_singular_form("physical entity").limit(1).run().front(); | 40 | n = database.nouns().with_singular_form("physical entity").limit(1).run().front(); |
@@ -137,10 +137,10 @@ class fill_blanks { | |||
137 | } else { | 137 | } else { |
138 | return verbly::filter<verbly::noun>{}; | 138 | return verbly::filter<verbly::noun>{}; |
139 | } | 139 | } |
140 | 140 | ||
141 | return verbly::filter<verbly::noun>{n, !selrestr.get_pos()}; | 141 | return verbly::filter<verbly::noun>{n, !selrestr.get_pos()}; |
142 | } | 142 | } |
143 | 143 | ||
144 | case verbly::frame::selrestr::type::group: | 144 | case verbly::frame::selrestr::type::group: |
145 | { | 145 | { |
146 | verbly::filter<verbly::noun> ret; | 146 | verbly::filter<verbly::noun> ret; |
@@ -149,12 +149,12 @@ class fill_blanks { | |||
149 | std::transform(std::begin(selrestr), std::end(selrestr), std::back_inserter(ret), [&] (verbly::frame::selrestr sr) { | 149 | std::transform(std::begin(selrestr), std::end(selrestr), std::back_inserter(ret), [&] (verbly::frame::selrestr sr) { |
150 | return parse_selrestrs(sr); | 150 | return parse_selrestrs(sr); |
151 | }); | 151 | }); |
152 | 152 | ||
153 | return ret; | 153 | return ret; |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | void visit(verbly::token& it) | 158 | void visit(verbly::token& it) |
159 | { | 159 | { |
160 | switch (it.get_type()) | 160 | switch (it.get_type()) |
@@ -166,20 +166,20 @@ class fill_blanks { | |||
166 | if (!tkn.is_complete()) | 166 | if (!tkn.is_complete()) |
167 | { | 167 | { |
168 | visit(tkn); | 168 | visit(tkn); |
169 | 169 | ||
170 | break; | 170 | break; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | break; | 174 | break; |
175 | } | 175 | } |
176 | 176 | ||
177 | case verbly::token::type::fillin: | 177 | case verbly::token::type::fillin: |
178 | { | 178 | { |
179 | switch (it.get_fillin_type()) | 179 | switch (it.get_fillin_type()) |
180 | { | 180 | { |
181 | case verbly::token::fillin_type::participle_phrase: | 181 | case verbly::token::fillin_type::participle_phrase: |
182 | { | 182 | { |
183 | for (;;) | 183 | for (;;) |
184 | { | 184 | { |
185 | verbly::verb v = database.verbs().has_frames().random().limit(1).run().front(); | 185 | verbly::verb v = database.verbs().has_frames().random().limit(1).run().front(); |
@@ -190,30 +190,30 @@ class fill_blanks { | |||
190 | { | 190 | { |
191 | return true; | 191 | return true; |
192 | } | 192 | } |
193 | 193 | ||
194 | if (f.parts()[0].get_type() != verbly::frame::part::type::noun_phrase) | 194 | if (f.parts()[0].get_type() != verbly::frame::part::type::noun_phrase) |
195 | { | 195 | { |
196 | return true; | 196 | return true; |
197 | } | 197 | } |
198 | 198 | ||
199 | if (f.parts()[0].get_role() != "Agent") | 199 | if (f.parts()[0].get_role() != "Agent") |
200 | { | 200 | { |
201 | return true; | 201 | return true; |
202 | } | 202 | } |
203 | 203 | ||
204 | if (f.parts()[1].get_type() != verbly::frame::part::type::verb) | 204 | if (f.parts()[1].get_type() != verbly::frame::part::type::verb) |
205 | { | 205 | { |
206 | return true; | 206 | return true; |
207 | } | 207 | } |
208 | 208 | ||
209 | return false; | 209 | return false; |
210 | }); | 210 | }); |
211 | 211 | ||
212 | if (filtered.empty()) | 212 | if (filtered.empty()) |
213 | { | 213 | { |
214 | continue; | 214 | continue; |
215 | } | 215 | } |
216 | 216 | ||
217 | verbly::frame fr = filtered[rand() % filtered.size()]; | 217 | verbly::frame fr = filtered[rand() % filtered.size()]; |
218 | verbly::token utter; | 218 | verbly::token utter; |
219 | for (auto part : fr.parts()) | 219 | for (auto part : fr.parts()) |
@@ -226,11 +226,11 @@ class fill_blanks { | |||
226 | { | 226 | { |
227 | continue; | 227 | continue; |
228 | } | 228 | } |
229 | 229 | ||
230 | if (part.get_synrestrs().count("adjp") == 1) | 230 | if (part.get_synrestrs().count("adjp") == 1) |
231 | { | 231 | { |
232 | utter << verbly::token{verbly::token::fillin_type::adjective_phrase}; | 232 | utter << verbly::token{verbly::token::fillin_type::adjective_phrase}; |
233 | 233 | ||
234 | continue; | 234 | continue; |
235 | } else if ((part.get_synrestrs().count("be_sc_ing") == 1) | 235 | } else if ((part.get_synrestrs().count("be_sc_ing") == 1) |
236 | || (part.get_synrestrs().count("ac_ing") == 1) | 236 | || (part.get_synrestrs().count("ac_ing") == 1) |
@@ -239,7 +239,7 @@ class fill_blanks { | |||
239 | || (part.get_synrestrs().count("oc_ing") == 1)) | 239 | || (part.get_synrestrs().count("oc_ing") == 1)) |
240 | { | 240 | { |
241 | utter << verbly::token{verbly::token::fillin_type::participle_phrase}; | 241 | utter << verbly::token{verbly::token::fillin_type::participle_phrase}; |
242 | 242 | ||
243 | continue; | 243 | continue; |
244 | } else if ((part.get_synrestrs().count("poss_ing") == 1) | 244 | } else if ((part.get_synrestrs().count("poss_ing") == 1) |
245 | || (part.get_synrestrs().count("possing") == 1) | 245 | || (part.get_synrestrs().count("possing") == 1) |
@@ -247,12 +247,12 @@ class fill_blanks { | |||
247 | { | 247 | { |
248 | utter << verbly::token{"their"}; | 248 | utter << verbly::token{"their"}; |
249 | utter << verbly::token{verbly::token::fillin_type::participle_phrase}; | 249 | utter << verbly::token{verbly::token::fillin_type::participle_phrase}; |
250 | 250 | ||
251 | continue; | 251 | continue; |
252 | } else if (part.get_synrestrs().count("genitive") == 1) | 252 | } else if (part.get_synrestrs().count("genitive") == 1) |
253 | { | 253 | { |
254 | utter << verbly::token{"their"}; | 254 | utter << verbly::token{"their"}; |
255 | 255 | ||
256 | continue; | 256 | continue; |
257 | } else if (part.get_synrestrs().count("adv_loc") == 1) | 257 | } else if (part.get_synrestrs().count("adv_loc") == 1) |
258 | { | 258 | { |
@@ -262,12 +262,12 @@ class fill_blanks { | |||
262 | } else { | 262 | } else { |
263 | utter << verbly::token{"there"}; | 263 | utter << verbly::token{"there"}; |
264 | } | 264 | } |
265 | 265 | ||
266 | continue; | 266 | continue; |
267 | } else if (part.get_synrestrs().count("refl") == 1) | 267 | } else if (part.get_synrestrs().count("refl") == 1) |
268 | { | 268 | { |
269 | utter << verbly::token{"themselves"}; | 269 | utter << verbly::token{"themselves"}; |
270 | 270 | ||
271 | continue; | 271 | continue; |
272 | } else if ((part.get_synrestrs().count("sc_to_inf") == 1) | 272 | } else if ((part.get_synrestrs().count("sc_to_inf") == 1) |
273 | || (part.get_synrestrs().count("ac_to_inf") == 1) | 273 | || (part.get_synrestrs().count("ac_to_inf") == 1) |
@@ -276,18 +276,18 @@ class fill_blanks { | |||
276 | || (part.get_synrestrs().count("oc_to_inf") == 1)) | 276 | || (part.get_synrestrs().count("oc_to_inf") == 1)) |
277 | { | 277 | { |
278 | utter << verbly::token{verbly::token::fillin_type::infinitive_phrase}; | 278 | utter << verbly::token{verbly::token::fillin_type::infinitive_phrase}; |
279 | 279 | ||
280 | continue; | 280 | continue; |
281 | } else if (part.get_synrestrs().count("oc_bare_inf") == 1) | 281 | } else if (part.get_synrestrs().count("oc_bare_inf") == 1) |
282 | { | 282 | { |
283 | verbly::token tkn{verbly::token::fillin_type::infinitive_phrase}; | 283 | verbly::token tkn{verbly::token::fillin_type::infinitive_phrase}; |
284 | tkn.set_extra(1); | 284 | tkn.set_extra(1); |
285 | 285 | ||
286 | utter << tkn; | 286 | utter << tkn; |
287 | 287 | ||
288 | continue; | 288 | continue; |
289 | } | 289 | } |
290 | 290 | ||
291 | auto selrestrs = fr.roles()[part.get_role()]; | 291 | auto selrestrs = fr.roles()[part.get_role()]; |
292 | auto query = database.nouns().limit(1).random().is_not_proper().full_hyponym_of(parse_selrestrs(selrestrs)); | 292 | auto query = database.nouns().limit(1).random().is_not_proper().full_hyponym_of(parse_selrestrs(selrestrs)); |
293 | verbly::noun n = query.run().front(); | 293 | verbly::noun n = query.run().front(); |
@@ -302,36 +302,36 @@ class fill_blanks { | |||
302 | utter << verbly::token{"a"}; | 302 | utter << verbly::token{"a"}; |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | if (part.get_synrestrs().count("plural") == 1) | 306 | if (part.get_synrestrs().count("plural") == 1) |
307 | { | 307 | { |
308 | utter << verbly::token{n, verbly::token::noun_inflection::plural}; | 308 | utter << verbly::token{n, verbly::token::noun_inflection::plural}; |
309 | } else { | 309 | } else { |
310 | utter << verbly::token{n}; | 310 | utter << verbly::token{n}; |
311 | } | 311 | } |
312 | 312 | ||
313 | if (part.get_synrestrs().count("acc_ing") == 1) | 313 | if (part.get_synrestrs().count("acc_ing") == 1) |
314 | { | 314 | { |
315 | utter << verbly::token{verbly::token::fillin_type::participle_phrase}; | 315 | utter << verbly::token{verbly::token::fillin_type::participle_phrase}; |
316 | } | 316 | } |
317 | 317 | ||
318 | break; | 318 | break; |
319 | } | 319 | } |
320 | 320 | ||
321 | case verbly::frame::part::type::verb: | 321 | case verbly::frame::part::type::verb: |
322 | { | 322 | { |
323 | utter << verbly::token{v, verbly::token::verb_inflection::ing_form}; | 323 | utter << verbly::token{v, verbly::token::verb_inflection::ing_form}; |
324 | 324 | ||
325 | break; | 325 | break; |
326 | } | 326 | } |
327 | 327 | ||
328 | case verbly::frame::part::type::literal_preposition: | 328 | case verbly::frame::part::type::literal_preposition: |
329 | { | 329 | { |
330 | utter << verbly::token{part.get_choices()[rand() % part.get_choices().size()]}; | 330 | utter << verbly::token{part.get_choices()[rand() % part.get_choices().size()]}; |
331 | 331 | ||
332 | break; | 332 | break; |
333 | } | 333 | } |
334 | 334 | ||
335 | case verbly::frame::part::type::selection_preposition: | 335 | case verbly::frame::part::type::selection_preposition: |
336 | { | 336 | { |
337 | auto query = database.prepositions(); | 337 | auto query = database.prepositions(); |
@@ -340,69 +340,69 @@ class fill_blanks { | |||
340 | query.in_group(preprestr); | 340 | query.in_group(preprestr); |
341 | } | 341 | } |
342 | utter << verbly::token{query.random().limit(1).run().front()}; | 342 | utter << verbly::token{query.random().limit(1).run().front()}; |
343 | 343 | ||
344 | break; | 344 | break; |
345 | } | 345 | } |
346 | 346 | ||
347 | case verbly::frame::part::type::adjective: | 347 | case verbly::frame::part::type::adjective: |
348 | { | 348 | { |
349 | utter << verbly::token{verbly::token::fillin_type::adjective_phrase}; | 349 | utter << verbly::token{verbly::token::fillin_type::adjective_phrase}; |
350 | 350 | ||
351 | break; | 351 | break; |
352 | } | 352 | } |
353 | 353 | ||
354 | case verbly::frame::part::type::adverb: | 354 | case verbly::frame::part::type::adverb: |
355 | { | 355 | { |
356 | utter << verbly::token{verbly::token::fillin_type::adverb_phrase}; | 356 | utter << verbly::token{verbly::token::fillin_type::adverb_phrase}; |
357 | 357 | ||
358 | break; | 358 | break; |
359 | } | 359 | } |
360 | 360 | ||
361 | case verbly::frame::part::type::literal: | 361 | case verbly::frame::part::type::literal: |
362 | { | 362 | { |
363 | utter << verbly::token{part.get_literal()}; | 363 | utter << verbly::token{part.get_literal()}; |
364 | 364 | ||
365 | break; | 365 | break; |
366 | } | 366 | } |
367 | } | 367 | } |
368 | } | 368 | } |
369 | 369 | ||
370 | it = utter; | 370 | it = utter; |
371 | 371 | ||
372 | break; | 372 | break; |
373 | } | 373 | } |
374 | 374 | ||
375 | break; | 375 | break; |
376 | } | 376 | } |
377 | 377 | ||
378 | case verbly::token::fillin_type::adjective_phrase: | 378 | case verbly::token::fillin_type::adjective_phrase: |
379 | { | 379 | { |
380 | verbly::token phrase; | 380 | verbly::token phrase; |
381 | 381 | ||
382 | if (rand() % 4 == 0) | 382 | if (rand() % 4 == 0) |
383 | { | 383 | { |
384 | phrase << verbly::token{verbly::token::fillin_type::adverb_phrase}; | 384 | phrase << verbly::token{verbly::token::fillin_type::adverb_phrase}; |
385 | } | 385 | } |
386 | 386 | ||
387 | if (rand() % 2 == 0) | 387 | if (rand() % 2 == 0) |
388 | { | 388 | { |
389 | phrase << verbly::token{verbly::token::fillin_type::participle_phrase}; | 389 | phrase << verbly::token{verbly::token::fillin_type::participle_phrase}; |
390 | } else { | 390 | } else { |
391 | phrase << verbly::token{database.adjectives().random().limit(1).run().front()}; | 391 | phrase << verbly::token{database.adjectives().random().limit(1).run().front()}; |
392 | } | 392 | } |
393 | 393 | ||
394 | it = phrase; | 394 | it = phrase; |
395 | 395 | ||
396 | break; | 396 | break; |
397 | } | 397 | } |
398 | 398 | ||
399 | case verbly::token::fillin_type::adverb_phrase: | 399 | case verbly::token::fillin_type::adverb_phrase: |
400 | { | 400 | { |
401 | it = verbly::token{database.adverbs().random().limit(1).run().front()}; | 401 | it = verbly::token{database.adverbs().random().limit(1).run().front()}; |
402 | 402 | ||
403 | break; | 403 | break; |
404 | } | 404 | } |
405 | 405 | ||
406 | case verbly::token::fillin_type::infinitive_phrase: | 406 | case verbly::token::fillin_type::infinitive_phrase: |
407 | { | 407 | { |
408 | verbly::token utter; | 408 | verbly::token utter; |
@@ -410,22 +410,22 @@ class fill_blanks { | |||
410 | { | 410 | { |
411 | utter << verbly::token{"to"}; | 411 | utter << verbly::token{"to"}; |
412 | } | 412 | } |
413 | 413 | ||
414 | utter << verbly::token{database.verbs().random().limit(1).run().front()}; | 414 | utter << verbly::token{database.verbs().random().limit(1).run().front()}; |
415 | 415 | ||
416 | it = utter; | 416 | it = utter; |
417 | 417 | ||
418 | break; | 418 | break; |
419 | } | 419 | } |
420 | 420 | ||
421 | default: | 421 | default: |
422 | { | 422 | { |
423 | it = verbly::token{"*the reality of the situation*"}; | 423 | it = verbly::token{"*the reality of the situation*"}; |
424 | 424 | ||
425 | break; | 425 | break; |
426 | } | 426 | } |
427 | } | 427 | } |
428 | 428 | ||
429 | break; | 429 | break; |
430 | } | 430 | } |
431 | } | 431 | } |
@@ -436,9 +436,9 @@ int main(int argc, char** argv) | |||
436 | { | 436 | { |
437 | srand(time(NULL)); | 437 | srand(time(NULL)); |
438 | rand(); rand(); rand(); rand(); | 438 | rand(); rand(); rand(); rand(); |
439 | 439 | ||
440 | Magick::InitializeMagick(nullptr); | 440 | Magick::InitializeMagick(nullptr); |
441 | 441 | ||
442 | if (argc != 2) | 442 | if (argc != 2) |
443 | { | 443 | { |
444 | std::cout << "usage: infinite [configfile]" << std::endl; | 444 | std::cout << "usage: infinite [configfile]" << std::endl; |
@@ -453,9 +453,9 @@ int main(int argc, char** argv) | |||
453 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); | 453 | auth.setConsumerSecret(config["consumer_secret"].as<std::string>()); |
454 | auth.setAccessKey(config["access_key"].as<std::string>()); | 454 | auth.setAccessKey(config["access_key"].as<std::string>()); |
455 | auth.setAccessSecret(config["access_secret"].as<std::string>()); | 455 | auth.setAccessSecret(config["access_secret"].as<std::string>()); |
456 | 456 | ||
457 | twitter::client client(auth); | 457 | twitter::client client(auth); |
458 | 458 | ||
459 | // Parse forms file | 459 | // Parse forms file |
460 | std::map<std::string, std::vector<std::string>> groups; | 460 | std::map<std::string, std::vector<std::string>> groups; |
461 | { | 461 | { |
@@ -475,7 +475,7 @@ int main(int argc, char** argv) | |||
475 | { | 475 | { |
476 | line.pop_back(); | 476 | line.pop_back(); |
477 | } | 477 | } |
478 | 478 | ||
479 | if (newgroup) | 479 | if (newgroup) |
480 | { | 480 | { |
481 | curgroup = line; | 481 | curgroup = line; |
@@ -490,7 +490,7 @@ int main(int argc, char** argv) | |||
490 | } | 490 | } |
491 | } | 491 | } |
492 | } | 492 | } |
493 | 493 | ||
494 | // Read in fonts | 494 | // Read in fonts |
495 | std::string fontsdirname = config["fonts"].as<std::string>(); | 495 | std::string fontsdirname = config["fonts"].as<std::string>(); |
496 | std::vector<std::string> fonts; | 496 | std::vector<std::string> fonts; |
@@ -518,23 +518,23 @@ int main(int argc, char** argv) | |||
518 | std::string colorsfile(config["colors"].as<std::string>()); | 518 | std::string colorsfile(config["colors"].as<std::string>()); |
519 | 519 | ||
520 | verbly::data database {config["verbly_datafile"].as<std::string>()}; | 520 | verbly::data database {config["verbly_datafile"].as<std::string>()}; |
521 | 521 | ||
522 | for (;;) | 522 | for (;;) |
523 | { | 523 | { |
524 | // Generate the text | 524 | // Generate the text |
525 | std::cout << "Generating text..." << std::endl; | 525 | std::cout << "Generating text..." << std::endl; |
526 | 526 | ||
527 | std::string action = "{FORM}"; | 527 | std::string action = "{FORM}"; |
528 | int tknloc; | 528 | int tknloc; |
529 | while ((tknloc = action.find("{")) != std::string::npos) | 529 | while ((tknloc = action.find("{")) != std::string::npos) |
530 | { | 530 | { |
531 | std::string token = action.substr(tknloc+1, action.find("}")-tknloc-1); | 531 | std::string token = action.substr(tknloc+1, action.find("}")-tknloc-1); |
532 | 532 | ||
533 | std::string canontkn; | 533 | std::string canontkn; |
534 | std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) { | 534 | std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) { |
535 | return std::toupper(ch); | 535 | return std::toupper(ch); |
536 | }); | 536 | }); |
537 | 537 | ||
538 | std::string result; | 538 | std::string result; |
539 | if (canontkn == "NOUN") | 539 | if (canontkn == "NOUN") |
540 | { | 540 | { |
@@ -560,7 +560,7 @@ int main(int argc, char** argv) | |||
560 | auto hem2 = database.nouns().with_singular_form("western hemisphere").limit(1).run().front(); | 560 | auto hem2 = database.nouns().with_singular_form("western hemisphere").limit(1).run().front(); |
561 | verbly::filter<verbly::noun> region{hem1, hem2}; | 561 | verbly::filter<verbly::noun> region{hem1, hem2}; |
562 | region.set_orlogic(true); | 562 | region.set_orlogic(true); |
563 | 563 | ||
564 | result = database.nouns().full_part_holonym_of(region).random().limit(1).run().front().singular_form(); | 564 | result = database.nouns().full_part_holonym_of(region).random().limit(1).run().front().singular_form(); |
565 | } else if (canontkn == "LANGUAGE") | 565 | } else if (canontkn == "LANGUAGE") |
566 | { | 566 | { |
@@ -586,7 +586,7 @@ int main(int argc, char** argv) | |||
586 | result = group[rand() % group.size()]; | 586 | result = group[rand() % group.size()]; |
587 | std::cout << canontkn << ": " << group.size() << std::endl; | 587 | std::cout << canontkn << ": " << group.size() << std::endl; |
588 | } | 588 | } |
589 | 589 | ||
590 | std::string finalresult; | 590 | std::string finalresult; |
591 | if (islower(token[0])) | 591 | if (islower(token[0])) |
592 | { | 592 | { |
@@ -600,12 +600,12 @@ int main(int argc, char** argv) | |||
600 | { | 600 | { |
601 | word[0] = std::toupper(word[0]); | 601 | word[0] = std::toupper(word[0]); |
602 | } | 602 | } |
603 | 603 | ||
604 | finalresult = verbly::implode(std::begin(words), std::end(words), " "); | 604 | finalresult = verbly::implode(std::begin(words), std::end(words), " "); |
605 | } else { | 605 | } else { |
606 | finalresult = result; | 606 | finalresult = result; |
607 | } | 607 | } |
608 | 608 | ||
609 | action.replace(tknloc, action.find("}")-tknloc+1, finalresult); | 609 | action.replace(tknloc, action.find("}")-tknloc+1, finalresult); |
610 | } | 610 | } |
611 | 611 | ||
@@ -616,32 +616,32 @@ int main(int argc, char** argv) | |||
616 | double target_w = 1280; | 616 | double target_w = 1280; |
617 | double target_h = 800; | 617 | double target_h = 800; |
618 | double sample_rate = 3; | 618 | double sample_rate = 3; |
619 | 619 | ||
620 | Magick::Image image(Magick::Geometry(target_w, target_h), "black"); | 620 | Magick::Image image(Magick::Geometry(target_w, target_h), "black"); |
621 | image.type(Magick::TrueColorMatteType); | 621 | image.type(Magick::TrueColorMatteType); |
622 | 622 | ||
623 | double coverage = 0.0; | 623 | double coverage = 0.0; |
624 | while (coverage < 0.05) | 624 | while (coverage < 0.05) |
625 | { | 625 | { |
626 | std::cout << "Generating flame fractal..." << std::endl; | 626 | std::cout << "Generating flame fractal..." << std::endl; |
627 | 627 | ||
628 | Fractal fractal = Fractal::random(colorsfile); | 628 | Fractal fractal = Fractal::random(colorsfile); |
629 | 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)); |
630 | 630 | ||
631 | double x = (double)rand()/(double)RAND_MAX*2.0-1.0; | 631 | double x = (double)rand()/(double)RAND_MAX*2.0-1.0; |
632 | double y = (double)rand()/(double)RAND_MAX*2.0-1.0; | 632 | double y = (double)rand()/(double)RAND_MAX*2.0-1.0; |
633 | double c = (double)rand()/RAND_MAX; | 633 | double c = (double)rand()/RAND_MAX; |
634 | 634 | ||
635 | double widthmul = fractal.width/target_w*zoom; | 635 | double widthmul = fractal.width/target_w*zoom; |
636 | double heightmul = fractal.height/target_w*zoom; | 636 | double heightmul = fractal.height/target_w*zoom; |
637 | double widthmul2 = widthmul * 2.0; | 637 | double widthmul2 = widthmul * 2.0; |
638 | double heightmul2 = heightmul * 2.0; | 638 | double heightmul2 = heightmul * 2.0; |
639 | 639 | ||
640 | int maxrad = 0; | 640 | int maxrad = 0; |
641 | for (int i=0; i<50000000; i++) | 641 | for (int i=0; i<50000000; i++) |
642 | { | 642 | { |
643 | fractal.sample(x, y, c); | 643 | fractal.sample(x, y, c); |
644 | 644 | ||
645 | int fx = (x+widthmul)/widthmul2*target_w*sample_rate; | 645 | int fx = (x+widthmul)/widthmul2*target_w*sample_rate; |
646 | int fy = (y+heightmul)/heightmul2*target_h*sample_rate; | 646 | int fy = (y+heightmul)/heightmul2*target_h*sample_rate; |
647 | 647 | ||
@@ -652,14 +652,14 @@ int main(int argc, char** argv) | |||
652 | double alph = irr.a; | 652 | double alph = irr.a; |
653 | irr *= 0.5; | 653 | irr *= 0.5; |
654 | irr.a = alph; | 654 | irr.a = alph; |
655 | 655 | ||
656 | if (irr.a > maxrad) | 656 | if (irr.a > maxrad) |
657 | { | 657 | { |
658 | maxrad = irr.a; | 658 | maxrad = irr.a; |
659 | } | 659 | } |
660 | } | 660 | } |
661 | } | 661 | } |
662 | 662 | ||
663 | image.modifyImage(); | 663 | image.modifyImage(); |
664 | Magick::Pixels view(image); | 664 | Magick::Pixels view(image); |
665 | Magick::PixelPacket* pixels = view.get(0, 0, target_w, target_h); | 665 | Magick::PixelPacket* pixels = view.get(0, 0, target_w, target_h); |
@@ -692,15 +692,15 @@ int main(int argc, char** argv) | |||
692 | } | 692 | } |
693 | } | 693 | } |
694 | } | 694 | } |
695 | 695 | ||
696 | if (freq_max > 0) | 696 | if (freq_max > 0) |
697 | { | 697 | { |
698 | covered++; | 698 | covered++; |
699 | } | 699 | } |
700 | 700 | ||
701 | freq_avg *= (white * fractal.filterlevel)/(sample_rate * sample_rate); | 701 | freq_avg *= (white * fractal.filterlevel)/(sample_rate * sample_rate); |
702 | color_avg *= (fractal.filterlevel/(sample_rate*sample_rate)); | 702 | color_avg *= (fractal.filterlevel/(sample_rate*sample_rate)); |
703 | 703 | ||
704 | double alph = k1 * std::log(1+white*freq_avg*k2)/(std::log(10*white*freq_max)); | 704 | double alph = k1 * std::log(1+white*freq_avg*k2)/(std::log(10*white*freq_max)); |
705 | double alphg = pow(alph, 1.0/fractal.gamma); | 705 | double alphg = pow(alph, 1.0/fractal.gamma); |
706 | if (alph <= fractal.gammathresh) | 706 | if (alph <= fractal.gammathresh) |
@@ -708,36 +708,36 @@ int main(int argc, char** argv) | |||
708 | double frac = alph / fractal.gammathresh; | 708 | double frac = alph / fractal.gammathresh; |
709 | alphg = (1-frac)*alph*pow(fractal.gammathresh, 1.0/fractal.gamma - 1.0) + frac*alphg; | 709 | alphg = (1-frac)*alph*pow(fractal.gammathresh, 1.0/fractal.gamma - 1.0) + frac*alphg; |
710 | } | 710 | } |
711 | 711 | ||
712 | double ls = vibrancy*alphg/alph; | 712 | double ls = vibrancy*alphg/alph; |
713 | Color finc = color_avg * ls; | 713 | Color finc = color_avg * ls; |
714 | finc.a = 1.0; | 714 | finc.a = 1.0; |
715 | 715 | ||
716 | if (finc.r > 1.0) | 716 | if (finc.r > 1.0) |
717 | { | 717 | { |
718 | finc *= (1.0 / finc.r); | 718 | finc *= (1.0 / finc.r); |
719 | } | 719 | } |
720 | 720 | ||
721 | if (finc.g > 1.0) | 721 | if (finc.g > 1.0) |
722 | { | 722 | { |
723 | finc *= (1.0 / finc.g); | 723 | finc *= (1.0 / finc.g); |
724 | } | 724 | } |
725 | 725 | ||
726 | if (finc.b > 1.0) | 726 | if (finc.b > 1.0) |
727 | { | 727 | { |
728 | finc *= (1.0 / finc.b); | 728 | finc *= (1.0 / finc.b); |
729 | } | 729 | } |
730 | 730 | ||
731 | *pixels++ = Magick::ColorRGB(finc.r, finc.g, finc.b); | 731 | *pixels++ = Magick::ColorRGB(finc.r, finc.g, finc.b); |
732 | } | 732 | } |
733 | } | 733 | } |
734 | 734 | ||
735 | coverage = ((double)covered/(double)(target_w*target_h)); | 735 | coverage = ((double)covered/(double)(target_w*target_h)); |
736 | std::cout << coverage << " coverage" << std::endl; | 736 | std::cout << coverage << " coverage" << std::endl; |
737 | 737 | ||
738 | view.sync(); | 738 | view.sync(); |
739 | } | 739 | } |
740 | 740 | ||
741 | // Put text on top of the fractal | 741 | // Put text on top of the fractal |
742 | std::string subaction = action; | 742 | std::string subaction = action; |
743 | std::string font = fonts[rand() % fonts.size()]; | 743 | std::string font = fonts[rand() % fonts.size()]; |
@@ -747,13 +747,13 @@ int main(int argc, char** argv) | |||
747 | return std::toupper(ch); | 747 | return std::toupper(ch); |
748 | }); | 748 | }); |
749 | } | 749 | } |
750 | 750 | ||
751 | Magick::Image textimage(Magick::Geometry(target_w, target_h), "transparent"); | 751 | Magick::Image textimage(Magick::Geometry(target_w, target_h), "transparent"); |
752 | textimage.type(Magick::TrueColorMatteType); | 752 | textimage.type(Magick::TrueColorMatteType); |
753 | textimage.fillColor(Magick::Color("white")); | 753 | textimage.fillColor(Magick::Color("white")); |
754 | textimage.fontPointsize(72.0); | 754 | textimage.fontPointsize(72.0); |
755 | textimage.font(fontsdirname + "/" + font); | 755 | textimage.font(fontsdirname + "/" + font); |
756 | 756 | ||
757 | auto words = verbly::split<std::list<std::string>>(subaction, " "); | 757 | auto words = verbly::split<std::list<std::string>>(subaction, " "); |
758 | std::string towrite = ""; | 758 | std::string towrite = ""; |
759 | std::string curline = ""; | 759 | std::string curline = ""; |
@@ -770,21 +770,21 @@ int main(int argc, char** argv) | |||
770 | towrite += " " + words.front(); | 770 | towrite += " " + words.front(); |
771 | curline = temp; | 771 | curline = temp; |
772 | } | 772 | } |
773 | 773 | ||
774 | words.pop_front(); | 774 | words.pop_front(); |
775 | } | 775 | } |
776 | 776 | ||
777 | textimage.annotate(towrite, Magick::CenterGravity); | 777 | textimage.annotate(towrite, Magick::CenterGravity); |
778 | textimage.opacity(((double)MaxRGB) * 0.8); | 778 | textimage.opacity(((double)MaxRGB) * 0.8); |
779 | image.composite(textimage, 0, 0, Magick::OverCompositeOp); | 779 | image.composite(textimage, 0, 0, Magick::OverCompositeOp); |
780 | 780 | ||
781 | image.magick("jpg"); | 781 | image.magick("jpg"); |
782 | 782 | ||
783 | Magick::Blob outputimg; | 783 | Magick::Blob outputimg; |
784 | image.write(&outputimg); | 784 | image.write(&outputimg); |
785 | 785 | ||
786 | std::cout << "Generated image!" << std::endl << "Tweeting..." << std::endl; | 786 | std::cout << "Generated image!" << std::endl << "Tweeting..." << std::endl; |
787 | 787 | ||
788 | std::string tweetText; | 788 | std::string tweetText; |
789 | size_t tweetLim = 140 - client.getConfiguration().getCharactersReservedPerMedia() - client.getUser().getScreenName().length() - 6; | 789 | size_t tweetLim = 140 - client.getConfiguration().getCharactersReservedPerMedia() - client.getUser().getScreenName().length() - 6; |
790 | if (action.length() > tweetLim) | 790 | if (action.length() > tweetLim) |
@@ -793,12 +793,12 @@ int main(int argc, char** argv) | |||
793 | } else { | 793 | } else { |
794 | tweetText = "\"" + action + "\" --@" + client.getUser().getScreenName(); | 794 | tweetText = "\"" + action + "\" --@" + client.getUser().getScreenName(); |
795 | } | 795 | } |
796 | 796 | ||
797 | try | 797 | try |
798 | { | 798 | { |
799 | long media_id = client.uploadMedia("image/jpeg", (const char*) outputimg.data(), outputimg.length()); | 799 | long media_id = client.uploadMedia("image/jpeg", (const char*) outputimg.data(), outputimg.length()); |
800 | client.updateStatus(tweetText, {media_id}); | 800 | client.updateStatus(tweetText, {media_id}); |
801 | 801 | ||
802 | std::cout << "Done!" << std::endl << "Waiting..." << std::endl << std::endl; | 802 | std::cout << "Done!" << std::endl << "Waiting..." << std::endl << std::endl; |
803 | } catch (const twitter::twitter_error& e) | 803 | } catch (const twitter::twitter_error& e) |
804 | { | 804 | { |