Java绘图面板?
我已经完成了色轮的一些代码,但我不知道如何完成它?我还对代码进行了注释,以帮助理解。到目前为止,它打印红色、橙色和黄色渐变。我如何完成这个Java绘图面板?,java,for-loop,colors,drawing,color-wheel,Java,For Loop,Colors,Drawing,Color Wheel,我已经完成了色轮的一些代码,但我不知道如何完成它?我还对代码进行了注释,以帮助理解。到目前为止,它打印红色、橙色和黄色渐变。我如何完成这个 import java.awt.*; public class ColorDrawing2 { public static final int CENTER = 256; public static final int RADIUS = 120; public static final int SH
import java.awt.*;
public class ColorDrawing2 {
public static final int CENTER = 256;
public static final int RADIUS = 120;
public static final int SHAPES = 32;
public static final int SIZE = 40;
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(512,512); // create a drawing panel
panel.setBackground(new Color(0,0,0)); // set background color (orange)
Graphics g = panel.getGraphics(); // get graphics toolkit
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = (i)*(360/SHAPES)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (199 + 56/SHAPES*i); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (7.97*i); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = 0;
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(200); // pause 200 msec
}
}
}
import java.awt.*;
公共类彩色绘图2{
公共静态最终整数中心=256;
公共静态最终整数半径=120;
公共静态最终整数形状=32;
公共静态最终整数大小=40;
公共静态void main(字符串[]args){
DrawingPanel=新建DrawingPanel(512512);//创建绘图面板
panel.setBackground(新颜色(0,0,0));//设置背景色(橙色)
Graphics g=panel.getGraphics();//获取图形工具包
for(int i=0;i是的,似乎6个for循环就足够了。也许颜色应该增加到255?对于6个for循环:
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) +65)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (255); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (7.97*i); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = 0;
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 130)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (255 - (255/SHAPES*i)); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (255); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = 0;
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 185)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (0); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (255); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (7.97*i);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 250)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (0); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (255 - (255/SHAPES*i)); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (255);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 315)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (7.97*i); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (0); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (255);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) +370)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (7.97*i); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (0); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (0);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for(int i=0;i