Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Python
Message
De
30/03/2014 19:13:28
 
 
À
29/03/2014 14:03:35
Information générale
Forum:
Python
Catégorie:
Autre
Titre:
Re: Python
Divers
Thread ID:
01597505
Message ID:
01597726
Vues:
48
>>>Hi Denis, thanks for that. He did know about Khan Academy but was not aware it had Python tutorials. He is going to check it out.
>>>
>>>Can anyone remember what John Fabiani was using, the Python variation and I think he was using a framework.
>>
>>The fwk is Dabo. There is a Python for kids book - unsure what exactly your son is loking for...
>
>Yes, that was the name, thanks. My son is just experimenting, teaching himself a bit. I think developing software is interesting to him, not as a career but simply as a useful skill to have. I'm suggesting to go after a language which has very wide universal acceptance and can lead him onto C/C++ and the various variations.


I haven't written a lot of Python code, but the code I have written does a lot. I hooked a bunch 6 USB mics to a laptop and monitored their input, change a tile on the screen a different color in response to the volume levels. The idea is to run it on a Raspberry Pi and an LED light / glass sculpture or chandelier.

It's about 60 lines of code.

**EDIT

Actually, it's 48. This reads the audio and opens a colored window for each mic:
import alsaaudio, time, audioop
from Tkinter import *

cards = alsaaudio.cards()
print cards

# the first card is internal Intel
# we need the rest

mics = []
windows = []

for i in range(len(cards) - 1):
    root = Tk()
    #    root.minsize(605,355)
    root.minsize(405,255)
    windows.append(root)
    
    inp  = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, "hw:CARD=" + cards[1 + i])
    
    inp.setchannels(1)
    inp.setrate(8000)
    inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
    inp.setperiodsize(160)
    
    mics.append(inp)

ratio = 4

while True:

    for i in range(len(mics)):
        l,data = mics[i].read()
        if l:
            red1 = audioop.max(data, 2)
            if i == 1:
                mycolor = '#%02x%02x%02x' % (0, min(red1/ ratio, 255), 0)
            elif i == 2:
                mycolor = '#%02x%02x%02x' % (0, 0, min(red1/ ratio, 255))
            elif i == 3:
                mycolor = '#%02x%02x%02x' % (min(red1/ ratio, 255), min(red1/ ratio, 255), 0)
            else:
                mycolor = '#%02x%02x%02x' % (min(red1/ ratio, 255), 0, 0)
            
            windows[i].configure(bg=mycolor)
            windows[i].update()

    time.sleep(.001)

You just go downloading different modules for something like that. A lot is in the standard library, but so much more is available too.

I volunteer to video Python conferences with former Foxer Carl Karsten and we recorded this one in Germany last fall:

http://www.pyvideo.org/video/2384/python-einsteiger-programmierwettbewerb

Skip to about 17 minutes.

It's a 13 kid demonstrating his 3D poker game.

I think PyMove3D is the module (library you download ).

There's pygame too (if memory serves) and various others.


I would throw out, though, that JavaScript is easier to get into.

Make a htm file.

Open a browser. Go.

And it's easier to show off.

If he can make things he's shows his friends and they can use in their browser, that might be more exciting.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform