如何用Java控制台打印螺旋藻 急急急 跪求各位高手帮下忙
螺旋藻类似于e那样 --------------------编程问答-------------------- 螺旋藻???? --------------------编程问答-------------------- * * * - - -* - - * - -
* - * - * -
* - - * * -
* - * - - -
* * - - - -
类似这样 --------------------编程问答-------------------- 这是个算法问题吧,螺旋藻生成规则是什么? --------------------编程问答-------------------- 具体什么形状?按照形状才能做算法啊!像空心菱形之类的 --------------------编程问答-------------------- ##############
#### ####
### ###
## ######## ##
### ##### ##### ###
## ### ### ##
## ## ## ##
## ### ########## ### ##
## ## #### #### ## #
# ## ## ## ## ##
## ## ### ###### ## # ##
## # ## #### #### ### ## #
# ## ## ## ## # ## ##
## ## # ### ## ## # #
# # ## ## ######## ## ## ## #
# # ## # ## ## ## # # ##
# ## # ## ### ## ## ## # #
# # ## # ## ## # # ## #
# ## # ## ####### ## # # # #
## # # # # ## # ## # # ##
# # # ## ## ## # # # # #
# # ## # # ### # # # # # #
# # # # # # # ## # # # # #
# # # # # # # # # # # #
# # ## # # ## ## # ## # # ##
# # # # # #### ## # # # #
## # # ## ## ## # ## ## #
# ## # # ## ## ## # # #
# # ## ## ######## ## # # ##
# # # ## ## ## ## #
## ## ## ## ## ## # #
# # ## #### #### ## ## ##
## ## ## ###### ## ## #
# ## ### ## ## ##
## ## ## ### ## ##
## ## ############ ## ##
## ### ## ## ##
## ## ### ##
## #### #### ##
### ########## ##
## ###
#### ###
##### #####
#######
--------------------编程问答--------------------
public class ArchimedeanSpiral {--------------------编程问答-------------------- CSDN 帖子中的行距很大,在控制台中输出就比较漂亮了
public static void main(String[] args) {
CoordinateCanvas canvas = new CoordinateCanvas(22);
for (double t = 0; t < 13; t += 0.00005) {
double r = 1.8 * t;
double radians = Math.toRadians(t * 180);
double x = r * Math.cos(radians);
double y = r * Math.sin(radians);
canvas.putPoint(x, y);
}
canvas.output(System.out, false);
}
}
class CoordinateCanvas {
private final int positiveX;
private final int negativeX;
private final int positiveY;
private final int negativeY;
private final char plotChar;
private final char[][] canvas;
public CoordinateCanvas(int quadrant) {
this(quadrant, '#');
}
public CoordinateCanvas(int quadrant, char plotChar) {
this(quadrant, quadrant, plotChar);
}
public CoordinateCanvas(int x, int y) {
this(x, y, '#');
}
public CoordinateCanvas(int x, int y, char plotChar) {
this(x, x, y, y, plotChar);
}
public CoordinateCanvas(int positiveX, int negativeX,
int positiveY, int negativeY, char plotChar) {
this.positiveX = Math.abs(positiveX);
this.negativeX = Math.abs(negativeX);
this.positiveY = Math.abs(positiveY);
this.negativeY = Math.abs(negativeY);
this.plotChar = plotChar;
this.canvas = new char[getHeigh()][getWidth()];
init();
}
public void putPoint(double x, double y) {
int ix = (int)Math.round(x);
int iy = (int)Math.round(y);
if (ix > positiveX || ix < -negativeX) {
return;
}
if (iy > positiveY || iy < -negativeY) {
return;
}
canvas[positiveY - iy][negativeX + ix] = plotChar;
}
public void output(PrintStream output, boolean line) {
for (int i = 0; i < canvas.length; i++) {
for (int j = 0; j < canvas[i].length; j++) {
output.print(canvas[i][j]);
if (line && i == negativeY) {
output.print('─');
}
if (line && j == negativeX) {
output.print('│');
}
if (line && i == negativeY && j == negativeX) {
output.print('┼');
}
}
output.println();
}
}
private int getHeigh() {
return positiveY + negativeY + 1;
}
private int getWidth() {
return positiveX + negativeX + 1;
}
private void init() {
for (int i = 0; i < canvas.length; i++) {
for (int j = 0; j < canvas[i].length; j++) {
canvas[i][j] = ' ';
}
}
}
}
##############
#### ####
### ###
## ######## ##
### ##### ##### ###
## ### ### ##
## ## ## ##
## ### ########## ### ##
## ## #### #### ## #
# ## ## ## ## ##
## ## ### ###### ## # ##
## # ## #### #### ### ## #
# ## ## ## ## # ## ##
## ## # ### ## ## # #
# # ## ## ######## ## ## ## #
# # ## # ## ## ## # # ##
# ## # ## ### ## ## ## # #
# # ## # ## ## # # ## #
# ## # ## ####### ## # # # #
## # # # # ## # ## # # ##
# # # ## ## ## # # # # #
# # ## # # ### # # # # # #
# # # # # # # ## # # # # #
# # # # # # # # # # # #
# # ## # # ## ## # ## # # ##
# # # # # #### ## # # # #
## # # ## ## ## # ## ## #
# ## # # ## ## ## # # #
# # ## ## ######## ## # # ##
# # # ## ## ## ## #
## ## ## ## ## ## # #
# # ## #### #### ## ## ##
## ## ## ###### ## ## #
# ## ### ## ## ##
## ## ## ### ## ##
## ## ############ ## ##
## ### ## ## ##
## ## ### ##
## #### #### ##
### ########## ##
## ###
#### ###
##### #####
#######
--------------------编程问答--------------------
果哥,我已经不能用牛B来形容你了。
给说下程序哈,看不大懂。 --------------------编程问答--------------------
呵呵,很简单,就是阿基米德螺线,你网上搜一下就能找到了,下面这个是 wiki 上的介绍
http://zh.易做图.org/zh/%E9%98%BF%E5%9F%BA%E7%B1%B3%E5%BE%B7%E8%9E%BA%E7%BA%BF --------------------编程问答-------------------- CoordinateCanvas 是笛卡坐标的类,使用 putPoint 方法在坐标系上描点
ArchimedeanSpiral 是阿基米德螺线循环计算类,这里已经将阿基米德螺线极坐标方程转换成为了参数方程,用于计算各个点的 x 和 y 值
补充:Java , Java相关