-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotSquare.py
More file actions
50 lines (43 loc) · 1.04 KB
/
plotSquare.py
File metadata and controls
50 lines (43 loc) · 1.04 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
import matplotlib.pyplot as plt
def recursivePlotSquare(x,y,size=0):
'''
Objective: To plot multiple squares
Input Parameters: x, y - lists of x coordinates and y
coordinates respectively
Return Value: None
'''
#approach: Using recursion
x = [0, size, size, 0, 0]
y = [0, 0, size, size, 0]
if (size == 1):
return
else:
plotSquare(x,y)
return recursivePlotSquare(x,y,size-1)
def plotSquare(x, y):
'''
Objective: To plot a square
Input Parameters: x, y - lists of x coordinates and y
coordinates respectively
Return Value: None
'''
plt.plot(x, y, 'ro--')
def main():
'''
Objective: To plot a square based on user input
Input Parameter: None
Return Value: None
'''
size = int(input('Enter size of the square: '))
if (size <= 0):
print("Invalid Size..!")
return
x = [0, size, size, 0, 0]
y = [0, 0, size, size, 0]
recursivePlotSquare(x, y, size)
plt.title('Square')
plt.axis([min(x)-1, max(x)+1, min(y)-1, max(y)+1])
plt.grid()
plt.show()
if __name__ == '__main__':
main()