Home>

There is a site where rectangles are located.

You need to find out their color and output to the console as RGB .

Example site:

An example of what should appear in the console (design does not matter):

What are the exact inputs?

andreymal2021-09-25 23:58:23
  • Answer # 1

    Since I like doing everything in PyQt5, I'll demonstrate to you how would i do it.

    If you haven't installed PyQt5 yet, I highly recommend it.

    PyQt is an implementation of the Qt framework for the Python language.

    pip install PyQt5
    pip install pyqt5-tools
    

    Now runpython main.py, click on the eyedropper and move across the screen, to the console we get the result.


    main.py

    from PyQt5.QtCore import QByteArray, Qt, QRectF, QLineF, pyqtSignal, QTimer
    from PyQt5.QtGui import (QFontDatabase, QFont, QPainter,
                             QPainterPath, QColor, QPen)
    from PyQt5.QtWidgets import (QPushButton, QApplication, QWidget,
                                 QDialog, QVBoxLayout)
    FONT= b'AAEAAAALAIAAAwAwR1NVQrD + s + 0AAAE4AAAAQk9TLzI9eEj0AAABfAAAAFZjbWFw6Cq4sAAAAdwAAAFwZ2x5ZhP0dwUAAANUAAAA8GhlYWQU7DSZAAAA4AAAADZoaGVhB94DgwAAALwAAAAkaG10eAgAAAAAAAHUAAAACGxvY2EAeAAAAAADTAAAAAZtYXhwAQ8AWAAAARgAAAAgbmFtZT5U /n0AAAREAAACbXBvc3Ta6Gh9AAAGtAAAADAAAQAAA4D /gABcBAAAAAAABAAAAQAAAAAAAAAAAAAAAAAAAAIAAQAAAAEAAAn6lORfDzz1AAsEAAAAAADY5nhOAAAAANjmeE4AAP /ABAADQAAAAAgAAgAAAAAAAAABAAAAAgBMAAMAAAAAAAIAAAAKAAoAAAD /AAAAAAAAAAEAAAAKAB4ALAABREZMVAAIAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAAAAQQAAZAABQAIAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wLnAgOA /4AAXAOAAIAAAAABAAAAAAAABAAAAAQAAAAAAAAFAAAAAwAAACwAA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MAAQQJAAYAEAEDAAMAAQQJAAoAVgETAAMAAQQJAAsAJgFpCkNyZWF0ZWQgYnkgaWNvbmZvbnQKaWNvbmZvbnRSZWd1bGFyaWNvbmZvbnRpY29uZm9udFZlcnNpb24gMS4waWNvbmZvbnRHZW5lcmF0ZWQgYnkgc3ZnMnR0ZiBmcm9tIEZvbnRlbGxvIHByb2plY3QuaHR0cDovL2ZvbnRlbGxvLmNvbQAKAEMAcgBlAGEAdABlAGQAIABiAHkAIABpAGMAbwBuAGYAbwBuAHQACgBpAGM AbwBuAGYAbwBuAHQAUgBlAGcAdQBsAGEAcgBpAGMAbwBuAGYAbwBuAHQAaQBjAG8AbgBmAG8AbgB0AFYAZQByAHMAaQBvAG4AIAAxAC4AMABpAGMAbwBuAGYAbwBuAHQARwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABzAHYAZwAyAHQAdABmACAAZgByAG8AbQAgAEYAbwBuAHQAZQBsAGwAbwAgAHAAcgBvAGoAZQBjAHQALgBoAHQAdABwADoALwAvAGYAbwBuAHQAZQBsAGwAbwAuAGMAbwBtAAAAAAIAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgECAQMABnhpZ3VhbgAA '
    class ScaleWindow (QWidget):
        # Enlarged viewport
        def __init __ (self, * args, ** kwargs):
            super (ScaleWindow, self) .__ init __ (* args, ** kwargs)
            self.setWindowFlags (Qt.Tool |
                                Qt.FramelessWindowHint |
                                Qt.WindowStaysOnTopHint)
            self.setAttribute (Qt.WA_TranslucentBackground, True)
            self.resize (1, 1)
            self.move (1, 1)
            self._image= None
        def updateImage (self, pos, image):
            self._image= image
            self.resize (image.size ())
            self.move (pos.x () + 10, pos.y () + 10)
            self.show ()
            self.update ()
        def paintEvent (self, event):
            super (ScaleWindow, self) .paintEvent (event)
            if self._image:
                painter= QPainter (self)
                painter.setRenderHint (QPainter.Antialiasing, True)path= QPainterPath () radius= min (self.width (), self.height ()) /2
                path.addRoundedRect (QRectF (self.rect ()), radius, radius)
                painter.setClipPath (path)
                # image
                painter.drawImage (self.rect (), self._image)
                # Medium blue crosshair
                painter.setPen (QPen (QColor (0, 174, 255), 3))
                hw= self.width () /2
                hh= self.height () /2
                painter.drawLines (
                    QLineF (hw, 0, hw, self.height ()),
                    QLineF (0, hh, self.width (), hh)
                )
                # frame
                painter.setPen (QPen (Qt.white, 3))
                painter.drawRoundedRect (self.rect (), radius, radius)
    class CColorStraw (QPushButton):
        colorChanged= pyqtSignal (QColor)
        def __init __ (self, parent):
            super (CColorStraw, self) .__ init __ (parent)
            # Uploading fonts to the font library
            QFontDatabase.addApplicationFontFromData (QByteArray.fromBase64 (FONT))
            font= self.font () or QFont ()
            font.setFamily ('iconfont')
            self.setFont (font)
            self.setText ('')
            self.setToolTip ('Draw screen color')
            self._scaleWindow= ScaleWindow ()
            # Don't forget to show it first and then hide it.
            self._scaleWindow.show ()
            self._scaleWindow.hide ()
        def closeEvent (self, event):
            self._scaleWindow.close ()
            super (CColorStraw, self) .closeEvent (event)
        def mousePressEvent (self, event):
            super (CColorStraw, self) .mousePressEvent (event)
            # Set mouse style to cross
            self.setCursor (Qt.CrossCursor)
        def mouseReleaseEvent (self, event):
            super (CColorStraw, self) .mouseReleaseEvent (event)
            # Set mouse style to normal
            self.setCursor (Qt.ArrowCursor)
            self._scaleWindow.hide ()
        def mouseMoveEvent (self, event):
            super (CColorStraw, self) .mouseMoveEvent (event)
            # Get mouse position on screen
            pos= event.globalPos ()
            # Take part of the enlarged image
            image= QApplication.primaryScreen (). grabWindow (
                int (QApplication.desktop (). winId ()),
                pos.x () -6, pos.y () -6, 13, 13) .toImage ()
            color= image.pixelColor (6, 6)
            print (f'RGB color ->
     ({color.red ()},
     {color.green ()},
     {color.blue ()}) ')
            if color.isValid ():
                self.colorChanged.emit (color)
            self._scaleWindow.updateImage (pos, image.scaled (130, 130))
    if __name__== '__main__':
        import sys
        import cgitb
        sys.excepthook= cgitb.enable (1, None, 5, '')
        app= QApplication (sys.argv)
        w= QDialog ()
        layout= QVBoxLayout (w)
        view= CColorStraw (w)
        view.colorChanged.connect (lambda c: print (c.name ()))
        layout.addWidget (view)
        w.exec_ ()
        QTimer.singleShot (200, app.quit)
        sys.exit (app.exec_ ())
    
  • Answer # 2

    Since I like doing everything in PyQt5, I'll demonstrate to you how would i do it.

    If you haven't installed PyQt5 yet, I highly recommend it.

    PyQt is an implementation of the Qt framework for the Python language.

    pip install PyQt5
    pip install pyqt5-tools
    

    Now runpython main.py, click on the eyedropper and move across the screen, to the console we get the result.


    main.py

    from PyQt5.QtCore import QByteArray, Qt, QRectF, QLineF, pyqtSignal, QTimer
    from PyQt5.QtGui import (QFontDatabase, QFont, QPainter,
                             QPainterPath, QColor, QPen)
    from PyQt5.QtWidgets import (QPushButton, QApplication, QWidget,
                                 QDialog, QVBoxLayout)
    FONT= b'AAEAAAALAIAAAwAwR1NVQrD + s + 0AAAE4AAAAQk9TLzI9eEj0AAABfAAAAFZjbWFw6Cq4sAAAAdwAAAFwZ2x5ZhP0dwUAAANUAAAA8GhlYWQU7DSZAAAA4AAAADZoaGVhB94DgwAAALwAAAAkaG10eAgAAAAAAAHUAAAACGxvY2EAeAAAAAADTAAAAAZtYXhwAQ8AWAAAARgAAAAgbmFtZT5U /n0AAAREAAACbXBvc3Ta6Gh9AAAGtAAAADAAAQAAA4D /gABcBAAAAAAABAAAAQAAAAAAAAAAAAAAAAAAAAIAAQAAAAEAAAn6lORfDzz1AAsEAAAAAADY5nhOAAAAANjmeE4AAP /ABAADQAAAAAgAAgAAAAAAAAABAAAAAgBMAAMAAAAAAAIAAAAKAAoAAAD /AAAAAAAAAAEAAAAKAB4ALAABREZMVAAIAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAAAAQQAAZAABQAIAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5wLnAgOA /4AAXAOAAIAAAAABAA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AAMAAQQJAAQAEADdAAMAAQQJAAUAFgDtAAMAAQQJAAYAEAEDAAMAAQQJAAoAVgETAAMAAQQJAAsAJgFpCkNyZWF0ZWQgYnkgaWNvbmZvbnQKaWNvbmZvbnRSZWd1bGFyaWNvbmZvbnRpY29uZm9udFZlcnNpb24gMS4waWNvbmZvbnRHZW5lcmF0ZWQgYnkgc3ZnMnR0ZiBmcm9tIEZvbnRlbGxvIHByb2plY3QuaHR0cDovL2ZvbnRlbGxvLmNvbQAKAEMAcgBlAGEAdABlAGQAIABiAHkAIABpAGMAbwBuAGYAbwBuAHQACgBpAGM AbwBuAGYAbwBuAHQAUgBlAGcAdQBsAGEAcgBpAGMAbwBuAGYAbwBuAHQAaQBjAG8AbgBmAG8AbgB0AFYAZQByAHMAaQBvAG4AIAAxAC4AMABpAGMAbwBuAGYAbwBuAHQARwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABzAHYAZwAyAHQAdABmACAAZgByAG8AbQAgAEYAbwBuAHQAZQBsAGwAbwAgAHAAcgBvAGoAZQBjAHQALgBoAHQAdABwADoALwAvAGYAbwBuAHQAZQBsAGwAbwAuAGMAbwBtAAAAAAIAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgECAQMABnhpZ3VhbgAA '
    class ScaleWindow (QWidget):
        # Enlarged viewport
        def __init __ (self, * args, ** kwargs):
            super (ScaleWindow, self) .__ init __ (* args, ** kwargs)
            self.setWindowFlags (Qt.Tool |
                                Qt.FramelessWindowHint |
                                Qt.WindowStaysOnTopHint)
            self.setAttribute (Qt.WA_TranslucentBackground, True)
            self.resize (1, 1)
            self.move (1, 1)
            self._image= None
        def updateImage (self, pos, image):
            self._image= image
            self.resize (image.size ())
            self.move (pos.x () + 10, pos.y () + 10)
            self.show ()
            self.update ()
        def paintEvent (self, event):
            super (ScaleWindow, self) .paintEvent (event)
            if self._image:
                painter= QPainter (self)
                painter.setRenderHint (QPainter.Antialiasing, True)path= QPainterPath () radius= min (self.width (), self.height ()) /2
                path.addRoundedRect (QRectF (self.rect ()), radius, radius)
                painter.setClipPath (path)
                # image
                painter.drawImage (self.rect (), self._image)
                # Medium blue crosshair
                painter.setPen (QPen (QColor (0, 174, 255), 3))
                hw= self.width () /2
                hh= self.height () /2
                painter.drawLines (
                    QLineF (hw, 0, hw, self.height ()),
                    QLineF (0, hh, self.width (), hh)
                )
                # frame
                painter.setPen (QPen (Qt.white, 3))
                painter.drawRoundedRect (self.rect (), radius, radius)
    class CColorStraw (QPushButton):
        colorChanged= pyqtSignal (QColor)
        def __init __ (self, parent):
            super (CColorStraw, self) .__ init __ (parent)
            # Uploading fonts to the font library
            QFontDatabase.addApplicationFontFromData (QByteArray.fromBase64 (FONT))
            font= self.font () or QFont ()
            font.setFamily ('iconfont')
            self.setFont (font)
            self.setText ('')
            self.setToolTip ('Draw screen color')
            self._scaleWindow= ScaleWindow ()
            # Don't forget to show it first and then hide it.
            self._scaleWindow.show ()
            self._scaleWindow.hide ()
        def closeEvent (self, event):
            self._scaleWindow.close ()
            super (CColorStraw, self) .closeEvent (event)
        def mousePressEvent (self, event):
            super (CColorStraw, self) .mousePressEvent (event)
            # Set mouse style to cross
            self.setCursor (Qt.CrossCursor)
        def mouseReleaseEvent (self, event):
            super (CColorStraw, self) .mouseReleaseEvent (event)
            # Set mouse style to normal
            self.setCursor (Qt.ArrowCursor)
            self._scaleWindow.hide ()
        def mouseMoveEvent (self, event):
            super (CColorStraw, self) .mouseMoveEvent (event)
            # Get mouse position on screen
            pos= event.globalPos ()
            # Take part of the enlarged image
            image= QApplication.primaryScreen (). grabWindow (
                int (QApplication.desktop (). winId ()),
                pos.x () -6, pos.y () -6, 13, 13) .toImage ()
            color= image.pixelColor (6, 6)
            print (f'RGB color ->
     ({color.red ()},
     {color.green ()},
     {color.blue ()}) ')
            if color.isValid ():
                self.colorChanged.emit (color)
            self._scaleWindow.updateImage (pos, image.scaled (130, 130))
    if __name__== '__main__':
        import sys
        import cgitb
        sys.excepthook= cgitb.enable (1, None, 5, '')
        app= QApplication (sys.argv)
        w= QDialog ()
        layout= QVBoxLayout (w)
        view= CColorStraw (w)
        view.colorChanged.connect (lambda c: print (c.name ()))
        layout.addWidget (view)
        w.exec_ ()
        QTimer.singleShot (200, app.quit)
        sys.exit (app.exec_ ())