Skip to content

Instantly share code, notes, and snippets.

@adam-davis
Created April 12, 2012 23:56
Show Gist options
  • Save adam-davis/2371988 to your computer and use it in GitHub Desktop.
Save adam-davis/2371988 to your computer and use it in GitHub Desktop.
A negative filter brush
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();
}
}
}
@jbaiera
Copy link

jbaiera commented Apr 17, 2012

What started off as an error quickly becomes understood and evolves into a neat feature!

You get a star!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment