Table of Contents

Actividad 5. Python, objectos, matrices, gráficos, acceso a mouse.

En esta actividad se practicarán conceptos asociados a programación en python.

Preguntas de la actividad

Temas tentativos a cubrir

Instrucciones

#!/usr/bin/env python

class Matrix(object):
    def __init__(self, data, shape):
        print "Initializing object"
        self.data=data
        self.shape=shape

    def imprimir(self):
        for i in xrange(self.shape[0]):
            print self.data[self.shape[1]*i:self.shape[1]*(i+1)]
        print "good bye"

    def add(self, o_matrix):
        result=Matrix(self.data, self.shape)
        for i in xrange(self.shape[0]):
            for j in xrange(self.shape[1]):
                result.data[i*result.shape[1]+j]=self.data[i*self.shape[1]+j]+o_matrix.data[i*o_matrix.shape[1]+j]
        return(result)

    def __len__(self):
        return(self.shape[0]*self.shape[1])

def main():
    data=[1,2,3,4,5,6,7,8,9,10,11,12]
    shape=(4,3)
    matrix1=Matrix(data, shape)
    matrix1.imprimir()
    data2=[1]*shape[0]*shape[1]
    data2=range(12)
    data2.reverse()
    matrix2=Matrix(data2, shape)
    matrix2.imprimir()
    matrix3=matrix1.add(matrix2)
    matrix3.imprimir()
    print len(matrix3)

if __name__=="__main__":
    main()

Python QT

sudo apt-get install libqt4-dev   qt4-dev-tools python-qt4-dev pyqt4-dev-tools libtclap-dev
import sys
from PyQt4 import QtGui,QtCore
app=QtGui.QApplication(sys.argv)
main_widget=QtGui.QWidget()
button=QtGui.QPushButton("test", main_widget)
main_widget.show()
main_widget.setWindowTitle("test application")
def testprint():
   print "Works"
QtCore.QObject.connect(button,QtCore.SIGNAL("clicked()"),testprint)
sys.exit(app.exec_())

Simulador de fuerzas

Evaluación

Se evaluará el visualizador de posición de mouse, con tres grados de libertad (DOFs), usando los movimientos en x, y y “scroll” del mouse (3 ejes, o 3D).

~~DISCUSSION~~