Created
April 12, 2012 23:56
-
-
Save adam-davis/2371988 to your computer and use it in GitHub Desktop.
A negative filter brush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void FilterBrush::mouseMoveEvent(QMouseEvent* event, PaintArea *ourImage) | |
{ | |
QImage* qImage = ourImage->getImage(); | |
int xCenter = event->pos().x(), yCenter = event->pos().y() , radius = 35; | |
int left = xCenter - radius; | |
int right = left + radius * 2; | |
int top = yCenter - radius; | |
int bottom = top + radius * 2; | |
char *x, *y; | |
x = new char(); | |
y = new char(); | |
for (int yPos = Top; yPos <= Bottom; ++yPos) | |
{ | |
for (int xPos = Left; xPos <= Right; ++xPos) | |
{ | |
double dist = pow(xCenter - xPos, 2.0) + pow(yCenter - yPos, 2.0); | |
if (dist <= pow(radius, 2.0)) | |
{ | |
itoa(xPos, x, 10); | |
itoa(yPos, y,10); | |
if(this->pixels.find(*x+"w"+*y) != this->pixels.end()) | |
continue; | |
this->pixels[*x+"w"+*y] = new QPoint(xPos, yPos); | |
QRgb color = yup->pixel(xPos, yPos); | |
QColor edit(color); | |
int red = 255 - edit.red(); | |
int blue = 255 - edit.blue(); | |
int green = 255 - edit.green(); | |
color = qRgb(red, green, blue); | |
yup->setPixel(xPos, yPos,color); | |
} | |
ourImage->update(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What started off as an error quickly becomes understood and evolves into a neat feature!
You get a star!