Skip to content

Instantly share code, notes, and snippets.

@popey456963
Last active May 20, 2016 19:50
Show Gist options
  • Save popey456963/fbd96ad6dd760d52ccfe3ae393bf2720 to your computer and use it in GitHub Desktop.
Save popey456963/fbd96ad6dd760d52ccfe3ae393bf2720 to your computer and use it in GitHub Desktop.
"""
Author: Popey456963
Date: 20/05/2016 20:10
Desc: Gradients
"""
import turtle
import time
from math import floor
window = turtle.Screen()
window.colormode(255)
CURRENT_BG = [0.0, 0.0, 0.0]
TICK_AMOUNT = 255
ITERATION_AMOUNT = 1
def gradient(red, green, blue):
global CURRENT_BG
red_change = (red[1] - red[0]) / TICK_AMOUNT
green_change = (green[1] - green[0]) / TICK_AMOUNT
blue_change = (blue[1] - blue[0]) / TICK_AMOUNT
for i in range(TICK_AMOUNT):
CURRENT_BG = [CURRENT_BG[0] + red_change, CURRENT_BG[1] + green_change, CURRENT_BG[2] + blue_change]
color = [int(floor(color)) if int(floor(color)) <= 255 else 255 for color in CURRENT_BG]
window.bgcolor(color)
time.sleep(0.001)
# Gradient #3
print("Gradient #3")
CURRENT_BG = [0, 255, 255]
window.bgcolor(CURRENT_BG)
for count in range(ITERATION_AMOUNT):
gradient([0, 255], [255, 0], [255, 255])
gradient([255, 0], [0, 255], [255, 255])
# Gradient #4
print("Gradient #4")
CURRENT_BG = [0, 255, 255]
window.bgcolor(CURRENT_BG)
for count in range(ITERATION_AMOUNT):
gradient([0, 255], [255, 255], [255, 0])
gradient([255, 0], [255, 255], [0, 255])
# Gradient #5
print("Gradient #5")
CURRENT_BG = [0, 255, 255]
window.bgcolor(CURRENT_BG)
for count in range(ITERATION_AMOUNT):
gradient([0, 255], [255, 255], [0, 0])
gradient([255, 255], [255, 0], [0, 255])
gradient([255, 0], [0, 255], [255, 255])
gradient([0, 0], [255, 255], [255, 0])
# Gradient #6
print("Gradient #6")
CURRENT_BG = [0, 255, 255]
window.bgcolor(CURRENT_BG)
for count in range(ITERATION_AMOUNT):
gradient([0, 255], [0, 255], [0, 255])
gradient([255, 0], [255, 0], [255, 0])
"""
Author: Popey456963
Date: 20/05/2016 19:09
Desc: Lightning Distance Calculator
"""
# Value * Unit Multiplier
SPEED_OF_SOUND = 340.29 * 1
def main():
timeInterval = float(input("<<< (Time Interval) "))
distance = timeInterval * SPEED_OF_SOUND
print(">>> " + str(round(distance,2)))
return distance
if __name__ == '__main__':
main()
"""
Author: Popey456963
Date: 20/05/2016 20:30
Desc: Molecular Formula
"""
import re
ATOMIC_MASSES = {'V': 50.9415, 'Hs': 268.0, 'Rn': 222.0, 'As': 74.9216, 'Xe': 131.293, 'Ar': 39.0983, 'Br': 79.904, 'Re': 186.207, 'Rf': 262.0, 'B': 10.811, 'Es': 252.0, 'Ne': 20.1797, 'Ni': 58.9332, 'Pu': 243.0, 'Po': 209.0, 'Li': 6.941, 'Ra': 226.0, 'Sb': 121.76, 'Tc': 98.0, 'Pr': 140.9077, 'In': 114.818, 'Ds': 277.0, 'Ru': 101.07, 'Tm': 168.9342, 'Lu': 174.967, 'Eu': 151.964, 'Al': 26.9815, 'Pd': 106.42, 'Mo': 95.94, 'K': 39.948, 'Cd': 112.411, 'Mg': 24.305, 'Fr': 223.0, 'Zn': 65.39, 'C': 12.0107, 'Hg': 200.59, 'Ag': 107.8682, 'Uut': 0.0, 'P': 30.9738, 'Tl': 204.3833, 'U': 237.0, 'O': 15.9994, 'Cl': 35.453, 'Pa': 232.0381, 'Se': 78.96, 'Md': 258.0, 'Np': 238.0289, 'Rg': 0.0, 'Pm': 145.0, 'Co': 58.6934, 'Uus': 0.0, 'Fm': 257.0, 'Pt': 195.078, 'At': 210.0, 'Uuh': 0.0, 'Er': 167.259, 'Ga': 69.723, 'Cu': 63.546, 'Bk': 247.0, 'Uub': 0.0, 'Rb': 85.4678, 'Sr': 87.62, 'Cm': 247.0, 'Sg': 264.0, 'Lr': 261.0, 'Tb': 158.9253, 'H': 1.0079, 'Nd': 144.24, 'Mt': 272.0, 'No': 259.0, 'Kr': 83.8, 'Si': 28.0855, 'Ta': 180.9479, 'S': 32.065, 'Na': 22.9897, 'I': 127.6, 'Os': 190.23, 'Uuq': 0.0, 'Te': 126.9045, 'Rh': 102.9055, 'Bi': 208.9804, 'N': 14.0067, 'He': 4.0026, 'Fe': 55.845, 'Sn': 118.71, 'Ho': 164.9303, 'F': 18.9984, 'Mn': 54.938, 'Cr': 51.9961, 'Dy': 162.5, 'Cf': 251.0, 'Y': 88.9059, 'Bh': 266.0, 'Cs': 132.9055, 'Ac': 227.0, 'Yb': 173.04, 'Ge': 72.64, 'Ca': 40.078, 'Ti': 47.867, 'Sc': 44.9559, 'Db': 262.0, 'Ba': 137.327, 'Am': 244.0, 'Th': 231.0359, 'Uup': 0.0, 'Pb': 207.2, 'La': 138.9055, 'Be': 9.0122, 'Au': 196.9665, 'Hf': 178.49, 'Ce': 140.116, 'Nb': 92.9064, 'W': 183.84, 'Uuo': 0.0, 'Sm': 150.36, 'Zr': 91.224, 'Gd': 157.25, 'Ir': 192.217}
def main():
chemical_input = input("<<< (Chemical) ")
parts = [chemical if chemical[1] != "" else (chemical[0], "1") for chemical in re.findall(r'([A-Z][a-z]*)(\d*)', chemical_input)]
print(">>> Molecule: " + chemical_input)
print(">>> Mass: " + str(round(sum([int(part[1]) * ATOMIC_MASSES[part[0]] for part in parts]),4)))
if __name__ == '__main__':
main()
"""
Author: Popey456963
Date: 20/05/2016 19:50
Desc: Sweet Shop
"""
# Value * Unit Multiplier
PRICE_LIST = [["Marshmallow", 0.2], ["Bubble Gum", 0.3], ["Jelly Bean", 0.15], ["Candy Stick", 0.35],
["Cola Whips", 0.22]]
LETTER_LIST = "ABCDEX"
LOWEST_PRICE = 0.15
def main():
bought = [0] * len(PRICE_LIST)
money = 5
while 1:
if money < LOWEST_PRICE:
print(">>> You can't buy anymore!")
break
for index, candy in enumerate(PRICE_LIST):
print(">>> " + LETTER_LIST[index] + " - " + (candy[0] + ":").ljust(12, " ") + " £"+ "{0:.2f}".format(candy[1]))
print(">>> " + LETTER_LIST[-1:] + " - Exit")
key = input("<<< (Key) ")
if key in LETTER_LIST:
if LETTER_LIST.index(key) == len(LETTER_LIST) - 1:
break
else:
item_bought = PRICE_LIST[LETTER_LIST.index(key)]
if item_bought[1] <= money:
money -= item_bought[1]
bought[LETTER_LIST.index(key)] += 1
print(">>> You bought " + item_bought[0] + " for £" + "{0:.2f}".format(item_bought[1]))
else:
print(">>> You don't have enough money for that item!")
else:
print(">>> Unknown Item...")
print(">>> You exitted with £" + "{0:.2f}".format(money))
for index, value in enumerate(bought):
if value != 0:
print(">>> You bought " + str(value) + " " + PRICE_LIST[index][0] + "(s)")
if __name__ == '__main__':
main()
"""
Author: Popey456963
Date: 20/05/2016 19:13
Desc: Window Cleaner's Quotes
"""
CALL_OUT_FEE = 10
WINDOW_COSTS = [[5, 2], [10, 1.5], ["max", 1]]
def main():
previous_ranges = 0
cost = CALL_OUT_FEE
windowsToClean = int(input("<<< (Number of Windows) "))
for index, cost_range in enumerate(WINDOW_COSTS):
print(cost)
print(windowsToClean)
print(index)
print(cost_range)
if cost_range[0] == "max" or cost_range[0] > windowsToClean:
# Clean all the current windows and break
cost += windowsToClean * cost_range[1]
break
else:
# Clean just the ones in range and continue
cost += cost_range[1] * (cost_range[0] - previous_ranges)
windowsToClean -= cost_range[0] - previous_ranges
previous_ranges = cost_range[0]
print(">>> £" + str(cost))
return cost
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment