Java Graphics Draw drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright, boolean showMirror, boolean isDichroic)

Here you can find the source of drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright, boolean showMirror, boolean isDichroic)

Description

draw Beamsplit

License

BSD License

Declaration

public static void drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright,
            boolean showMirror, boolean isDichroic) 

Method Source Code

//package com.java2s;
/***/*w w w.  j a v a2  s . c o m*/
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class Main {
    private static final int beamR = 6;

    public static void drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright,
            boolean showMirror, boolean isDichroic) {
        int boxR = 15;

        //Box
        g.setColor(Color.lightGray);
        g.fillRect(midx - boxR, midy - boxR, boxR * 2, boxR * 2);
        //g.drawRect(midx-boxR, midy-boxR, boxR*2, boxR*2);

        //Beams
        float[] carr = new float[3];
        if (cright != null) {
            cright.getColorComponents(carr);
            for (int i = -beamR; i < beamR; i++) {
                float weight = fmin1((beamR - Math.abs(i)) / (double) beamR);
                g.setColor(new Color(carr[0], carr[1], carr[2], weight));
                g.drawLine(midx - i, midy + i, midx + boxR, midy + i);
            }
        }
        if (cdown != null) {
            cdown.getColorComponents(carr);
            for (int i = -beamR; i < beamR; i++) {
                float weight = fmin1((beamR - Math.abs(i)) / (double) beamR);
                g.setColor(new Color(carr[0], carr[1], carr[2], weight));
                g.drawLine(midx + i, midy - i, midx + i, midy + boxR);
            }
        }
        if (cup != null) {
            cup.getColorComponents(carr);
            for (int i = -beamR; i < beamR; i++) {
                float weight = fmin1((beamR - Math.abs(i)) / (double) beamR);
                g.setColor(new Color(carr[0], carr[1], carr[2], weight));
                g.drawLine(midx + i, midy - boxR, midx + i, midy - i);
            }
        }

        //Mirror
        if (showMirror) {
            if (isDichroic) {
                float[] Dashes = { 3.0F, 3.0F };
                g = g.create();
                ((Graphics2D) g).setStroke(
                        new BasicStroke(1.0F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0F, Dashes, 0.F));
            }
            g.setColor(Color.BLACK);
            g.drawLine(midx - boxR, midy + boxR, midx + boxR, midy - boxR);
        }
    }

    private static float fmin1(double x) {
        return Math.max(Math.min(0.9f, (float) x), 0f);
    }
}

Related

  1. draw(int[] pixels, int width, int height)
  2. drawAndFill(Graphics g, Shape s, Color draw, Color fill)
  3. drawAngledLine(Graphics g, int x, int y, double angle, int length)
  4. drawAt(final Graphics2D g, final double x, final double y, final Shape s)
  5. drawAutoCompleteMarker(Graphics2D g2, int x, int y, int iconSize)
  6. drawBeamVariableRadiusVertical(Graphics g, Color c, int midx, int y1, int y2, int r1, int r2)
  7. drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts)
  8. drawBoxOrBlockChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)
  9. drawBubbleHead(Graphics2D g, Point2D headPosition, double orientation, double size, Color color, Stroke stroke)