From 69a8e0bd9b5bf62cadb3f26b675a0d92b53e8668 Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Mon, 6 Nov 2023 21:55:46 +0100 Subject: [PATCH] Kuhschleudern --- kreis.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 kreis.py diff --git a/kreis.py b/kreis.py new file mode 100755 index 0000000..cf1d512 --- /dev/null +++ b/kreis.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +import os, sys, termios, tty, time, random +from math import sin, cos, sqrt +from time import sleep + +# Randomly choose a cow +cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕" +cowslength = len(cows) +cow = cows[random.randint(0, cowslength - 1)] +# cow = "🐄" +# cow = "*" +if cow.isascii(): + charlength = 1 +else: + charlength = 2 + +# Needed: find our screensize +termsize_xy = os.get_terminal_size() +# maximum and medium of points in a row +xmax = termsize_xy[0] - 1 +xmitte = xmax / 2 +# maximum and medium of points in a column +ymax = termsize_xy[1] +ymitte = ymax / 2 + +# CTRL and ESC-codes for the used outputdevice. Probably a terminal. +clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h" + + +# pi is not defined by default. Noone has a display with 31416 Pixels in a row. U know better? Enhance it. +pi = 3.1416 +# This is for convenience, if you are thinking in degrees. It must not be recalculated every loop. +deg2rad = pi / 180 +# position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams + +# some scales, we need. Those UTF8Cows are 2 chars wide and need more space. So we have to scale one Axis +radius = ymitte - 2 +xradius = ymitte * charlength - 1 + + +# Position the curser at x,y. Yes, we start with x, print does not, you are looking right. Leave it this way! +def curpos(x, y): + print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) + + +print(clear, curoff) + +# Draw a circle in maximum 360 Steps, one for for every degree +for winkel in range(0, 359): + x = sin(winkel * deg2rad) * xradius + xmitte + y = cos(winkel * deg2rad) * radius + ymitte + curpos(x, y) + print(cow, end="") + time.sleep(0.01) + + +curpos(1, 1) +sys.exit(curon + "Schulz nun.")