Skip to content
Snippets Groups Projects
Unverified Commit b81fb0f8 authored by Noah Huppert's avatar Noah Huppert
Browse files

added drexel hackethon files

parents
No related branches found
No related tags found
No related merge requests found
import os, threading, time
# Constants
# If we should be running
stopped = threading.Event()
# Time to wait between frames
framedelay = 0.25
"""Clears the terminal screen
"""
def clearscr():
os.system("clear")
"""Prints msg without a newline at the end
Args:
- msg (str): String to print
"""
def printl(msg):
print(msg, end="", flush=True)
"""Prints a falling waterfall animation
Args:
- t (int): Time value
"""
def print_waterfall(t):
# Top
topL = 14
for i in range(topL):
if (i + t) % 3 == 0:
printl("_")
else:
printl(">")
printl("\n")
# Down stream
streamH = 10
for i in range(streamH):
printl(" " * topL)
if (i + t) % 3 == 0:
printl("|")
else:
printl("v")
printl("\n")
"""Prints a fountain animation
Args:
- t (int): Time value
"""
def print_fountain(t):
# Sizing
leftSpacing=10
spirtSpacing=5
baseWidth=16
streamHeight=10
poolWidthFudgeFactor=8
poolHeight=5
# Base
printl(" " * leftSpacing)
for i in range(baseWidth):
if i % spirtSpacing == 0:
middleChar = "|"
if t % 2 == 0:
middleChar = "v"
printl("|{}|".format(middleChar))
else:
printl("=")
printl("\n")
# Streams from base
for h in range(streamHeight):
printl(" " * leftSpacing)
for w in range(baseWidth):
if w % spirtSpacing == 0:
if (h + t) % 2 == 0:
printl(" | ")
else:
printl(" v ")
else:
printl(" ")
printl("\n")
# First pool
def pool(poolWidth, leftSp):
printl("{}\\".format(" " * leftSp))
for w in range(poolWidth + poolWidthFudgeFactor):
ww = t + w
if ww % 2 == 0:
printl("^")
else:
printl("v")
printl("/\n")
for h in range(poolHeight):
pool(baseWidth - ( 2*h ), leftSpacing + h)
"""Draw action loop
"""
def draw():
t = 0
while not stopped.is_set():
# Draw
clearscr()
print_waterfall(t)
# Wait
time.sleep(framedelay)
t += 1
# Run
thread = threading.Thread(target=draw)
thread.start()
while input() != "q":
pass
stopped.set()
thread.join()
# Fire
Have a fire that slowly spreads across the grass. After it has spread have a
rain cloud put it out. And loop.
#!/usr/bin/env python
class FieldValue:
def __init__(self, name, symbol):
self.name = name
self.symbol = symbol
def __str__(self):
return "{} = {}".format(self.symbol, self.name)
WALL = FieldValue("wall", "+")
UNKNOWN = FieldValue("unknown", "?")
SAFE = FieldValue("safe", "0")
MINE = FieldValue("mine", "*")
ROBOT = FieldValue("robot", "R")
DOOR = FieldValue("door", " ")
""" Field represents a minefield. (0, 0) is the bottom left.
"""
class Field:
def __init__(self, xSize, ySize):
# Check minimum size
if xSize < 4:
raise ValueError("xSize can not be less than 4")
if ySize < 4:
raise ValueError("ySize can not be less than 4")
self.values = []
# For each column
for x in range(xSize):
col = []
# For each row
for y in range(ySize):
col.append(UNKNOWN)
self.values.append(col)
def __str__(self):
out = ""
# For each column
colStrs = []
for col in self.values:
colStr = ""
# For each row
for row in col:
colStr += row.symbol
colStrs.append(" ".join(colStr))
out = "\n".join(colStrs)
return out
# Test field
f = Field(3, 3)
print(f)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment