Program is written in Java. Write a program that draws a pattern of hexagons, as
ID: 3876993 • Letter: P
Question
Program is written in Java.
Write a program that draws a pattern of hexagons, as shown in the figure below. The vertices of a (regular) hexagon lie on its so-called circumscribed circle. The user must be able to specify the radius of this circle by clicking a point near the upper-left corner of the drawing rectangle. Then the distance between that point and that corner is to be used as the radius of the circle just mentioned. There must be as many hexagons of the specified size as possible and the margins on the left and the right must be equal. The same applies to the upper and lower margins, as the figure shows
HexagonsExplanation / Answer
Ans:-
Dear Student Before Creating hexagon shape for Said purpose we Need to Create Class to get output of Hexagon Shape.
sprite = new Polygon();
sprite.addPoint(0,zero);
sprite.addPoint(0,-forty);
sprite.addPoint(30,-40);
sprite.addPoint(60,-10);
sprite.addPoint(60,20);
sprite.addPoint(40,50);
sprite.addPoint(-20,50);
sprite.addPoint(-50,-20);
sprite.addPoint(50,-10);
sprite.addPoint(-20,-forty);
By the above Diagram Pls find Programm for the Hexagon.
public Hexagon(flow pX, waft pY, go with the flow pSize) {
exquisite(pX, pY, pSize, pSize);
// setColor(1, zero, 0);
setAlpha(0);
glide x1, x2, y1, y2;
float lineWidth = 3;
x1 = zero; y1 = pSize / 2;
x2 = pSize / 4;
y2 = (pSize * ((2 - (waft)Math.sqrt(three)) / 4)); // accomplished
Line line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize * .75f; // accomplished
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize; y2 = pSize / 2; // accomplished
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize * .75f; y2 = pSize - (pSize * ((2 - (go with the flow)Math.sqrt(3)) / 4)); // performed
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize / 4; // completed
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = 0; y2 = pSize / 2; // completed
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
touchableArea = new Rectangle(pSize / four, pSize / four, pSize * .75f, pSize * .75f);
touchableArea.setAlpha(0);
attachChild(touchableArea);
}
Result & output for Hexagon Symbol:-
mport java.util.Scanner;
public magnificence Ex02_16 {
public static void primary(String[] args) {
machine.out.println("This software Calculates The place Of A Hexagon.n");
Scanner input = new Scanner(system.in);
device.out.println("enter the period of a facet of the hexagon:");
double aspect = enter.nextDouble();
//calculate region using the formulation ((33) ÷ 2) * the rectangular of the period of a facet
double place = ((three * (Math.pow(three, 0.5))) / 2) * aspect * aspect;
//format area to two decimal places
vicinity = (int) (region * 10000) / ten thousand.0;
//display the end result
machine.out.println("The location of the hexagon is " + place + "n");
}
}
FORMULA :
The method for finding the location of a hexagon is area = (3three s2)/ 2 in which s is the period of a aspectof the ordinary hexagon.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.