mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 15:17:47 +00:00
This PR is part of porting all old scripts #221 and ports `fun` folder <details><summary>Summary</summary> ### star.nu ```yaml from: before_v0.60/fun/star.nu to: modules/fun/star.nu ``` ### spark.nu The script has already been ported. I've removed old version. ```yaml from: before_v0.60/fun/spark.nu to: sourced/fun/spark.nu functions: spark: sourced/fun/spark.nu:1:spark ``` ### life.nu ```yaml from: before_v0.60/fun/life.nu to: modules/fun/life.nu ``` ### lisp_mode.nu There is a problem with this module because `-` is not allowed in names anymore, however `def "-"` is a valid syntax, but you will be unable to call this function. ```yaml from: before_v0.60/fun/lisp_mode.nu to: sourced/fun/lisp_mode.nu ``` ### nyancat.nu I also fixed animation frames from https://github.com/klange/nyancat ```yaml from: before_v0.60/fun/nyancat.nu to: modules/fun/nyancat.nu ``` </details>
This commit is contained in:
parent
b40ead9ae2
commit
2fe0756df9
7 changed files with 194 additions and 236 deletions
127
modules/fun/star.nu
Normal file
127
modules/fun/star.nu
Normal file
|
@ -0,0 +1,127 @@
|
|||
# i found this script on a github issue and wanted to see what nushell would do.
|
||||
# https://github.com/microsoft/terminal/issues/11794
|
||||
|
||||
#########################################################
|
||||
# here's the python version from that issue
|
||||
#########################################################
|
||||
# import math
|
||||
# import os
|
||||
# import sys
|
||||
|
||||
# size = os.popen('stty size', 'r').read().split()
|
||||
# h,w = tuple(int(n) for n in size)
|
||||
# mx = w//2
|
||||
# my = h//2
|
||||
|
||||
# def frame(i):
|
||||
# s = '\033[H'
|
||||
# for y in range(h):
|
||||
# for x in range(w):
|
||||
# dy,dx = y-my,x-mx
|
||||
# a = math.atan2(dy*2,dx) + math.pi
|
||||
# c = (int(a/math.pi*127)+i)%256
|
||||
# s += '\033[38;2;%d;%d;%dm*' % (c,c,c)
|
||||
# return s
|
||||
|
||||
# sys.stdout.write('Generating content...\n')
|
||||
# s = '\033[?25l'
|
||||
# for i in range(512):
|
||||
# s += frame(i)
|
||||
# s += '\033[?25h\033[m\033[H'
|
||||
|
||||
# sys.stdout.write('Starting animation...\n')
|
||||
# sys.stdout.write(s)
|
||||
|
||||
#########################################################
|
||||
# here's the c version from that issue
|
||||
#########################################################
|
||||
# #include <windows.h>
|
||||
# #include <string>
|
||||
# #include <cmath>
|
||||
|
||||
# void main()
|
||||
# {
|
||||
# HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
# DWORD mode;
|
||||
# GetConsoleMode(handle, &mode);
|
||||
# mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
# SetConsoleMode(handle, mode);
|
||||
|
||||
# CONSOLE_SCREEN_BUFFER_INFOEX csbie;
|
||||
# csbie.cbSize = sizeof(csbie);
|
||||
# GetConsoleScreenBufferInfoEx(handle, &csbie);
|
||||
|
||||
# const auto w = csbie.dwSize.X;
|
||||
# const auto h = csbie.srWindow.Bottom - csbie.srWindow.Top + 1;
|
||||
# const auto mx = w/2;
|
||||
# const auto my = h/2;
|
||||
# const auto pi = 3.14159265358979323846;
|
||||
|
||||
# printf("Generating content...\n");
|
||||
# std::string s = "\033[?25l";
|
||||
# for (auto i = 0; i < 512; i++) {
|
||||
# s += "\033[H";
|
||||
# for (auto y = 0; y < h; y++) {
|
||||
# for (auto x = 0; x < w; x++) {
|
||||
# auto dy = y-my;
|
||||
# auto dx = x-mx;
|
||||
# auto a = std::atan2(dy*2,dx) + pi;
|
||||
# auto c = std::to_string((int(a/pi*127)+i)%256);
|
||||
# s += "\033[38;2;"+c+";"+c+";"+c+"m*";
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# s += "\033[?25h\033[m\033[H";
|
||||
|
||||
# printf("Starting animation...\n");
|
||||
# DWORD written = 0;
|
||||
# WriteConsoleA(handle, s.c_str(), s.length(), &written, NULL);
|
||||
# }
|
||||
|
||||
|
||||
use std math
|
||||
|
||||
def atan2 [y x] {
|
||||
if $x > 0 {
|
||||
$y / $x | math arctan
|
||||
} else if $x < 0 {
|
||||
if $y >= 0 {
|
||||
$math.PI + ($y / $x | math arctan)
|
||||
} else {
|
||||
-1 * $math.PI + ($y / $x | math arctan)
|
||||
}
|
||||
} else {
|
||||
if $y >= 0 {
|
||||
$math.PI / 2
|
||||
} else {
|
||||
-1 * $math.PI / 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let w = 50
|
||||
let h = 20
|
||||
# if it's fast for your, change w, h to the below lines
|
||||
# let w = (term size).columns - 2
|
||||
# let h = (term size).rows - 2
|
||||
let mx = ($w / 2 | math floor)
|
||||
let my = ($h / 2 | math floor)
|
||||
|
||||
print (ansi -e "?25l")
|
||||
|
||||
for i in 0..512 {
|
||||
let rows = (0..($h) | each {|y|
|
||||
let cols = (0..($w) | each {|x|
|
||||
let dy = ($y - $my)
|
||||
let dx = ($x - $mx)
|
||||
let a = (atan2 ($dy * 2) $dx) + $math.PI
|
||||
let c = ((($a / ($math.PI) * 127) + ($i)) mod 256 | math round)
|
||||
$"(ansi -e '38;2;')($c);($c);($c)m*"
|
||||
})
|
||||
$cols | str join
|
||||
})
|
||||
print ((ansi -e 'H') + ($rows | str join (char nl)))
|
||||
}
|
||||
|
||||
print $"(ansi -e '?25h')(ansi -e 'm')(ansi -e 'H')"
|
Loading…
Add table
Add a link
Reference in a new issue