{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Generating mini-puzzles with random.choice()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Dots-and-boxes & Connect the dots & ... ?\n", "\n", "![](https://upload.wikimedia.org/wikipedia/commons/b/b7/Dots-and-boxes-chains.png)\n", "\n", "![](https://upload.wikimedia.org/wikipedia/commons/thumb/d/d8/Connect_the_dots_puzzle_%28partially_solved%29.png/400px-Connect_the_dots_puzzle_%28partially_solved%29.png)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " . . . . . . \n", " . . . .. . \n", " . . . . . . . \n", " . . . . . . . . .. \n", " . . . . . . . . . .\n", " . . . .. . . . . . \n", " . . . . . \n", " . . . . . . \n", " . .. . . . \n", " . . . .. . . . \n", " . . . . . . . \n", ". . . . . . . . \n", " . . . . .. .. . . . \n", " . . . . . . . . . . . . . \n", " . . . . . . \n", " . ... . .. . . . . . . . . . .. \n", " . . . . . . . . . \n", " . . ... .. . .. . . . . . . \n", " . . . . .. . . ... . \n", " . . . . . . . . . . \n", " . . . . . . . .. . . . .. \n", " . . . . . . . . \n", ". . . . . . . . .. . . . . . \n", " . . . .. .\n", " . . .. . . . . . . . \n" ] } ], "source": [ "from random import choice\n", "\n", "characters = ['.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']\n", "width = 100\n", "height = 25\n", "\n", "for y in range(height):\n", " for x in range(width):\n", " print(choice(characters), end='')\n", " print('')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate a \"Connect the dots\" with jp2a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](play.jpg)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "jp2a 1.0.6\n", "Copyright (C) 2006 Christian Stigen Larsen\n", "Distributed under the GNU General Public License (GPL) v2.\n", "\n", "Usage: jp2a [ options ] [ file(s) | URL(s) ]\n", "\n", "Convert files or URLs from JPEG format to ASCII.\n", "\n", "OPTIONS\n", " - Read images from standard input.\n", " --blue=N.N Set RGB to grayscale conversion weight, default is 0.1145\n", " -b, --border Print a border around the output image.\n", " --chars=... Select character palette used to paint the image.\n", " Leftmost character corresponds to black pixel, right-\n", " most to white. Minimum two characters must be specified.\n", " --clear Clears screen before drawing each output image.\n", " --colors Use ANSI colors in output.\n", " -d, --debug Print additional debug information.\n", " --fill When used with --color and/or --html, color each character's\n", " background color.\n", " -x, --flipx Flip image in X direction.\n", " -y, --flipy Flip image in Y direction.\n", " -f, --term-fit Use the largest image dimension that fits in your terminal\n", " display with correct aspect ratio.\n", " --term-height Use terminal display height.\n", " --term-width Use terminal display width.\n", " -z, --term-zoom Use terminal display dimension for output.\n", " --grayscale Convert image to grayscale when using --html or --colors\n", " --green=N.N Set RGB to grayscale conversion weight, default is 0.5866\n", " --height=N Set output height, calculate width from aspect ratio.\n", " -h, --help Print program help.\n", " --html Produce strict XHTML 1.0 output.\n", " --html-fill Same as --fill (will be phased out)\n", " --html-fontsize=N Set fontsize to N pt, default is 4.\n", " --html-no-bold Do not use bold characters with HTML output\n", " --html-raw Output raw HTML codes, i.e. without the
section etc.\n", " --html-title=... Set HTML output title\n", " -i, --invert Invert output image. Use if your display has a dark\n", " background.\n", " --background=dark These are just mnemonics whether to use --invert\n", " --background=light or not. If your console has light characters on\n", " a dark background, use --background=dark.\n", " --output=... Write output to file.\n", " --red=N.N Set RGB to grayscale conversion weight, default 0.2989f.\n", " --size=WxH Set output width and height.\n", " -v, --verbose Verbose output.\n", " -V, --version Print program version.\n", " --width=N Set output width, calculate height from ratio.\n", "\n", " The default mode is `jp2a --term-fit --background=dark'.\n", " See the man-page for jp2a for more detailed help text.\n", "\n", "Project homepage on http://jp2a.sf.net\n", "Report bugs to