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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#include <iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<fstream>
#include<sstream>
#include <iomanip>
#define PI 3.14159265
int scr[216][216];
using namespace std;
int function (int scr[216][216], double x1,double y1,double x2,double y2,double teta);
//void function (int scr[1296][1296],int);
//void function (int x1,int y1,int x2,int y2,int teta);
int main() {
double x,y,x1,x2,y1,y2,teta,alpha;
int p,q;
ofstream myfile;
myfile.open("pic kock program6.pgm");
myfile<< "P2\n";
myfile<< "# Shows the word (example from Netpbm main page on ";
myfile<< "PGM)\n";
myfile<< "216 216 \n";
myfile<< "15\n";
x1=10;
y1=10;
x2=200;
y2=10;
alpha=0;// the angle between first line and horizental axis
teta=0;
int i=0,j=0;
for(j=0;j<216;j++)
for(i=0;i<216;i++)
scr[j][i]=0; // clears whole screen
scr=function(scr,x1,y1,x2,y2,teta);
for(i=0;i<216;i++)
{
myfile<<"\n";
for(j=0;j<216;j++)
myfile<<scr[i][j]<<" ";
}
myfile.close();
return 0;
}
int function (double x1,double y1,double x2,double y2,double teta)
{
double x,y,alpha;
int p,q,i,j;
for (i=0 ;i<(floor((x2-x1)/3)); i++) {
j=i* tan(teta*PI/180);
p= floor(y1+j);
q=floor(x1+i);
scr[p][q]=15;
}
for (i=floor(2*(x2-x1)/3) ;i<floor(x2-x1); i++) {
j=i* tan(teta*PI/180);
p=floor(y1+j);
q=floor(x1+i);
scr[p][q]=15;
}
for (i=0 ;i<floor((x2-x1)/3); i++)
{
j=i* tan(teta*PI/180);
x=i*cos((60+teta)*PI/180)-j*sin((60+teta)*PI/180);
y=i*sin((60+teta)*PI/180)-j*cos((60+teta)*PI/180);
p=floor(y1+y);
q=floor(x+x1+(x2-x1)/3);
scr[p][q]=15;
}
for (i=0 ;i<floor((x2-x1)/3); i++)
{
j=i* tan(teta*PI/180);
x=i*cos((120+teta)*PI/180)-j*sin((120+teta)*PI/180);
y=i*sin((120+teta)*PI/180)-j*cos((120+teta)*PI/180);
p=floor(y+y1);
q=floor(x+x1+2*(x2-x1)/3);
scr[p][q]=15;
}
return scr[216][216];
}
|