Java Graphics Draw drawBubbles(Graphics g, int nCode)

Here you can find the source of drawBubbles(Graphics g, int nCode)

Description

draw Bubbles

License

LGPL

Declaration

public static void drawBubbles(Graphics g, int nCode) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Color;

import java.awt.Graphics;

import java.util.Random;

public class Main {
    public static void drawBubbles(Graphics g, int nCode) {
        int width = g.getClipBounds().width;
        int height = g.getClipBounds().height;

        g.setColor(Color.BLUE);//from  w  ww. j  ava 2s .c  o m
        g.fillRect(1, 1, width - 2, height - 2);

        Random r = new Random(nCode);
        int nBubbles = r.nextInt(3) + 2;
        for (int i = 0; i < nBubbles; i++) {
            int xB = (int) (r.nextDouble() * width);
            int yB = (int) (r.nextDouble() * height);
            int rB = (int) (r.nextDouble() * Math.min(width, height) / 5.0);
            g.setColor(Color.CYAN);
            g.drawOval(xB - rB, yB - rB, rB * 2, rB * 2);
        }
    }
}

Related

  1. drawBeamsplit(Graphics g, int midx, int midy, Color cup, Color cdown, Color cright, boolean showMirror, boolean isDichroic)
  2. drawBeamVariableRadiusVertical(Graphics g, Color c, int midx, int y1, int y2, int r1, int r2)
  3. drawBoundary(Graphics2D g2d, Rectangle bounds, Point2D.Double[] pts)
  4. drawBoxOrBlockChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)
  5. drawBubbleHead(Graphics2D g, Point2D headPosition, double orientation, double size, Color color, Stroke stroke)
  6. drawChar(char c, int x, int y, Graphics g)
  7. drawChars(JComponent c, Graphics g, char[] data, int offset, int length, int x, int y)
  8. drawCheck(Graphics g, int x, int y)
  9. drawCheckerPattern(Graphics g_, int checkerSize)