programar con processing en...

20
Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACI ´ ON EN MATEM ´ ATICAS Julio 2015 , J.B. Hayet Processing-Python Mode, Julio 2015 1 / 20

Upload: dinhhanh

Post on 02-Aug-2018

257 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Programar con Processing en Python

J.B. Hayet

CENTRO DE INVESTIGACION EN MATEMATICAS

Julio 2015

,J.B. Hayet Processing-Python Mode, Julio 2015 1 / 20

Page 2: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

El “lenguaje” Processing

Processing:

Un dialecto de Java, muy simplificado.

Una IDE sencilla e intuitiva.

A priori ninguna dificultad para programadores en C, C++.

La meta es tocar a un publico que no sabe de lenguajes engeneral, enfocado a graficos interactivos, sonido, vıdeo,animacion. . .

,J.B. Hayet Processing-Python Mode, Julio 2015 2 / 20

Page 3: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

El “lenguaje” Processing

Aplicaciones particularmente bien adaptadas:

ensenanza: rudimentos programacion hasta POO,

ensenanza: ilustracion animada de conceptos,

prototipaje rapido de aplicaciones, “sketches”

visualizacion de datos.

,J.B. Hayet Processing-Python Mode, Julio 2015 3 / 20

Page 4: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Una IDE reducida a lo esencial

,J.B. Hayet Processing-Python Mode, Julio 2015 4 / 20

Page 5: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Una IDE reducida a lo esencial

Una ventana de texto, para escribir el codigo.

Una consola.

Una ventana grafica, con el output del programa.

Interfaz de la IDE simplista:

En unos minutos, se entiende como funciona todo.

,J.B. Hayet Processing-Python Mode, Julio 2015 5 / 20

Page 6: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Sketches

El concepto de Sketch es el de “proyecto” de las IDEsnormales, es decir el un programa con una o varias unidades decompilacion.

A un Sketch corresponde a un directorio en un directorio deSketches.

Los archivos de los Sketches tienen extension .pde (Java) o.pyde (Python).

Los diferentes archivos aparecen como pestanas en la ventanadel codigo.

,J.B. Hayet Processing-Python Mode, Julio 2015 6 / 20

Page 7: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Librerıas disponibles

Integrados

Importacion de datos XML, SVG

Exportacion PDF, DXF, etc.

Video

Redes

Comunicacion serial

External Contributions

Sonido: Ess, Sonia

Computer Vision: JMyron, ReacTIVision,BlobDetection

Interface: proCONTROLL, Interfascia

. . .

,J.B. Hayet Processing-Python Mode, Julio 2015 7 / 20

Page 8: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Tres maneras de programar en Python (con el Python Mode)

Modo basico (dibujos estaticos, codigo secuencial).

Modo continuo (animacion, funciones).

Modo objeto (clases Python).

Se puede adaptar a la audiencia. . .

,J.B. Hayet Processing-Python Mode, Julio 2015 8 / 20

Page 9: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Modo basico, programacion imperativa

s i z e (512 ,512)background (255)noSt roke ( )f o r i i n range ( 1 0 0 ) :

f i l l ( random (255) , random (255) , random (255 ) )x = random (512)y = random (512)r e c t ( x , y , 5 0 , 50 )

Ciclos, llamadas a funciones, variables. . .

,J.B. Hayet Processing-Python Mode, Julio 2015 9 / 20

Page 10: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Modo continuo, programacion procedural

de f s e tup ( ) :s i z e (729 ,729)background (255)noSt roke ( )f rameRate (1 )

de f draw ( ) :drawCross (0 , 0 , 729 )

,J.B. Hayet Processing-Python Mode, Julio 2015 10 / 20

Page 11: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Modo continuo, programacion procedural

de f drawCross ( x , y ,w ) :i f w<1:

returnf i l l ( random (255) , random (255) , random (255 ) )r e c t ( x+w/3 , y+w/3 ,w/3 ,w/3)r e c t ( x , y+w/3 ,w/3 ,w/3)r e c t ( x+2∗w/3 , y+w/3 ,w/3 ,w/3)r e c t ( x+w/3 , y ,w/3 ,w/3)r e c t ( x+w/3 , y+2∗w/3 ,w/3 ,w/3)drawCross ( x , y ,w/3)drawCross ( x+2∗w/3 , y ,w/3)drawCross ( x , y+2∗w/3 ,w/3)drawCross ( x+2∗w/3 , y+2∗w/3 ,w/3)

Funciones, recursiones. . .,

J.B. Hayet Processing-Python Mode, Julio 2015 11 / 20

Page 12: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Modo continuo, programacion proceduralDos funciones invocadas por default:

setup() : al crear la ventana,

draw() : funcion de dibujo llamada en cada ciclo (frecuenciaadaptable. . . )

Simulacion dinamica. . .

,J.B. Hayet Processing-Python Mode, Julio 2015 12 / 20

Page 13: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Modo continuo, programacion procedural+ Handlers para eventos de raton, teclados. . .

mousePressed()

mouseReleased()

mouseMoved()

keyPressed()

...

Variables globales mouseX, mouseY, pmouseX, pmouseY. . .

,J.B. Hayet Processing-Python Mode, Julio 2015 13 / 20

Page 14: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Modo objeto: programacion orientada a objetos, clases. . .

Usar la applet de Processing en otro programa. . .

Usaremos clases en los talleres de robotica.

,J.B. Hayet Processing-Python Mode, Julio 2015 14 / 20

Page 15: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Varios modos de programacion

Implicit data types (int, float, boolean)

Arrays

Loops

Conditionals and Logical Operators

Strings

Variables and Scoping

,J.B. Hayet Processing-Python Mode, Julio 2015 15 / 20

Page 16: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Graficos

Es lo mas interesante del lenguaje:

se encarga de toda la parte generalmente tecnicamente delicadade inicializacion integrando varias modalidades graficas pordefault (2D, 3D, OpenGL. . . ),

muy facil de crear animaciones, visualizaciones dinamicas aunpara debutante,

graficos, sonidos, animacion son al centro del concepto.

,J.B. Hayet Processing-Python Mode, Julio 2015 16 / 20

Page 17: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Graficos

,J.B. Hayet Processing-Python Mode, Julio 2015 17 / 20

Page 18: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Graficos

Modo 2D

de f s e tup ( ) :s i z e (320 , 240)background (153)

de f draw ( ) :l i n e (0 , 0 , width , h e i g h t )

,J.B. Hayet Processing-Python Mode, Julio 2015 18 / 20

Page 19: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Graficos

Modo P3D

de f s e tup ( ) :s i z e (320 , 240 , P3D)

de f draw ( ) :background (0 )s t r o k e (255 ,0 , 0 )t r a n s l a t e ( width /2 , h e i g h t /2)ro ta t eX ( cos ( frameCount ∗ PI / 300))l i n e (0 , 0 , 0 , width , he i gh t , −200)l i n e (0 , 0 , 0,−width , he i gh t , −200)l i n e ( width , he i gh t , −200,−width , he i gh t , −200)

,J.B. Hayet Processing-Python Mode, Julio 2015 19 / 20

Page 20: Programar con Processing en Pythonaplicaciones.cimat.mx/Personal/sites/default/files/jbhayet/files/... · Programar con Processing en Python J.B. Hayet CENTRO DE INVESTIGACION EN

Features adicionales

Soporte para imagenes.Soporte para manejo de vıdeo.Unos esfuerzos para portar el OpenCV a Processinghttps://github.com/atduskgreg/opencv-processing

,J.B. Hayet Processing-Python Mode, Julio 2015 20 / 20