From cf982a11563429228070ce9b0f81a2fb0a066666 Mon Sep 17 00:00:00 2001 From: Scott Date: Sun, 13 Jul 2025 18:16:12 +0000 Subject: [PATCH] Initial Commit. My first commit on Tilde.club! --- .gitignore | 15 ++++++++++ README.md | 13 +++++++++ dna.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 dna.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39cefb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +.env +*.pyc +*.swp +/bin +/Include +/include +/lib +/lib64 +/Lib +/Scripts +pyvenv.cfg +/build +/dist +*.egg-info⏎ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a26910 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +#Clever Heading Goes Here. + +This is just a Python script that makes an ascii art DNA strand. It took me way too long to make for what it is, but it was fun. + +Use the `-h` flag to show command line args. I recommend the `-b` flag to use blocks intead of letters, It loooks pretty cool I think. + +When I signed up for tilde.club, the starting message says "Make a disaster, be a disaster!" And somewhere on Mastodon I saw a meme that says "BUILD SILLY THINGS!" + +So that's what I did. And that's what I'll continue to do, when I'm not outsiding. But it's too dang hot this weekend. So, ASCII art. + +###Does this really need a license? + +Just consider it MIT I guess if you really need one. diff --git a/dna.py b/dna.py new file mode 100644 index 0000000..524c0c3 --- /dev/null +++ b/dna.py @@ -0,0 +1,85 @@ +from math import sin, cos, pi +from colorama import Fore,Back,Style +from time import sleep +from random import randint +import argparse + +#command line arg stuff +desc="Displays an ASCII art strand of DNA, because why not?" +epi="""Protip: to watch an animated strand of ASCII DNA scroll across the screen, +set length to a really large number and pause to a reasonable number like 50 +or 100 milliseconds. Enjoy!""" +parser=argparse.ArgumentParser(description=desc, epilog=epi) +parser.add_argument("-l", "--length", type=int, help="Changes the length of the ASCII DNA. Default = 40") +parser.add_argument("-p", "--pause", type=int, help="Number of milliseconds to pause after plotting each line. Default=0") +parser.add_argument("-b", "--block", action="store_true", help="Display useing block characters instead of letters. Default=False") +args=parser.parse_args() + +if args.length: length=args.length +else: length=40 + +if args.pause: pause=args.pause +else: pause=0 + +if args.block: + chars={"x":"█","a":"█","t":"█","g":"█","c":"█"} +else: + chars={"x":"X","a":"A","t":"T","g":"G","c":"C"} + +#define and initialize stuff +class DnaStrand: + def __init__(self, char, func): + self.char=char + self.func=func + def pos(self,x): + return int(self.func(x)) + def getchar(self): return self.char + +width = 20 +blank=[] +lin=[] +theta=0 +basecount=2 +step=pi/12 + +bluchar=Fore.BLUE+chars["x"]+Fore.WHITE +blustrand=DnaStrand(bluchar, lambda x: (width/2-1)*(sin(x)+1)) +redchar=Fore.RED+chars["x"]+Fore.WHITE +redstrand=DnaStrand(redchar, lambda x: (width/2-1)*(cos(x)+1)) + +a=Fore.YELLOW+chars["a"]+Fore.WHITE +t=Fore.WHITE+chars["t"]+Fore.WHITE +g=Fore.GREEN+chars["g"]+Fore.WHITE +c=Fore.CYAN+chars["c"]+Fore.WHITE +msg="tilde.club" +for i in range (width): + blank.append(" ") + + +#Draw +for i in range(length): + lin=blank.copy() + blupos=blustrand.pos(theta) + redpos=redstrand.pos(theta) + lin[blupos]=blustrand.getchar() + lin[redpos]=redstrand.getchar() + + if basecount%3==0 and abs(blupos-redpos) > 3: + bp=randint(1,4) + if bp==1:bp1,bp2=a,t + elif bp==2:bp1,bp2=t,a + elif bp==3:bp1,bp2=g,c + else:bp1,bp2=c,g + halfway=int(abs(blupos+redpos)/2) + start=min(redpos,blupos)+1 + end=max(redpos,blupos) + lin[start:halfway]=[bp1]*abs(halfway-start) + lin[halfway:end]=[bp2]*abs(end-halfway) + tc=randint(1,5) + if tc==5 and end-start > len (msg): + lin[start:start+len(msg)]=list(msg) + + print("".join(lin)) + theta += step + basecount+=1 + sleep(pause/1000)