I wrote a c++ program in order to draw some shapes bit by bit. But I have difficulties in drawing circle. I couldn't give it's original shape. I think about finding any point on a circle by using the formulas,but i have two unknowns.
for ex: r^2=(x-a)^2-(y-b)^2
where:
x and y are the x,y coordinates for any point on the circle.
a and b are the x,y coordinates for the center of the circle.
r is the radius of the circle
I give the center cordinates,i have the radius... But there are two variables (x,y) which is unknown.How can i get points.
Here is the code that I work for other shapes:
Code:#include <iostream>
#include <fstream>
class BMP
{
public:
unsigned char header[1078];
unsigned char data[640][480];
BMP()
{
for(int i = 0; i<1078; i++)
header[i] = 0;
header[0] = 'B';
header[1] = 'M';
unsigned char* p = &header[2];
*(int*)(p) = 0x4b436;
p = &header[6];
*(int*)(p) = 0x0;
p = &header[10];
*(int*)(p) = 0x436;
p = &header[14];
*(int*)(p) = 0x28;
p = &header[18];
*(int*)(p) = 0x280;
p = &header[22];
*(int*)(p) = 0x1e0;
p = &header[26];
*(unsigned short*)(p) = 0x1;
p = &header[28];
*(unsigned short*)(p) = 0x8;
p = &header[30];
*(int*)(p) = 0x0;
p = &header[34];
*(int*)(p) = 0x4b000;
p = &header[38];
*(int*)(p) = 0x0;
p = &header[42];
*(int*)(p) = 0x0;
p = &header[46];
*(int*)(p) = 0x0;
p = &header[50];
*(int*)(p) = 0x0;
p = &header[54];
*(int*)(p) = 0x0;
p = &header[58];
*(int*)(p) = 0x800000;
p = &header[62];
*(int*)(p) = 0x8000;
p = &header[66];
*(int*)(p) = 0x808000;
p = &header[70];
*(int*)(p) = 0x80;
p = &header[74];
*(int*)(p) = 0x800080;
p = &header[78];
*(int*)(p) = 0x8080;
p = &header[82];
*(int*)(p) = 0x808080;
p = &header[86];
*(int*)(p) = 0xC0C0C0;
p = &header[90];
*(int*)(p) = 0xFF00000;
p = &header[94];
*(int*)(p) = 0xFF00;
p = &header[98];
*(int*)(p) = 0xFFFF00;
p = &header[102];
*(int*)(p) = 0xFF;
p = &header[106];
*(int*)(p) = 0xFF00FF;
p = &header[110];
*(int*)(p) = 0xFFFF;
p = &header[114];
*(int*)(p) = 0xFFFFFF;
for(int i= 0; i<640; i++)
for(int j= 0; j<480; j++)
data[i][j] = 15;
}
void save(const std::string str="");
void line(int x1, int y, int length, int color)
{
for(int i=x1;i<x1+length;i++)
data[i][y] = color;
}
void point(int x, int y, int color)
{
data[x][y] = color;
}
void rectangle(int x1, int x2, int y1, int y2,int color)
{
for(int i=x1;i<x2;i++)
data[i][y1] = color;
for(int y=y1;y<y2;y++)
data[x1][y] = color;
for(int i=x1;i<x2;i++)
data[i][y2] = color;
for(int y=y1;y<y2;y++)
data[x2][y] = color;
}
void square(int x1, int y1, int length,int color)
{
for(int i=x1;i<x1+length;i++)
data[i][y1] = color;
for(int y=y1;y<y1+length;y++)
data[x1][y] = color;
for(int i=x1;i<x1+length;i++)
data[i][y1+length] = color;
for(int y=y1;y<y1+length;y++)
data[x1+length][y] = color;
}
};
void BMP::save(const std::string str)
{
int i = 0;
std::ofstream f(str.c_str());
for(i = 0; i<1078; i++)
f<<header[i];
for(int i= 0; i<480; i++)
for(int j= 0; j<640; j++)
f<<data[j][i];
f.close();
}
int main()
{
BMP bitmap;
bitmap.line(100, 150, 150, 12);
bitmap.rectangle(200, 400, 200, 300,12);
bitmap.square(300, 50, 100,1);
bitmap.save("renk.bmp");
return 0;
}