aboutsummaryrefslogtreecommitdiff
path: root/.local/src/rainfall
diff options
context:
space:
mode:
authorkj-sh6042025-06-10 13:32:36 -0400
committerkj-sh6042025-06-10 13:32:36 -0400
commitd55248989fe4aa8b7c6f5d06ac8a89b66ba3aba8 (patch)
treeb86e16f5a611246ba6740d7c3e9331a5b2cf38eb /.local/src/rainfall
parent3eceaf30b0bfeb617e74275d15e41c0939fecd61 (diff)
refactor: multiple changes (see description)
* add LICENSEs where necesary * remove *pkg scripts from repo see: https://github.com/kj-sh604/gitpkg * rename .local/src python directories * update .local/bin scripts in relation to above
Diffstat (limited to '.local/src/rainfall')
-rw-r--r--.local/src/rainfall/LICENSE21
-rw-r--r--.local/src/rainfall/Makefile4
-rw-r--r--.local/src/rainfall/rainfall.py161
3 files changed, 186 insertions, 0 deletions
diff --git a/.local/src/rainfall/LICENSE b/.local/src/rainfall/LICENSE
new file mode 100644
index 0000000..4344f2d
--- /dev/null
+++ b/.local/src/rainfall/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 alpin111
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/.local/src/rainfall/Makefile b/.local/src/rainfall/Makefile
new file mode 100644
index 0000000..c7cdd98
--- /dev/null
+++ b/.local/src/rainfall/Makefile
@@ -0,0 +1,4 @@
+compile:
+ cython3 --embed -o rainfall.c -X language_level=3 rainfall.py
+ PYTHON_VERSION=`ls --sort version /usr/include | grep -o 'python[3-9]\+\.[0-9]\+' | tail -1` ; \
+ gcc -march=native -O2 -pipe -fno-plt -I /usr/include/$$PYTHON_VERSION -o rainfall rainfall.c -l$$PYTHON_VERSION -lpthread -lm -lutil -ldl
diff --git a/.local/src/rainfall/rainfall.py b/.local/src/rainfall/rainfall.py
new file mode 100644
index 0000000..9175022
--- /dev/null
+++ b/.local/src/rainfall/rainfall.py
@@ -0,0 +1,161 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import time
+import random
+import os
+import sys
+
+
+colors = {
+ "black": "\u001b[30m",
+ "red": "\u001b[31m",
+ "green": "\u001b[32m",
+ "yellow": "\u001b[33m",
+ "blue": "\u001b[34m",
+ "magenta": "\u001b[35m",
+ "cyan": "\u001b[36m",
+ "white": "\u001b[37m",
+ "reset": "\u001b[0m",
+
+ "b_black": "\u001b[30;1m",
+ "b_red": "\u001b[31;1m",
+ "b_green": "\u001b[32;1m",
+ "b_yellow": "\u001b[33;1m",
+ "b_blue": "\u001b[34;1m",
+ "b_magenta": "\u001b[35;1m",
+ "b_cyan": "\u001b[36;1m",
+ "b_white": "\u001b[37;1m",
+
+ "Reset": "\u001b[0m",
+}
+
+def Colored(string, color):
+ return string if "-m" in sys.argv else ( colors[color] + string + colors["Reset"])
+
+
+def Clear_Screen():
+ print("\033[2J") # erase saved lines
+ print("\033[3J") # erase entire screen
+ print("\033[H") # moves cursor to home position
+
+
+def Get_Arguments():
+ args_dict = {"colors": []}
+ if sys.argv:
+ for arg in sys.argv:
+ if "-i=" in arg:
+ args_dict["intensity"] = int(arg.split("-i=")[1])
+ if "-t=" in arg:
+ args_dict["timing"] = float(arg.split("-t=")[1])
+ if arg in colors:
+ args_dict["colors"].append(arg)
+ if not args_dict["colors"]:
+ del args_dict["colors"]
+ return args_dict
+
+
+def New_Drop():
+ for i in range(intensity):
+ shape = random.choice(DROPSHAPES)
+ color = random.choice(drop_colors)
+
+ raindrop = {
+ "shape": Colored(shape, color),
+ "x": random.randint(0, xmax),
+ "y": 0,
+ }
+ rainfall.append(raindrop)
+
+def Rain():
+ ## iterate over every line
+ for i in range(ymax):
+ line = " "*xmax
+
+ ### to avoid splicing of ansi codes, splice in the drops from the end of the line
+ this_line_raindrops = [raindrop for raindrop in rainfall if raindrop["y"] == i]
+ this_line_raindrops.sort(key=lambda y: y["x"])
+ this_line_raindrops.reverse()
+
+ ## insert new drops and shift existing drops
+ for raindrop in this_line_raindrops:
+ x = raindrop["x"]
+ line = line[:x] + raindrop["shape"] +line[x:]
+
+ print(line)
+
+ ### update raindrop positions
+ for raindrop in rainfall:
+ raindrop["y"] += 1
+
+ ## once a raindrop reaches the ground, they splash
+ if raindrop["y"] > ymax-2:
+ raindrop["shape"] = Colored("o", random.choice(drop_colors))
+
+ # raindrops outside the window evaporate
+ if raindrop["y"] > ymax:
+ rainfall.remove(raindrop)
+
+ New_Drop()
+
+
+
+def Weather_Forecast():
+ global weather
+ global intensity
+
+ weather += 1
+ if weather == 100:
+ weather = 0
+ intensity += random.choice([-1,1])
+ if intensity < 1:
+ intensity = 1
+ if intensity > 10:
+ intensity = 10
+
+
+size = os.get_terminal_size()
+xmax = size.columns
+ymax = int(size.lines)
+
+weather = 0
+rainfall = []
+DROPSHAPES =["|", "│", "┃", "╽", "╿", "║", "┆", "┇", "┊", "┋", "╵", "╹", "╻"]
+
+args = Get_Arguments()
+intensity = args.get("intensity", 1)
+timing = args.get("timing", 0.08)
+drop_colors = args.get("colors", ["blue", "b_blue"])
+
+
+
+print('\033[?25l', end="") ## hides the cursor
+New_Drop()
+
+try:
+ while True:
+ Rain()
+ time.sleep(timing)
+ Clear_Screen()
+ Weather_Forecast()
+
+except KeyboardInterrupt:
+ Clear_Screen()
+ print('\033[?25h', end="") # makes cursor visible again
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+