Answer the question
In order to leave comments, you need to log in
How to determine scene pixel color in Qt?
There is an instance of the QGraphicsScene class . It creates instances of class TFish , inherited from QGraphicsItem . A timer has been started with a value of 0.003 seconds. Each time it expires, a signal is sent to the advance() slot , it is overridden for the TFish class, if it is not equal to 0, then according to a random algorithm, TFish instances "float".
The goal is to make it so that the TFish class determines the color of the pixel in front of itself, if it does not match the specified condition, then the direction of the TFish instance changes.
This has already been implemented to avoid collision with other TFish instances:
QList<QGraphicsItem *> dangerMice = scene()->items(QPolygonF()
<< mapToScene(0, 0)
<< mapToScene(-30, -50)
<< mapToScene(30, -50));
foreach (QGraphicsItem *item, dangerMice) {
if (item == this)
continue;
QLineF lineToMouse(QPointF(0, 0), mapFromItem(item, 0, 0));
qreal angleToMouse = ::acos(lineToMouse.dx() / lineToMouse.length());
if (lineToMouse.dy() < 0)
angleToMouse = TwoPi - angleToMouse;
angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
if (angleToMouse >= 0 && angleToMouse < Pi / 2) {
angle += 0.5;
} else if (angleToMouse <= TwoPi && angleToMouse > (TwoPi - Pi / 2)) {
angle -= 0.5;
}
}
Answer the question
In order to leave comments, you need to log in
Load the background into a separate area of memory and look for the color of the pixel in peace.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question