-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
148 lines (129 loc) · 5.16 KB
/
index.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<html>
<head>
<title>Document</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<link rel ="stylesheet" href ="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"></script>
<py-env>
- matplotlib
</py-env>
</head>
<style>
input[type=text],
select {
width: 50%;
padding: 10px 10px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
align-items: center;
}
input[type=submit] {
width: 50%;
background-color: #4c4faf;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
align-content: center;
}
input[type=submit]:hover {
background-color: #45a049;
}
p {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
<body>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="https://atitbimali.com.np/">Contact Admin</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarScroll">
<ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style="--bs-scroll-height: 100px;">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/AtitBimali/dda_algorithm_pyscript">GitHub</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<h1 id="h1" style="text-align:center;">DDA Line Drawing Algorithm</h1>
<hr>
<h4 id="h3" class="text-muted" style="text-align:center;">Implementation of DDA Algorithm using pyscript and matplotlib</h4>
<p style="text-align:center;">Input the X-coordinates and Y-coordinates and it will generate a matplotlib plot using the DDA line drawing
algotithm. <br> Don't put equal values for the coordinates because the difference will be 0 which will make the denominator/numerator 0 so no plot will be displayed.
</p>
<hr class="border border-primary border-3 opacity-75">
<form onsubmit="return false" style="margin-left: 30%;">
<label for="name">Enter x1:</label><br>
<input type="text" id="x1" name="x1" value=""><br>
<label for="name">Enter y1</label><br>
<input type="text" id="y1" name="y2" value=""><br>
<label for="name">Enter x2:</label><br>
<input type="text" id="x2" name="x2" value=""><br>
<label for="name">Enter y2</label><br>
<input type="text" id="y2" name="y2" value=""><br>
<select name="algorithm" id="algorithm">
<option value="DDA">DDA Line Drawing Algorithm</option>
</select>
<input pys-onClick="main" id="submit" value="submit" type="submit">
</form>
<!-- <py-script> print("My Lineplot")</py-script> -->
<div id="lineplot"></div>
<py-script output="lineplot">
# Python Code Goes Here ...
import matplotlib.pyplot as plt
<!-- def index(*args, **kwargs): -->
fig, ax = plt.subplots()
def DDALine(x1, y1, x2, y2, color):
dx = x2 - x1
dy = y2 - y1
# calculate steps required for generating pixels
steps = abs(dx) if abs(dx) > abs(dy) else abs(dy)
#calculate increment in x & y for each steps
Xinc = float(dx / steps)
Yinc = float(dy / steps)
for i in range(0, int(steps + 1)):
# Draw pixels
plt.plot(int(x1), int(y1), color)
x1 += Xinc
y1 += Yinc
plt.plot()
def main(*args, **kwargs):
xa = Element('x1').element
xavalue = int(xa.value)
ya = Element('y1').element
yavalue = int(ya.value)
xb = Element('x2').element
xbvalue = int(xb.value)
yb = Element('y2').element
ybvalue = int(yb.value)
x = xavalue
y = yavalue
xEnd = xbvalue
yEnd =ybvalue
color = "r."
DDALine(x, y, xEnd, yEnd, color)
fig
result_place = Element('lineplot')
result_place.write(fig)
</py-script>
</body>
</html>