-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel.cpp
More file actions
120 lines (114 loc) · 2.56 KB
/
pixel.cpp
File metadata and controls
120 lines (114 loc) · 2.56 KB
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
#include<iostream>
using namespace std;
class Pixel {
unsigned int iloc, jloc;
char mark;
public:
Pixel()
{
}
Pixel (int x,int y,char m) {
iloc = x;
jloc = y;
mark=m;
}
Pixel (Pixel &p) {
iloc = p.iloc;
jloc = p.jloc;
mark=p.mark;
}
~Pixel()
{}
int Get_x()
{
return iloc;
}
int Get_y()
{
return jloc;
}
char get_mark()
{
return mark;
}
void Change_mark(char m)
{
if(mark=='o')
mark=m;
}
};
class Image {
int x_length,y_length=5;
Pixel** p;
public:
Image(int x,int y)
{
x_length=x;
y_length=y;
p= new Pixel* [y_length];
for(int i=0;i<y_length;i++)
p[i]=new Pixel[x_length];
for(int i=0;i<y_length;i++)
{
for(int j=0;j<x_length;j++)
{
p[i][j]=Pixel(i,j,'o');
}
}
}
void Print()
{
for(int i=0;i<y_length;i++)
{
for(int j=0;j<x_length;j++)
{
cout<<p[i][j].get_mark();
cout<<' ';
}
cout<<"\n";
}
}
void Transform(Pixel pix,int d)
{
int x=pix.Get_y();
int y=pix.Get_x();
p[y][x].Change_mark('c');
for(int i=0;i<=d;i++)
{
for(int j=0;j<d-i+1;j++)
{
if(i!=0 || j!=0)
{
if(y+i<y_length && y+i>-1 && x-j>-1 && x-j<x_length)
p[y+i][x-j].Change_mark('x');
if(y+i<y_length && y+i>-1 && x+j>-1 && x+j<x_length)
p[y+i][x+j].Change_mark('x');
if(y-i<y_length && y-i>-1 && x-j>-1 && x-j<x_length)
p[y-i][x-j].Change_mark('x');
if(y-i<y_length && y-i>-1 && x+j>-1 && x+j<x_length)
p[y-i][x+j].Change_mark('x');
}
}
}
}
};
int main()
{
int sizex,sizey;
cin>>sizex>>sizey;
Image img(sizex,sizey);
int temp;
int x,y,d;
x=0;
while (x!=-1)
{
cin>>x;
if(x==-1)
break;
cin>>y;
cin>>d;
Pixel temp(x,y,'o');
img.Transform(temp,d);
}
img.Print();
}