1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
# -*- coding: utf-8 -*-
import sys
from random import randint
from PyQt4 import QtGui, QtCore
###################
### VARIABLES ###
###################
tabDes = [1]*600
x=0
tabNbreNoyaux=[600]
###############################################
### Fonctions utilisées dans le programme ###
###############################################
# METHODES
def remplir(tabDes) :
for i in range (0,len(tabDes)):
if tabDes[i]!=0:
tabDes[i]=randint(1,6)
return tabDes
def remplacer6(tabDes) :
for i in range (0,len(tabDes)):
if (tabDes[i]==6) :
tabDes[i]=0
def nombreNoyaux():
tabNbreNoyaux.append(600-tabDes.count(0))
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.resize(460, 610)
self.central = QtGui.QWidget()
self.topLayout = QtGui.QGridLayout(self.central)
self.viewer = QtGui.QGraphicsView(self.central)
self.topLayout.addWidget(self.viewer)
self.scene = QtGui.QGraphicsScene()
self.viewer.setScene(self.scene)
self.setCentralWidget(self.central)
def set_graphics(self, values):
self.create_background()
self.draw_curve(values)
pix = QtGui.QPixmap.fromImage(self.background)
self.scene.clear()
self.scene.setSceneRect(0, 0, 450, 650)
self.scene.addPixmap(pix)
def draw_curve(self, data):
color = QtGui.QColor(250, 50, 50, 255)
painter = QtGui.QPainter()
painter.begin(self.background)
path = QtGui.QPainterPath()
x = 10
path.moveTo(x, 0)
for dat in data:
x += 10
path.lineTo(x, 600 - dat)
painter.setPen(QtGui.QPen(color, 2,
QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
QtCore.Qt.MiterJoin))
painter.drawPath(path)
painter.end()
def create_background(self):
self.background = QtGui.QImage(QtCore.QSize(450, 650),
QtGui.QImage.Format_ARGB32_Premultiplied)
self.background.fill(QtGui.QColor(0, 0, 0, 255))
if __name__ == '__main__':
while tabDes.count(0)!=600:
remplir(tabDes)
remplacer6(tabDes)
nombreNoyaux()
x=x+1
app = QtGui.QApplication(sys.argv)
win = MainWindow()
win.set_graphics(tabNbreNoyaux)
win.show()
sys.exit(app.exec_()) |
Partager