Showing posts with label pygame. Show all posts
Showing posts with label pygame. Show all posts

Monday, July 20, 2015

RetroTech Tuesdays

“Saving history, one tech gadget at a time”


RetroTech is akin to computer clubs from the early days of computing, such as the one where Steve Wozniak drug Steve Jobs to see his computer kit, later known as the Apple I.

But we are interested in all aspects of retro technologies, not just computers. Handheld games, music gear,  arcade machines, calculators, media, hifi, consoles, cartridges, cameras etc sharing one thing in common: they are definitely out of warranty!

We want to exchange techniques to repair, restore, maintain and preserve these otherwise disposable items that have shaped our past, present, and will continue to shape our future. Feel free to bring something for a “show and tell”. We also talk about simulation and emulation of older technology.

Come and join us around the TV in the Innovation Lounge (1st floor, where the foosball tables are), Tuesday the 21st at noon. A freshly restored Apple //c will be there, along with a miniature functional model (based on a Raspberry Pi and some Python code).


Outside the walls


The above is a typical communication sent every other week internally at Inmar. But I'd like to open this to the community. Perhaps rotating the meet to local schools and businesses. At least in the WFIQ, but ideally around downtown Winston Salem.

Francois Dion
@f_dion

Thursday, July 18, 2013

Pidora and Python

Hands On: Raspbian alternative on Raspberry Pi Part Deux

Last month, I looked at FreeBSD and Arch Linux and demoed these in a hands on session. This month, one of the Pi I'll have for the hands on this coming monday at WFU will be running Pidora.

If you are used to Raspbian for your Python coding, you'll find that there are a few differences, such as using yum instead of apt-get. Development packages end in -devel instead of -dev. All of that is quite normal since pidora is really Fedora and Raspbian is debian.

What I've found though is that if you are not willing to build quite a few packages yourself, it is still a little early to adopt pidora. I've not been able to get a satisfactory (ie, full library support) version of pygame going (no package available in the pidora repository at this time). No mpeg, no framebuffer support etc.

On the plus side, it boots very quickly (faster than arch or raspbian) and the shutdown is also extremely fast. I suspect that within a few months, the repository will be a bit more complete and will make python development easier. I'll revisit the OS later this year.

François
@f_dion

Friday, June 14, 2013

Pygame sound play

Música de fondo


En la lista Python tutor (en ingles) se hizo la pregunta de como añadir música en un vídeo-juego con pygame. Pueden leer mi respuesta en ingles en los archivos, o aquí en español. Es muy sencillo:

4 lineas, nada mas


Podemos hacerlo con python directamente en modo interactivo. La primera es incluir pygame.

>>> import pygame


Como es un juego pygame, es siempre presente, asi que en realidad hay que añadir solo 3 lineas mas.

>>> pygame.mixer.init(22050,-16,2,4096)

Las opciones del init, es según lo que uno desea (44100KHz o 22050KHz etc) o solo un init()

>>> snd = pygame.mixer.Sound("bach-cello-suite-1.wav")
>>> music = snd.play()
Ahora empieza la música. music.get_busy() nos dará un cero cuando es el fin de la música.

>>> music.get_busy()
1
>>> music.get_busy()
1
>>> music.get_busy()
0

Obviamente, el fichero .wav debe ser con el script .py o donde se ejecuta python.

François
@f_dion

Friday, June 7, 2013

Alcyone and on and on

SELF 2013

I had to share these snapshots I took at SELF 2013 (south east Linux fest in Charlotte, NC) today. Went there mostly for some database talks, but there were 2 raspberry Pi related presentations today. There is another one tomorrow at 4pm (Ruth Suehle, Easy As Raspberry Pi: Getting Started)

One was Alcyone:

Moog Taurus bass pedals? Almost
Raspberry Pi powered Alcyone

Joseph Ottinger designed and built this MIDI controller that is reminiscent of the Moog Taurus bass pedals (used by musicians such as Geddy Lee of Canadian band Rush). Interesting, isn't it?

Joseph used C and a non realtime kernel Linux (such as Raspbian). But it is possible to do this also using Python. Pygame would be one natural choice for that.

I'll follow up in a few days with some more details and some information on the other Raspberry Pi talk from today's program (Mike Brown, Linux On Arm).

François
@f_dion

Tuesday, February 5, 2013

Gráficos en la consola

Pygame, RaspberryPi, Webcams.


Pygame utiliza SDL para los gráficos, así que soporta directamente la consola o X windows. Es el caso en todas la plataformas (Unix, Linux, Mac, no solo en Raspbian sobre el RaspberryPi).

Si no conocen nada de Pygame, hay tutoriales en espanol aqui:
razonartificial.com

En mi caso, necesitaba código para capturar imágenes de una webcam (por un taller PyHack). con Python y Pygame, es muy sencillo. Hacer el import y init de los modulos, crear un objeto cam (de resolución 320x240), iniciar la camara, obtener una imagen (cam.get_image), y grabar como png.


import pygame
import pygame.camera  # experimental
from pygame.locals import *

pygame.init()
pygame.camera.init()

cam = pygame.camera.Camera("/dev/video0", (320,240))  # webcam

cam.start()
image = cam.get_image()
pygame.image.save(image,'fablocker.png')
cam.stop()

El mismo código funciona en la consola o el escritorio, perfecto con los cron jobs.


Matplotlib


Hay otros módulos Python que dependen de un servidor X windows. En casos de que no se require OpenGL (no hay en Raspberry Pi) o OpenGL ES, hay un servidor basico que podemos utilizar: xvfb.

Primeramente hay que hacer la instalación de xvfb:


$ sudo apt-get install xvfb


Matplotlib es bueno para hacer imagenes y incluirles en informes de actividad de servidor, por ejemplo. Un servidor web no requiere X windows, asi que porque deberiamos utilizar LXDE o otro escritorio grafico, solo por hacer imagenes que vamos a incluir en una pagina web?

Con xvfb, no hay problemas. Un script que contiene el código Python siguiente (poner en un fichero mpl.py):


from matplotlib.pyplot import *

plot([2,4,2,5,6,3,1])
savefig("graph.png")

Es lo que haria normalmente. Pero si tratamos de ejecutar el script directamente, vamos a recibir un error. A utilizar xvfb, eliminamos el error, así:

$ xvfb-run python mpl.py
  Va a generar un fichero graph.png que se vera asi:


Todo de la consola, sin escritorio gráfico.


François
@f_dion