-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
161 lines (120 loc) · 3.91 KB
/
index.js
File metadata and controls
161 lines (120 loc) · 3.91 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
// 绘制调用
"use strict";
// customized part
function getLine() {
var x1 = Number(document.querySelector("#x1").value)
var y1 = Number(document.querySelector("#y1").value)
var x2 = Number(document.querySelector("#x2").value)
var y2 = Number(document.querySelector("#y2").value)
// console.log(y2, typeof (y2));
return [x1, y1, x2, y2]
}
function getMethod() {
var method = document.querySelector("#method").value
console.log(method);
return method
}
function getCircle() {
var x1 = Number(document.querySelector("#ox").value)
var y1 = Number(document.querySelector("#oy").value)
var r = Number(document.querySelector("#r").value)
return [x1, y1, r]
}
function getEllipe() {
var x1 = Number(document.querySelector("#ox").value)
var y1 = Number(document.querySelector("#oy").value)
var a = Number(document.querySelector("#a").value)
var b = Number(document.querySelector("#b").value)
return [x1, y1, a, b]
}
function getPolygon() {
var temp = []
for (let index = 0; index < buffer.length; index++) {
const element = buffer[index];
if (element.class == "Polygon") {
temp = element.points
break
}
}
return temp
}
function getRectangle() {
var temp = []
for (let index = 0; index < buffer.length; index++) {
const element = buffer[index];
if (element.class == "Rectangle") {
temp = element.points
break
}
}
return temp
}
function getLines() {
var temp = []
for (let index = 0; index < buffer.length; index++) {
const element = buffer[index];
if (element.class == "Lines") {
temp = element.points
break
}
}
return temp
}
function draw() {
var method = getMethod()
switch (method) {
case "DDA":
var line = getLine()
var positions = DDA(line)
console.log(positions);
break
case "中点算法":
var line = getLine()
var positions = Midpointline(line)
console.log(positions);
break
case "Bresenham":
var line = getLine()
var positions = lineBreshm(line)
console.log(positions);
break
case "中点画圆":
var circle = getCircle()
var positions = midPointCircle(circle)
break
case "中点画椭圆":
var ellipe = getEllipe()
var positions = midPointEllipe(ellipe)
break
case "多边形填充":
var polygon = getPolygon()
console.log("多边形填充", polygon);
if (polygon.length == 0) {
alert("请输入多边形!")
}
var positions = scanLine(polygon)
break
case "多边形裁剪":
var polygon = getPolygon()
var rectangle = getRectangle()
if (polygon.length == 0 || rectangle.length < 4) {
alert("请输入多边形和矩形!")
}
console.log("多边形裁剪", polygon, rectangle);
var positions = sutherland(rectangle, polygon)
console.log("结果:", positions);
break
case "矩形截线":
var rectangle = getRectangle()
var lines = getLines()
if (rectangle.length < 4 || lines.length == 0) {
alert("请输入矩形和直线!")
}
console.log("矩形截线", rectangle, lines);
var positions = CS_LineClip(lines, rectangle)
break
}
// console.log(line);
main(positions);
}
document.querySelector("#drawbtn").addEventListener("click", draw)