-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab14_2.cpp
58 lines (48 loc) · 1.08 KB
/
lab14_2.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
const int N = 30;
const int M = 70;
void updateImage(bool [][M],int,int,int);
void showImage(const bool [][M]);
int main()
{
bool image[N][M] = {};
int s,x,y;
do{
showImage(image);
cout << "Input your brush size and location: ";
cin >> s >> x >> y;
updateImage(image,s,x,y);
}while(s != 0 || x != 0 || y != 0);
return 0;
}
void updateImage(bool image[][M],int s,int x,int y){
for (int i = 0; i < N ; i++){
for (int j = 0; j < M ; j++){
if (sqrt(pow(i-x,2)+pow(j-y,2)) <= s-1) {
image[i][j] = 1;
}
}
}
}
void showImage(const bool image[N][M]){
for(int i=0;i<M+2;i++){
cout << "-";
}
cout <<endl;
for (int i = 0; i < N ; i++){
cout << "|";
for (int j = 0; j < M ; j++){
if (image[i][j]==1)
cout << "*";
else
cout << " ";
}
cout << "|"<<endl;
}
for(int i=0;i<M+2;i++){
cout << "-";
}
cout <<endl;
}