#!/usr/bin/perl use strict; use warnings; use utf8; use Mojolicious::Lite -signatures; use Readonly; use List::Util qw(first); use experimental 'smartmatch'; #=== # MAKE SURE ORIGIN PAGE MATCHES FILENAME (especially if you are testing changes)! # #=== my $ORIGIN_PAGE = "/cgi-bin/wordle-life-mojo.cgi"; my $defaulttext = "Paste your wordle share here (replace this text)"; my $PATH_PARAM = "PATH_INFO"; my $WORDLE_INPUT_PARAM = "wordle-result"; my $SHARENOTE_PARAM = "share-note"; my $wordle; my $rle = ""; my $isshare = 0; #flag for sharing, default false my $sharenote = ""; #a note someone can tack onto their share get '/' => sub ($cgi) { #if there are sharing query parameters put them in $wordle and activate share page logic if (first { $_ eq $WORDLE_INPUT_PARAM } @{$cgi->req->query_params} ){ $wordle = $cgi->param($WORDLE_INPUT_PARAM); $isshare = 1; #true $sharenote = $cgi->param($SHARENOTE_PARAM); }else{ $wordle = $defaulttext; } my $template_name = 'index'; $cgi->stash( WORDLE_INPUT_PARAM => $WORDLE_INPUT_PARAM, ORIGIN_PAGE => $ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle, isshare => $isshare, sharenote => $sharenote ); $cgi->render(template => $template_name); }; get '/*path_info' => sub ($cgi) { my $template_name = $cgi->stash("path_info"); #TODO: Check against a list of valid templates! #if ( grep ( /^$template_name$/, ('index', 'about') )) { if ( $template_name ~~ ['about'] ) { $cgi->stash( ORIGIN_PAGE => $ORIGIN_PAGE); #this isn't general purpose, what template needs what variables? }else{ #TODO: fix so as not to need copied code from the else below? $template_name = 'index'; $cgi->stash( WORDLE_INPUT_PARAM => $WORDLE_INPUT_PARAM, ORIGIN_PAGE => $ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle, isshare => $isshare, sharenote => $sharenote ); } $cgi->render(template => $template_name); }; post '/' => sub($cgi) { #textarea name, pull the value from POST and reload into textarea $wordle = $cgi->param($WORDLE_INPUT_PARAM); #if input textarea not changed from default text, do nothing unless ($wordle =~ /\Q$defaulttext\E/ or $wordle eq '') { #if they put in something that looks like an RLE, pass output through, for share or to just use the life viewer if ($wordle =~ /^#[Cc] /){ $rle = $wordle; #if none of that, do the thing: generate RLE }else{ $rle = generate_rle($wordle); } } $cgi->stash( WORDLE_INPUT_PARAM => $WORDLE_INPUT_PARAM, ORIGIN_PAGE => $ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle, isshare => $isshare, sharenote => $sharenote ); $cgi->render(template =>'index'); }; app->start; sub template_from_path_info { my $template=''; my $path = shift; if ($path =~ /^\//){ $template = $path; $template =~ s/^.//; $template =~ tr/\//./; } return $template; } #Try to Generate the RLE. Makes a lot of assumptions sub generate_rle { my $headline = ""; my $rleline = ""; my $rowcount; my $myline; Readonly my $headline_prefix => "#C "; #Part of RLE spec https://conwaylife.com/wiki/Run_Length_Encoded Readonly my $row_prefix => "x = 5"; #for wordle always 5 Readonly my $col_prefix => ",y = "; Readonly my $lifeviewer_settings => "\n[[\n GPS 3\n ZOOM 23\n COLOR ALIVE LIME\n COLOR BACKGROUND MIDNIGHTBLUE\n STOP 100\n GRID\n]]"; #Part of Viewer Spec #Readonly my $lifeviewer_settings => "\n[[\n GPS 3\n ZOOM 23\n THEME INVERSE\n STOP 100\n GRID\n]]"; #Part of Viewer Spec my $wordle = shift; # this is how you get variables in your function call! $rowcount = 0; my @lines = split /^/, $wordle; foreach $myline (@lines) { chomp($myline); if ($headline eq "" && $myline =~ /Wordle/){ $headline = $headline_prefix . $myline; }else{ #remove all line endings with magic perl identifier R $myline =~ s/\R//; $myline =~ s/^(.*)$/$1\$/; #these replaces are logicless, so they need to be done in this order! #in case of text mode (Discord) $myline =~ s/:yellow_square:/o/g; $myline =~ s/:green_square:/o/g; $myline =~ s/:blue_square:/o/g; #HC equiv yellow $myline =~ s/:orange_square:/o/g; #HC equiv green $myline =~ s/:[a-z_]*square:/b/g; # for normal unicode $myline =~ s/\N{U+1f7e8}/o/g; #yellow hit $myline =~ s/\N{U+1f7e9}/o/g; #green hit $myline =~ s/\N{U+1F7E6}/o/g; #blue $myline =~ s/\N{U+1F7E7}/o/g; #orange $myline =~ s/\N{U+2B1B}/b/g; #black $myline =~ s/\N{U+2B1C}/b/g; #white #broken copy/paste text $myline =~ s/black_large_square/b/g; $myline =~ s/white_large_square/b/g; $myline =~ s/yellow_square/o/g; $myline =~ s/green_square/o/g; $myline =~ s/blue_square/o/g; $myline =~ s/orange_square/o/g; #skip blank lines, count rows added if(length($myline) > 1){ $rowcount += 1; $rleline= $rleline . $myline; } } } #this is the format with b,o, and $. Done lazily because I don't compress the repeated b or o. $rleline =~ s/\$$/\!/; #Correct termination of last line of RLE is !, not $, so replace it. return "$headline\n$row_prefix$col_prefix$rowcount\n$rleline\n$lifeviewer_settings"; } __DATA__ @@ index.html.ep Play Conway's Life with your Wordle Score

back to Site Home

Wordle->Life

about

% if ($isshare) {

Hey, someone wants to share their Wordle->Life score with you!

%if ($sharenote){

They said: <%= $sharenote =%>

%};

Skip to step 2 of the instructions below and see the shared wordle-life happen!

%}else{

Play your Wordle Share score in Conway's Life!

% };

Hey, nerds, isn't it funny how the Wordle Scores can look like a glider in that old computer programming exercise, Conway's Life?

Glider image from Conwaylife.org, it looks like an 8-bit staple gun
  1. Paste your wordle share below and submit to convert it to a Conway's Life file so you can run it (to learn more about Conway's Life, read this).


  2. Click "Submit" and an RLE format file made for Conway's Game of Life will appear in the box below and get loaded into the Life Viewer.

  3. Watch your Wordle score play LIFE!

    If the RLE is correct, it should be loaded in the Life Viewer, and so you are ready to go!

    • For best results with the Life Viewer, you may adjust the default Zoom and the playback speed, then press the Play button:

    • Press "[Pause]" when it seems stable.

This should work with the share/copy button in wordle, or copy/pasting your friends' wordles out of Discord or wherever as well. See whose Wordle Score runs the coolest!

% if ($rle ne ""){

Share your wordle-life!

You can copy/paste the RLE into your favorite social media post or email
OR
Click this button to go to a share page where you can copy/paste the URL to someone:

% };

If it doesn't seem to be working:

  1. If there is extra text or lines in your paste, you might not get a valid file in the box above, so look and make sure it looks like a proper RLE file, for example:

    #C Wordle 235 3/6
    x = 5,y = 3
    boobo$bobbo$ooooo!
    
    [[
    GPS 3
    ZOOM 23
    COLOR ALIVE LIME
    COLOR BACKGROUND BLUE
    STOP 100
    GRID
    ]]
    
    
    

    (the main thing that needs to be right are the first 3 lines. If the 3rd line has any colon : symbols, just try deleting them. The stuff between double brackets aren't part of the RLE but are comments that set some defaults for the Life Viewer)

    For details about the Life RLE file format above, read this.

  2. You can also copy the contents of the Conway Life box above and try it somewhere else:
    1. go to a Conway's Life site, such as this one at copy.sh or this one at lazyslug.com and load and run your file.
      1. specifically for the one at copy.sh:
      2. Press the [Import] button at the top
      3. paste in your Life file contents in the box and press [Import]
      4. It will put up a box telling you it loaded your Wordle, press [OK]
      5. Press the [Run] button and watch your Wordle score play LIFE!

@@ about.html.ep About Wordle-Life

Wordle->Life

This is an about page.

Click >here to return to Wordle-Life page

Click here to go to website Home


Disclaimer: I made this! People and/or corporations may own their marks or copyrights, etc, on words mentioned on these pages I don't claim to

Thanks to hankchizljaw for making his basic css publicly available

Made in February 2022, revised April 2022 for this site, using Perl Mojolicious

Hosted by Bisect Hosting

bisecthosting.com