Java Graphics Draw drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode)

Here you can find the source of drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode)

Description

draw Rainbow

License

Open Source License

Declaration

static public void drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode) 

Method Source Code


//package com.java2s;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.util.Vector;

public class Main {
    static public void drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode) {
        Vector Colors = new Vector();
        GradientPaint gp;//  w w w.  j a va  2 s. co m
        switch (Mode) {
        case 1:
            Colors.add(new Color(255, 000, 000));
            Colors.add(new Color(255, 255, 000));
            Colors.add(new Color(000, 255, 000));
            Colors.add(new Color(000, 255, 255));
            Colors.add(new Color(000, 000, 255));
            Colors.add(new Color(255, 000, 255));
            break;
        case 2:
            Colors.add(new Color(255, 000, 000));
            Colors.add(new Color(255, 255, 000));
            Colors.add(new Color(000, 000, 128));
            break;
        case 3:
            Colors.add(new Color(255, 000, 255));
            Colors.add(new Color(000, 000, 255));
            Colors.add(new Color(000, 255, 255));
            Colors.add(new Color(000, 255, 000));
            Colors.add(new Color(255, 255, 000));
            Colors.add(new Color(255, 000, 000));
            break;

        }
        double Step = Width / (double) (Colors.size() - 1);
        for (int i = 0; i < (Colors.size() - 1); i++) {
            gp = new GradientPaint(x + (int) Math.round(i * Step), 0, (Color) Colors.get(i),
                    x + (int) Math.round((i + 1) * Step), 0, (Color) Colors.get(i + 1));
            g2.setPaint(gp);
            g2.drawRect(x + (int) Math.round(i * Step), y, (int) Step, Height);
            g2.fillRect(x + (int) Math.round(i * Step), y, (int) Step, Height);
        }
    }
}

Related

  1. drawMovingRect(int x, int y, int width, int height, Graphics g, int seed)
  2. drawOptimizedLine(Graphics g, int x1, int y1, int x2, int y2)
  3. drawPaintedShape(Graphics2D graphics, Shape shape, Paint paint, Rectangle2D paintBounds, Stroke stroke)
  4. drawPowerScaleLabel(Graphics g, int base, int power, int x, int y, boolean yAxisP)
  5. drawProgressBar(Graphics2D g, final int x, final int y, final int width, final int height, final Color main, final Color progress, final int alpha, final int percentage)
  6. drawRequiredMarker(Graphics2D g2, int x, int y, int iconSize)
  7. drawRTriangle(Graphics g, Color color, int x, int y, int r)
  8. drawScaleTick(Graphics g, int x, int y, boolean yAxisP, int length)
  9. drawScrollBar(Graphics g, int which, int direction, int x, int y, int fmWidth, int fmHeight, Color fg, Color bg)