Author Topic: Merry Happy ChristmaHunauKwanzika  (Read 1040 times)

0 Members and 1 Guest are viewing this topic.

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Merry Happy ChristmaHunauKwanzika
« on: December 25, 2012, 01:07:29 am »
Love you guys, Windows only though. I'm sure it will be a fun little challenge to port this to Linux for those who want to =). (Yes I see you Kulver and RedBull).

Python 2.6
Code: (Python) [Select]
#Quick geek/nerd Christmas from le Tech B.
#There is at lest zip() that shows working with 2 iterables and a windows only method

import winsound, time, os

note_trans = {"C":2441, "D":2741, "E":3048, "F":3255, "G":3654, "A":4058, "B":4562}
len_trans = {1:100, 2:200, 4:400}

song = ("E", "E", "E", "E", "E", "E", "E", "G", "C", "D", "E", "F", "F", "F", "F",
        "F", "E", "E", "E", "E", "D", "D", "E", "D", "G")
       
length = (1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2)

os.system("color 02")
print "Have a programmers Christmas!!!"

for n,l in zip(song,length):
    time.sleep(.3)
    winsound.Beep(note_trans[n], len_trans[l])

print "I love you EZ, and all who see this.\nKeep being awesome people."
« Last Edit: December 25, 2012, 01:13:10 am by techb »
>>>import this
-----------------------------

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Merry Happy ChristmaHunauKwanzika
« Reply #1 on: December 25, 2012, 09:47:18 am »
AHAHAHA you made me laugh man :D very nice song script :)
« Last Edit: December 25, 2012, 09:53:13 am by Kulverstukas »

Offline RedBullAddicted

  • VIP
  • Sir
  • *
  • Posts: 519
  • Cookies: 189
    • View Profile
Re: Merry Happy ChristmaHunauKwanzika
« Reply #2 on: December 25, 2012, 10:35:12 am »
Hi,

marry christmas to you, too mate :) I don't know why but none of my machines want to play it. Theoretical it should be possible to make it run on linux by installing beep (debian apt-get install beep) and run it in python with os.system e.g.

Code: (python) [Select]
winsound.Beep(note_trans[n], len_trans[l])
replaced with:

Code: (python) [Select]
os.system('beep -f %s -l %s' % (note_trans[n],len_trans[l]))
the color command is a bit more complicated as you need to write it to bash.rc. To keep it simple I would just remove the line :)
Maybe someone can try it ... really don't know why my machines won't play it. I looked through the bios settings and when I unplug the power cord a sound is played ???

I know this is not the best way but it was the only thing my hangover brain was able to do so please don't flame me.
Deep into that darkness peering, long I stood there, wondering, fearing, doubting, dreaming dreams no mortal ever dared to dream before. - Edgar Allan Poe