📄 alg.java
字号:
package graphInterface;
import java.awt.*;
import java.util.Stack;
import javax.swing.JPanel;
public class Alg {
private static int abs(int n) {
return Math.abs(n);
}
public static void line(Graphics g, int x0, int y0, int xt, int yt) {
// bresonham 画线法
if (x0 > xt) {
int temp = x0;
x0 = xt;
xt = temp;
temp = y0;
y0 = yt;
yt = temp;
}
int dy = yt > y0 ? yt - y0 : y0 - yt;
int ystep = yt > y0 ? 1 : -1;
int dx = xt - x0;
if (dy < dx) {
int e = -dx;
int x = x0;
int y = y0;
for (int i=0; i<=dx; ++i) {
g.drawLine(x, y, x, y);
++x;
e = e + dy * 2;
if (e >= 0) {
y += ystep;
e = e - dx * 2;
}
}
}
else {
int e = -dy;
int x = x0;
int y = y0;
for (int i=0; i<=dy; ++i) {
g.drawLine(x, y, x, y);
y += ystep;
e = e + dx * 2;
if (e >= 0) {
++x;
e = e - dy * 2;
}
}
}
}
public static void round(Graphics g, int x0, int y0, int r) {
// 画圆算法,先用系统画圆替代
g.drawArc(x0 - r, y0 - r, r + r, r + r, 0, 360);
}
public static void eclipse(Graphics g, int x0, int y0, int a, int b) {
g.drawArc(x0 - a, y0 - b, a + a, b + b, 0, 360);
}
public static void fill(Graphics g, JPanel panel, Color bg, int x, int y) {
Stack s = new Stack();
s.push(new Point(x, y));
while (!s.empty()) {
Point p = (Point)s.pop();
//panel.getBackground()
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -