Skip to content

Commit

Permalink
polygon brush and its scattered version
Browse files Browse the repository at this point in the history
  • Loading branch information
dipsywong98 committed Feb 28, 2019
1 parent 77ba7a7 commit b1796d1
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ImpBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ enum
BLUR_BRUSH,
SHARPEN_BRUSH,
PIXELIZE_BRUSH,
POLYGON_BRUSH,
SCATTERED_POLYGON_BRUSH,
NUM_BRUSH_TYPE // Make sure this stays at the end!
};

Expand Down
5 changes: 5 additions & 0 deletions ImpressionistDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Bayesian.h"
#include "KernelBrush.h"
#include "PixelizeBrush.h"
#include "PolygonBrush.h"

#define DESTROY(p) { if ((p)!=NULL) {delete [] p; p=NULL; } }

Expand Down Expand Up @@ -75,6 +76,10 @@ ImpressionistDoc::ImpressionistDoc()
= new KernelBrush( this, "Sharpen Brush" );
ImpBrush::c_pBrushes[PIXELIZE_BRUSH]
= new PixelizeBrush( this, "Pixelize Brush" );
ImpBrush::c_pBrushes[POLYGON_BRUSH]
= new PolygonBrush( this, "Polygon Brush" );
ImpBrush::c_pBrushes[SCATTERED_POLYGON_BRUSH]
= new PolygonBrush( this, "Polygon Brush", true );

std::vector<std::vector<float>> blurKernel = {
{1,2,1},
Expand Down
2 changes: 2 additions & 0 deletions ImpressionistUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ Fl_Menu_Item ImpressionistUI::brushTypeMenu[NUM_BRUSH_TYPE + 1] = {
{ "Blur Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)BLUR_BRUSH },
{ "Sharpen Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)SHARPEN_BRUSH },
{ "Pixelize Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)PIXELIZE_BRUSH },
{ "Polygon Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)POLYGON_BRUSH },
{ "Scattered Polygon Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)SCATTERED_POLYGON_BRUSH },
{ 0 }
};

Expand Down
88 changes: 88 additions & 0 deletions PolygonBrush.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "PolygonBrush.h"
//
// PolygonBrush.cpp
//
// The implementation of Line Brush. It is a kind of ImpBrush. All your brush implementations
// will look like the file with the different GL primitive calls.
//

#include "impressionistDoc.h"
#include "impressionistUI.h"
#include <ostream>
#include <iostream>

extern float frand();
extern int irand(int max);
extern double degToRad(double);

PolygonBrush::PolygonBrush(ImpressionistDoc* pDoc, char* name,bool scattered) :
ImpBrush(pDoc, name),scattered(scattered)
{
}
void PolygonBrush::BrushBegin(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;

BrushMove(source, target);
}

void PolygonBrush::BrushMove(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;

if (pDoc == NULL) {
printf("PolygonBrush::BrushMove document is NULL\n");
return;
}

if (source.x > pDoc->m_nPaintWidth || source.y < 0)
{
return;
}

int size = pDoc->getSize();
if(!scattered)
{
SetColor(source);
DrawPolygon(target, size,nSides?nSides: irand(10));
}else
{
for (int i = 0; i < 0.3*irand(size); i++)
{
const double dx = -size / 2.f + irand(size);
const double dy = -size / 2.f + irand(size);
const Point sourcePt(source.x + dx, source.y + dy);
const Point targetPt(target.x + dx, target.y + dy);
if (sourcePt.x > pDoc->m_nPaintWidth || sourcePt.y < 0)
{
continue;
}
SetColor(sourcePt);
DrawPolygon(targetPt, size, nSides ? nSides : irand(10));
}
}
}

void PolygonBrush::BrushEnd(const Point source, const Point target)
{
}

void PolygonBrush::DrawPolygon(const Point target, int size, int nSides)
{
glBegin(GL_POLYGON);
if (nSides < 3)nSides = 3;
double incre = 360.f / nSides;
int offset = irand(360);
for (double i = 0; i < 360; i+=incre)
{
double rad = degToRad(i + offset);
glVertex2f(
static_cast<GLfloat>(target.x) + cos(rad)*size / 2.f,
static_cast<GLfloat>(target.y) + sin(rad)*size / 2.f
);
}

glEnd();
}
18 changes: 18 additions & 0 deletions PolygonBrush.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "ImpBrush.h"
class PolygonBrush :
public ImpBrush
{
public:
PolygonBrush(ImpressionistDoc* pDoc = NULL, char* name = NULL, bool scattered = false);

void BrushBegin(const Point source, const Point target);
void BrushMove(const Point source, const Point target);
void BrushEnd(const Point source, const Point target);
void DrawPolygon(Point target, int size, int nSides);
char* BrushName(void);
PolygonBrush();
~PolygonBrush() = default;
bool scattered;
int nSides = 0;
};
2 changes: 2 additions & 0 deletions impressionist.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<ClCompile Include="Cluster.cpp" />
<ClCompile Include="CurvedBrush.cpp" />
<ClCompile Include="PixelizeBrush.cpp" />
<ClCompile Include="PolygonBrush.cpp" />
<ClCompile Include="PowerIter.cpp" />
<ClCompile Include="ImageUtils.cpp" />
<ClCompile Include="ImpBrush.cpp" />
Expand Down Expand Up @@ -178,6 +179,7 @@
<ClInclude Include="Cluster.h" />
<ClInclude Include="CurvedBrush.h" />
<ClInclude Include="PixelizeBrush.h" />
<ClInclude Include="PolygonBrush.h" />
<ClInclude Include="PowerIter.h" />
<ClInclude Include="ImageUtils.h" />
<ClInclude Include="ImpBrush.h" />
Expand Down
6 changes: 6 additions & 0 deletions impressionist.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
<ClCompile Include="PixelizeBrush.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PolygonBrush.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AlphaMapBrush.h">
Expand Down Expand Up @@ -188,5 +191,8 @@
<ClInclude Include="PixelizeBrush.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PolygonBrush.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Programming project 1 of HKUST Computer Graphics course COMP4411
- [x] (1W each) more brushes
- [ ] pattern brush
- [x] pixelize brush
- [ ] random polygon
- [X] random polygon
- [X] random scattered polygon
- [ ] clone brush
- [x] **(1W)** clipped bushes
- [x] **(1W)** cursor on original image
Expand Down

0 comments on commit b1796d1

Please sign in to comment.