You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 KiB

Generating mini-puzzles with random.choice()

Dots-and-boxes & Connect the dots & ... ?

In [1]:
from random import choice

characters = ['.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
width = 100
height = 25

for y in range(height):
    for x in range(width):
        print(choice(characters), end='')
    print('')
             .         .     .       .                      .         .                             
     .             .              .                                    ..           .               
          .       .             .               .                     .                .          . 
      . .    .    .  .         .             .                       .              ..              
    .  .                      .     .                                   .  .    .       .        . .
  .                            .  .      ..                 .      .         . .             .      
                          .               .        .                          .                  .  
           .                                  .  . .      .                    .                    
            .   ..                    .               .  .                                          
       .  .                      .     ..   .                                            .   .      
 .            .          .                             .      .             .         .             
. .       .   .                              .        .       .                            .        
    .                   .             .  .             ..               .. .    .       .           
    .   .  . .      .                   .        .    .                     . .          .     . .  
                    .        .        .    .                     .                            .     
    .               ...      . .. .                  .         .     . .     .        .    . .   .. 
                 .      .            .   .         .         .          .            .            . 
  .   .       ...  ..     .      ..          .    .    .  .            .     .                      
         .    .                 . .  ..                       .              .       ... .          
                      .      .         .         .    .      .    .        .        .        .      
         .        .   . . .     .     .                       ..              . .     .     ..      
      .    .                                    .    .    .            . . .                        
.   .   .     . .      .       .           .         ..   .  . .               .       .            
                 .              .                     .        ..                                  .
        .           .           ..       . .   .                 .          .  .  .                 

Generate a "Connect the dots" with jp2a

In [2]:
! jp2a --help
jp2a 1.0.6
Copyright (C) 2006 Christian Stigen Larsen
Distributed under the GNU General Public License (GPL) v2.

Usage: jp2a [ options ] [ file(s) | URL(s) ]

Convert files or URLs from JPEG format to ASCII.

OPTIONS
  -                 Read images from standard input.
      --blue=N.N    Set RGB to grayscale conversion weight, default is 0.1145
  -b, --border      Print a border around the output image.
      --chars=...   Select character palette used to paint the image.
                    Leftmost character corresponds to black pixel, right-
                    most to white.  Minimum two characters must be specified.
      --clear       Clears screen before drawing each output image.
      --colors      Use ANSI colors in output.
  -d, --debug       Print additional debug information.
      --fill        When used with --color and/or --html, color each character's
                    background color.
  -x, --flipx       Flip image in X direction.
  -y, --flipy       Flip image in Y direction.
  -f, --term-fit    Use the largest image dimension that fits in your terminal
                    display with correct aspect ratio.
      --term-height Use terminal display height.
      --term-width  Use terminal display width.
  -z, --term-zoom   Use terminal display dimension for output.
      --grayscale   Convert image to grayscale when using --html or --colors
      --green=N.N   Set RGB to grayscale conversion weight, default is 0.5866
      --height=N    Set output height, calculate width from aspect ratio.
  -h, --help        Print program help.
      --html        Produce strict XHTML 1.0 output.
      --html-fill   Same as --fill (will be phased out)
      --html-fontsize=N   Set fontsize to N pt, default is 4.
      --html-no-bold      Do not use bold characters with HTML output
      --html-raw    Output raw HTML codes, i.e. without the <head> section etc.
      --html-title=...  Set HTML output title
  -i, --invert      Invert output image.  Use if your display has a dark
                    background.
      --background=dark   These are just mnemonics whether to use --invert
      --background=light  or not.  If your console has light characters on
                    a dark background, use --background=dark.
      --output=...  Write output to file.
      --red=N.N     Set RGB to grayscale conversion weight, default 0.2989f.
      --size=WxH    Set output width and height.
  -v, --verbose     Verbose output.
  -V, --version     Print program version.
      --width=N     Set output width, calculate height from ratio.

  The default mode is `jp2a --term-fit --background=dark'.
  See the man-page for jp2a for more detailed help text.

Project homepage on http://jp2a.sf.net
Report bugs to <csl@sublevel3.org>
In [3]:
! jp2a play.jpg --width=100
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMWMMMMMMM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MMcMMMMXMMMMOxMWWWNXNlKMMNXXcXMNNNMMcNWWWMNMMMMMM
MMMKXXKXXXNNXNMMMMMMMMMMX0WMMMMMMMKO0KKXNWMMMMMMMMMMMXKKKKNMMMMWKXXKXXXWMKk0NMMWONWMMMMNXKKXKWMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'''

for line in img.split("\n"):
    for letter in line:
        if letter == "M":
            img = img.replace(letter, " ")
        else:
            img = img.replace(letter, ".")
    
print(img)
                                                                                                    
                                                                                                    
                                                                                                    
      .                    ..  ...    ....                .        .        ....                    
  ......   ..................... ......  ...         ...............       ..  ..   .....   .....   
  ..   .   ..      ....    ....  ..   .....          .    ..  ...  .      ..    .....   .....   ..  
  ..   .   .. .........   ..  ....... ......         .   .... ...  .     ..  ..  ....     .   ...   
  ..   ......  ...   ..   ..       ......  ..        .   ........  ........  ...  ......     ..     
   .       ..  ..... ..   .      .......    .        .    ...  ..       ..         ..  .     .      
   .  .............. ......      ..      ...         .    .    .. ........  ..... ...  ..... .      
   ...........          ...       ........           ......    ......... ....  ....    .......      
                                                                                                    
                                                                                                    
                                                                                                    

World Wheel but different

In [5]:
from random import choice

character_set = 'gamification                                                                                 '
characters = [character for character in character_set]
width = 100
height = 25

for y in range(height):
    for x in range(width):
        print(choice(characters), end='')
    print('')
 a      a                n             i      i      i   o  a f  i     fi       i                   
                     a                  cm i                                    i  a                
      c          ti     n a     c        ii   a        n                                 n          
                   a        f           i  g   n                    a              i        i     c 
                    nt   i        c i            n                 c               o                
       a                    a             m o       m            fg        a      cm     g      m   
  i                a           i                n  ia      a     a           o  g i                t
nm   g   n  i            a       f           i      i     i   i   a    i   n     o   i  if     t    
o                    c i    a             i  gt  o    g          a  a        i             i        
                 g o  o       i                o        f  c                a  c    a      i       i
  o    g f    i                    i       a              t   c     i  an        t     a   i i  f  n
                                                         i             i           o a gm  g f i    
      i    g           f c          a a         ca  i       t               c          a   t        
               i                   a to       a n  o       n     o    c                       io    
     f        o                 f                  iam           c   i              i      a        
 g                    g        a     a    m   g       a      n          a    n           i   g      
       c         f           o      o    t               n     o                  g     n m  t    c 
  f        i  g      ng            o      m       i     i          im                               
                 a iim  a                       i     i               t  i                i       n 
       c    oa       m    a c  g    a     n                   g      ig           i   naag          
 f  i   o    a  f               o   a    a    o  t                       o                  g     m 
                  t  t i    a            i     a        a              fa        c         c  n     
     o  g m i       a        i i  n             g m m       i              f       n  i         i   
          n  g  a                                m     i i   o                  ft  i    f i       f
          t                                  m    ia           g  i         i                       

More games plz!

What other mini-games can we make?

You can restrict yourself to using ASCII characters only (see https://en.wikipedia.org/wiki/ASCII) and stay in touch with early computer graphics ASCII art...

Or you can extend your pallete with Unicode characters. This is a nice website that highlights specific character sets: http://xahlee.info/comp/unicode_index.html

In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: