1

Тема: PyQt4 малює не те

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import pyqtSlot

class Example(QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.gx=1
        self.gy=0
        self.lbl=QLabel()
        self.tlb = None
        self.image = QImage(512, 512, QImage.Format_RGB32)
        self.hbox = QHBoxLayout()
        self.pixmap = QPixmap()
        self.length = 1
        self.initUI()
        
    def mousePressEvent(self, QMouseEvent):
        px = QMouseEvent.pos().x()
        py = QMouseEvent.pos().y()

        size = self.frameSize()

        self.gx = px-size.width()/2
        self.gy = py-size.height()/2

        h = (self.gx**2+self.gy**2)**0.5

        self.gx/=h
        self.gy/=h

        #self.gx*=self.length
        #self.gy*=self.length

        self.fillImage()

    def wheelEvent(self,event):
        self.length+=(event.delta()*0.001)
        print(self.length)


    def initUI(self):    
        self.hbox = QHBoxLayout(self)
        self.pixmap = QPixmap()
        self.move(300, 200)
        self.setWindowTitle('Red Rock')
        
        self.addedWidget = None

        self.fillImage()

        self.setLayout(self.hbox)
        
        self.show()  

    def fillImage(self):
        for x in range(0, 512):
            t = -1+(x/512)*2
            color =  (1 - (3 - 2*abs(t))*t**2) 

            for y in range(0, 512):
                
                t1 = -1+(y/512)*2
                color1 = (1 - (3 - 2*abs(t1))*t1**2)
                result = (255/2)+(color * color1 * (t*self.gx+t1*self.gy) )*(255/2)
                result = (t*self.gx+t1*self.gy)*(255.0)

                self.image.setPixel(x, y, qRgb(result, result, result))

        
        self.pixmap = self.pixmap.fromImage(self.image)

        if self.lbl == None:
            self.lbl = QLabel(self)
        else:
            self.lbl.setPixmap(self.pixmap)

        if self.addedWidget == None:
            self.hbox.addWidget(self.lbl)
            self.addedWidget = True

        if self.tlb==None:
            self.tlb = QLabel(str(self.gx)+" : "+str(self.gy), self)
            self.tlb.move(12,3)
        else:
            self.tlb.setText(str(self.gx)+" : "+str(self.gy))
        
        self.repaint()
        self.update()


def main():
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()    

чому воно малює два градієнти, коли

result = (t*self.gx+t1*self.gy)*(255.0)

змінюється від -255 до 255 ?
має ж бути один градієнт, з повністю чорною першою половиною
http://puu.sh/vYP2s/f0813bd07d.png

All you want is a dingle,
What you envy's a schwang,
A thing through which you can tinkle,
Or play with, or simply let hang...

2

Re: PyQt4 малює не те

Тому що https://uk.wikipedia.org/wiki/Доповняльний_код

Подякували: FakiNyan1