Skip to content

Commit

Permalink
the basic finished version
Browse files Browse the repository at this point in the history
  • Loading branch information
sinofool committed Nov 11, 2013
1 parent 4dd8a27 commit c5f5033
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
@@ -1,8 +1,8 @@

CPP=g++

CXXFLAGS=`Magick++-config --cppflags`
LDFLAGS=`Magick++-config --ldflags`
CXXFLAGS=`Magick++-config --cflags --cppflags`
LDFLAGS=`Magick++-config --ldflags --libs`

.PHONY: all
.PHONY: clean
Expand Down
49 changes: 49 additions & 0 deletions src/main/cpp/captcha.hpp
@@ -1,6 +1,7 @@
#include <Magick++.h>
#include <string>
#include <stdio.h>
#include <sstream>

struct rgb {
rgb(uint16_t red, uint16_t green, uint16_t blue) :
Expand All @@ -19,13 +20,15 @@ using Magick::Drawable;
using Magick::DrawableText;
using Magick::DrawableGravity;
using Magick::CenterGravity;
using Magick::NorthWestGravity;
using Magick::DrawableFont;
using Magick::DrawablePointSize;
using Magick::DrawableRotation;
using Magick::DrawableStrokeColor;
using Magick::DrawableFillColor;
using Magick::NormalStyle;
using Magick::NormalStretch;
using Magick::PolynomialDistortion;

class background {
public:
Expand Down Expand Up @@ -85,10 +88,56 @@ class text {
Image* _img;
};

class mathadd {
public:
mathadd(int a, int b, int x, int y, rgb rgb) :
_a(a), _b(b), _x(x), _y(y), _rgb(rgb) {
}
template<typename T> mathadd* merge(T old) {
this->_img = old->img();
std::list<Drawable> txt;
txt.push_back(DrawableGravity(NorthWestGravity));
txt.push_back(DrawablePointSize(25));
txt.push_back(DrawableStrokeColor(Color(_rgb.r, _rgb.g, _rgb.b)));
txt.push_back(DrawableFillColor(Color(_rgb.r, _rgb.g, _rgb.b, 0)));
std::ostringstream text;
text << "Please solve: " << std::endl << _a << "+" << _b << "=?";
txt.push_back(DrawableText(_x, _y, text.str()));
_img->draw(txt);
return this;
}

Image* img() {
return _img;
}
private:
int _a;
int _b;
int _x;
int _y;
rgb _rgb;
Image* _img;
};
class distorting {
public:
template<typename T> distorting* merge(T old) {
this->_img = old->img();
double arr[] = {2,
0.5, 0.5, 8.5, 7.5,
16.5, 0.5, 20.5, 5.5,
32.5, 0.5, 33.5, 3.5,
48.5, 0.5, 48.5, 1.5,
64.5, 0.5, 64.5, 1.5,
80.5, 0.5, 80.5, 1.5,
96.5, 0.5, 95.5, 3.5,
112.5, 0.5, 109.5, 5.5,
128.5, 0.5, 121.5, 7.5,
0, 0, 0, 0,
300, 200, 300, 200,
300, 0, 300, 0,
0, 200, 0, 200,
};
_img->distort(PolynomialDistortion, sizeof(arr)/sizeof(double), arr, false);
return this;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/cpp/main.cpp
Expand Up @@ -7,9 +7,10 @@ int main() {

background bg(300, 200, rgb(0x0000, 0xF000, 0x0000));
text text("Hello", "./au.ttf", 50, 1, 0, 0, rgb(0x0000, 0x0000, 0xF000));
mathadd mathadd(3, 5, 0, 0, rgb(0x0000, 0x0000, 0xF000));
distorting distorting;
save save("background.png");
save.merge(distorting.merge(text.merge(bg.merge(NULL))));
save.merge(distorting.merge(mathadd.merge(bg.merge(NULL))));

return 0;
}
Empty file removed src/main/cpp/noise.h
Empty file.

0 comments on commit c5f5033

Please sign in to comment.