/* * [ChaosIcon.java] * * Summary: Draws icon for the Chaos app. * * Copyright: (c) 2013-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2013-02-16 initial version. */ package com.mindprod.connectors; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Polygon; import java.util.Random; /** * Draws icon for the Chaos app. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2013-02-16 initial version. * @since 2013-02-16 */ class ChaosIcon extends ConnectorPanel { private static final Color BLUE = new Color( 0x364bfc ); private static final Color CYAN = new Color( 0x36fcf4 ); private static final Color GREEN = new Color( 0x3cfc9e ); private static final Color OUTLINE_COLOR = Color.BLACK; /** * default transparent background colour for images. */ private static final Color TRANSPARENT = new Color( 0x00ffffff, true ); private static final Random wheel = new Random(); /** * thickness of the outline */ private final int lineWidth; /** * overal dimension of entire image */ private final int size; /** * Draw a quilty of randomly coloured and placed squares * * @param overallSize in pixels e.g. 32 .. 256 * @param lineWidth width in pixels of outlines of small and over all image 2..5 */ ChaosIcon( final int overallSize, final int lineWidth ) { super( overallSize, overallSize ); this.size = overallSize; this.lineWidth = lineWidth; } /** * draw random squares at random positions outlined. * * @param g where to paint */ public void paintComponent( Graphics g ) { super.paintComponent( g ); final Graphics2D g2d = ( Graphics2D ) g; g2d.setColor( TRANSPARENT ); g2d.fillRect( 0, 0, size - 1, size - 1 ); for ( int y = 0; y < size; y++ ) { int x = wheel.nextInt( size ); switch ( wheel.nextInt( 3 ) ) { case 0: g2d.setColor( GREEN ); break; case 1: g2d.setColor( CYAN ); break; default: g2d.setColor( BLUE ); break; } g2d.fillRect( 0, y, x, 1 ); } // touch up the frame outline. g2d.setColor( Color.BLACK ); final Polygon outline = new Polygon(); outline.addPoint( 0, 0 ); outline.addPoint( size - 1, 0 ); outline.addPoint( size - 1, size - 1 ); outline.addPoint( 0, size - 1 ); g2d.setColor( OUTLINE_COLOR ); g2d.setStroke( new BasicStroke( lineWidth ) ); g2d.drawPolygon( outline ); } }