Nicole
Nicole

Reputation: 247

How do I draw a cloud with polygons?

In my course notes my lecturer explains how to make a triangle but that is about where the explanation ends. I need to draw a cloud so is there a way I can make the edges round? Or is there a better way to approach this?

package polygon;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;

public class PanelPoly extends javax.swing.JPanel {

   int[] xWaarden = {100,210,360};
   int[] yWaarden = {170,60,170};
   Polygon triangle = new Polygon(xWaarden, yWaarden,xWaarden.length);

   public PanelPoly() {

   }

   public void paintComponent(Graphics g){
       super.paintComponent(g);
       g.setColor(Color.BLACK);
       g.fillPolygon(triangle);
   }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>                        
    // Variables declaration - do not modify                     
    // End of variables declaration                   
}

Upvotes: 1

Views: 5257

Answers (1)

StanislavL
StanislavL

Reputation: 57381

You can use java.awt.geom.Area. Create multiple areas from several ovals and organize intersections of the circles.

Or you can see Polygon with rounded angles. See for example sources from here http://java-sl.com/shapes.html for the starts and regular polygons there is an approach how to round their angles.

That's simple example how to combine 2 ovals http://java-sl.com/tip_flatteningpathiterator_moving_shape.html

Upvotes: 2

Related Questions