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.

369 lines
18 KiB
Plaintext

{
"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 <head> 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 <csl@sublevel3.org>\n"
]
}
],
"source": [
"! jp2a --help"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMWMMMMMMMMMMMMMMMMMMMMWNMMNNWMMMMNWNNMMMMMMMMMMMMMMMMWMMMMMMMMWMMMMMMMMKNNWMMMMMMMMMMMMMMMMMMMM\n",
"MMKdWWNXMMMxNWNNWNNONNNWNNNNWokWMNNXNNNMMWNXMMMMMMMMM0NNNNXNNNNoXWWKMMMMMMMdKMMNXMMM00NXWMMM00NNNMMM\n",
"MM0oMMMNMMM;NMMMMMM;KXWMMMMXXKcMMxkMMMNXkkXMMMMMMMMMMcMMMMXNMMW:XMMNMMMMMMOkMMMMNXXONMMMNNNkXMMMXNMM\n",
"MMXlMMMNMMMcXMX00KXNXkxMMMWXMM00KKoOXMWNNNNNMMMMMMMMMcMMMXNxxMW:0MMNMMMMMXdMMKlMMNox0MMMMMXMMMWXWMMM\n",
"MMNcMMMNWWN,0MMXXNMMM0xMMMXWMMMMMMMKK00oWMMWNMMMMMMMMcMMMWWXWNXx0MMWWWWNXoWMMKcKMMNXKxxKMMMMMNNMMMMM\n",
"MMMlMMMMMMM,0MMWWWNNM0kMMMXMMMMMMWdNNNNXMMMMXMMMMMMMMcMMMMXXNMMkkMMMMMMMcXMMMMMMMMMNNMMcMMMMMNMMMMMM\n",
"MMMcMMWWWXN:kNXXXXXWMKd0KWXMMMMMMoOMMMMMMWNXMMMMMMMMMcMMMMXMMMMOxMWWWNXNlKMMNXXcXMNNNMMcNWWWMNMMMMMM\n",
"MMMKXXKXXXNNXNMMMMMMMMMMX0WMMMMMMMKO0KKXNWMMMMMMMMMMMXKKKKNMMMMWKXXKXXXWMKk0NMMWONWMMMMNXKKXKWMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n"
]
}
],
"source": [
"! jp2a play.jpg --width=100"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" \n",
" \n",
" \n",
" . .. ... .... . . .... \n",
" ...... ..................... ...... ... ............... .. .. ..... ..... \n",
" .. . .. .... .... .. ..... . .. ... . .. ..... ..... .. \n",
" .. . .. ......... .. ....... ...... . .... ... . .. .. .... . ... \n",
" .. ...... ... .. .. ...... .. . ........ ........ ... ...... .. \n",
" . .. ..... .. . ....... . . ... .. .. .. . . \n",
" . .............. ...... .. ... . . .. ........ ..... ... ..... . \n",
" ........... ... ........ ...... ......... .... .... ....... \n",
" \n",
" \n",
" \n"
]
}
],
"source":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MNNNMMcNWWWMNMMMMMM\n",
"MMMKXXKXXXNNXNMMMMMMMMMMX0WMMMMMMMKO0KKXNWMMMMMMMMMMMXKKKKNMMMMWKXXKXXXWMKk0NMMWONWMMMMNXKKXKWMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n",
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'''\n",
"\n",
"for line in img.split(\"\\n\"):\n",
" for letter in line:\n",
" if letter == \"M\":\n",
" img = img.replace(letter, \" \")\n",
" else:\n",
" img = img.replace(letter, \".\")\n",
" \n",
"print(img)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## World Wheel but different\n",
"\n",
"![](https://literacystarter.files.wordpress.com/2014/11/word-wheel.png)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" a a n i i i o a f i fi i \n",
" a cm i i a \n",
" c ti n a c ii a n n \n",
" a f i g n a i i c \n",
" nt i c i n c o \n",
" a a m o m fg a cm g m \n",
" i a i n ia a a o g i t\n",
"nm g n i a f i i i i a i n o i if t \n",
"o c i a i gt o g a a i i \n",
" g o o i o f c a c a i i\n",
" o g f i i a t c i an t a i i f n\n",
" i i o a gm g f i \n",
" i g f c a a ca i t c a t \n",
" i a to a n o n o c io \n",
" f o f iam c i i a \n",
" g g a a m g a n a n i g \n",
" c f o o t n o g n m t c \n",
" f i g ng o m i i im \n",
" a iim a i i t i i n \n",
" c oa m a c g a n g ig i naag \n",
" f i o a f o a a o t o g m \n",
" t t i a i a a fa c c n \n",
" o g m i a i i n g m m i f n i i \n",
" n g a m i i o ft i f i f\n",
" t m ia g i i \n"
]
}
],
"source": [
"from random import choice\n",
"\n",
"character_set = 'gamification '\n",
"characters = [character for character in character_set]\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": [
"# More games plz!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What other mini-games can we make?\n",
"\n",
"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...\n",
"\n",
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}