summaryrefslogtreecommitdiff
path: root/src/game/EllipseBrush.h
blob: 9a75dfb56beb19b3acaeacaec933115a3be8274f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * ElipseBrush.h
 *
 *  Created on: Jan 26, 2012
 *      Author: Simon
 */

#ifndef ELIPSEBRUSH_H_
#define ELIPSEBRUSH_H_

#include <cmath>
#include "Brush.h"

class EllipseBrush: public Brush
{
public:
	EllipseBrush(ui::Point size_):
		Brush(size_)
	{
		SetRadius(size_);
	};
	virtual void GenerateBitmap()
	{
		if(bitmap)
			delete[] bitmap;
		bitmap = new unsigned char[size.X*size.Y];
		int rx = radius.X;
		int ry = radius.Y;
		for(int x = 0; x <= radius.X*2; x++)
		{
			for(int y = 0; y <= radius.Y*2; y++)
			{
				if((pow(x-radius.X,2.0f)*pow(ry,2.0f)+pow(y-radius.Y,2.0f)*pow(rx,2.0f)<=pow(rx,2.0f)*pow(ry,2.0f)))
				{
					bitmap[y*(size.X)+x] = 255;
				}
				else
				{
					bitmap[y*(size.X)+x] = 0;
				}
			}
		}
	}
};

#endif /* ELIPSEBRUSH_H_ */