How to draw a diamond shape in java?

Lana

So i have to draw a diamond shape. Not a Static diamond but a diamond that i will myself drag and draw. I've used General Path to do it but it is drawing a diamond that is not straight; the diamond is bend to the left and it's not being drawn to where my mouse is pointed.

enter image description here

Here is my code to create the diamond shape. Can someone please help me solve this?

 private GeneralPath drawDiamond(int x1, int y1, int x2, int y2){
            
            int x = Math.min(x1, x2);
            int y = Math.min(y1, y2);

            // Gets the difference between the coordinates and

            int width = Math.abs(x1 - x2);
            int height = Math.abs(y1 - y2);
            
            Rectangle2D.Double diamond = new Rectangle2D.Double(x1,y1,width,height);
            
            GeneralPath connectedDiamond = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
            
            connectedDiamond.append(diamond, true);
            
            AffineTransform at = new AffineTransform();
            at.rotate(Math.toRadians(20));
            connectedDiamond.transform(at);
            
            return connectedDiamond;
        }

Here is my paint method:

public void paint(Graphics g) {           

            graphSettings = (Graphics2D) g;           

            graphSettings.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);

            graphSettings.setStroke(new BasicStroke(4));
           
            Iterator<Color> strokeCounter = shapeStroke.iterator();
            for (NamedShape s : shapes) {

                graphSettings.draw(s.getShape());

            }

            if (drawStart != null && drawEnd != null) {
                
                graphSettings.setComposite(AlphaComposite.getInstance(
                        AlphaComposite.SRC_OVER, 0.40f));

                graphSettings.setPaint(Color.LIGHT_GRAY);

                Shape aShape = null;
                    
                if(currentAction == 7){
                    
                    aShape = drawDiamond(drawStart.x, drawStart.y, drawEnd.x, drawEnd.y);
                }

                graphSettings.draw(aShape);
            }
        }

Can someone please help me to do this?

Subler

How about instead of rotating a rectangle, you draw lines between 4 points inside a rectangle:

the points:

enter image description here

excuse my poor mspaint skills.

but i hope u get what i mean. u take the top center, middle right, bottom center and middle left points and draw lines between those (using generalPath, i think)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to draw Diamond And zick zack shape in ios?

From Dev

Need help adjusting a diamond shape in Java

From Dev

How to transform a cube mesh into a diamond shape

From Dev

How to display image in Diamond shape in iOS?

From Dev

How to print diamond shape w/ c++

From Dev

How to draw a responsive shape

From Dev

How to insert text inside a shape that i will draw in Java

From Dev

Java how to make a shape(s) that can be draw by clicking button

From Dev

How to draw a ring shape in Java using unit circle trig

From Dev

Java diamond-shape isometric map tile pick

From Dev

How to Draw a triangle shape in python?

From Dev

How to draw trapezoid shape in iOS?

From Dev

Printing numbers in a diamond shape

From Dev

How to make an image inside a diamond shape morph to circle

From Dev

How would I create a title inside a diamond shape, with CSS?

From Dev

How to add a "yellow diamond" while editing points of a shape?

From Dev

How would I create a title inside a diamond shape, with CSS?

From Dev

In Box Plot Chart, how can I set the average point to Diamond shape instead of standard Line shape

From Dev

In Box Plot Chart, how can I set the average point to Diamond shape instead of standard Line shape

From Dev

Outline shape with a character g.draw java

From Dev

Java LibreOffice Draw - Set text of a shape

From Java

SwiftUI: How to draw filled and stroked shape?

From Dev

How do I draw this shape in SVG?

From Dev

How to draw a shape that resizes with the form WPF?

From Dev

Android how to draw Rounded Rectangle shape programmatically

From Dev

How to draw fan shape with animation by using UIBezierPath?

From Dev

How to draw an arbitrary shape using html canvas?

From Dev

How to remove previous shape after draw() in Processing

From Dev

How to draw a shape using a piece of image in php

Related Related

  1. 1

    How to draw Diamond And zick zack shape in ios?

  2. 2

    Need help adjusting a diamond shape in Java

  3. 3

    How to transform a cube mesh into a diamond shape

  4. 4

    How to display image in Diamond shape in iOS?

  5. 5

    How to print diamond shape w/ c++

  6. 6

    How to draw a responsive shape

  7. 7

    How to insert text inside a shape that i will draw in Java

  8. 8

    Java how to make a shape(s) that can be draw by clicking button

  9. 9

    How to draw a ring shape in Java using unit circle trig

  10. 10

    Java diamond-shape isometric map tile pick

  11. 11

    How to Draw a triangle shape in python?

  12. 12

    How to draw trapezoid shape in iOS?

  13. 13

    Printing numbers in a diamond shape

  14. 14

    How to make an image inside a diamond shape morph to circle

  15. 15

    How would I create a title inside a diamond shape, with CSS?

  16. 16

    How to add a "yellow diamond" while editing points of a shape?

  17. 17

    How would I create a title inside a diamond shape, with CSS?

  18. 18

    In Box Plot Chart, how can I set the average point to Diamond shape instead of standard Line shape

  19. 19

    In Box Plot Chart, how can I set the average point to Diamond shape instead of standard Line shape

  20. 20

    Outline shape with a character g.draw java

  21. 21

    Java LibreOffice Draw - Set text of a shape

  22. 22

    SwiftUI: How to draw filled and stroked shape?

  23. 23

    How do I draw this shape in SVG?

  24. 24

    How to draw a shape that resizes with the form WPF?

  25. 25

    Android how to draw Rounded Rectangle shape programmatically

  26. 26

    How to draw fan shape with animation by using UIBezierPath?

  27. 27

    How to draw an arbitrary shape using html canvas?

  28. 28

    How to remove previous shape after draw() in Processing

  29. 29

    How to draw a shape using a piece of image in php

HotTag

Archive