Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I was trying to draw a dinosarus facing left of the screen i tried to use different shapes even the coordinate points but it didn't

I was trying to draw a dinosarus facing left of the screen i tried to use different shapes even the coordinate points but it didn't worked, just the draw dino need to be done (private void drawDino(Graphics2D g2d)) image text in transcribed import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel;
public class DrawDino1 { static final int WIDTH = 768; static final int HEIGHT = WIDTH; public DrawDino1() { BufferedImage dino = initDino(); initSwing(dino); } public static void main(String[] args) { EventQueue.invokeLater(DrawDino1::new); } private void initSwing(BufferedImage dino) { JFrame jf = new JFrame("Draw Dino 1"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jp = new DrawPanel(dino); jf.add(jp, BorderLayout.CENTER); jf.setSize(WIDTH, HEIGHT); jf.setLocationRelativeTo(null); jf.setResizable(false); jf.setVisible(true); } static class DrawPanel extends JPanel { private static final long serialVersionUID = 1L; private BufferedImage dino; public DrawPanel(BufferedImage dino) { this.dino = dino; setBackground(Color.WHITE); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setPaint( new GradientPaint( 0.0f, 0.0f, Color.RED, getWidth(), getHeight(), Color.BLUE ) ); g2d.fillRect(0, 0, getWidth(), getHeight()); AffineTransform gat = new AffineTransform(); gat.translate( getWidth() / 2.0 - dino.getWidth() / 2.0, getHeight() / 2.0 - dino.getHeight() / 2.0 ); g2d.transform(gat); g2d.drawRenderedImage(dino, new AffineTransform()); Rectangle2D r2d = new Rectangle2D.Double( 0.0, 0.0, dino.getWidth(), dino.getHeight() ); g2d.setColor(Color.WHITE); g2d.draw(r2d); g2d.dispose(); } } private BufferedImage initDino() { BufferedImage bi = new BufferedImage(513, 513, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bi.createGraphics(); g2d.setPaint(new Color(0x00000000, true)); g2d.fillRect(0, 0, WIDTH, HEIGHT); AffineTransform gat = new AffineTransform(); gat.translate(bi.getWidth() / 2.0, bi.getHeight() / 2.0); gat.scale(224.0, -224.0); g2d.transform(gat); g2d.setStroke(new BasicStroke(0.0f)); drawDino(g2d); g2d.dispose(); return bi; } private void drawDino(Graphics2D g2d) { // just this one Path2D p2d = new Path2D.Double(Path2D.WIND_EVEN_ODD); p2d.moveTo(1.0, -1.0); Ellipse2D e2d1 = new Ellipse2D.Double(-0.5, 0.0625, 0.125, 0.125); Ellipse2D e2d2 = new Ellipse2D.Double(-0.45, 0.0625, 0.0625, 0.0625); g2d.setPaint(Color.WHITE); g2d.fill(e2d1); g2d.setPaint(Color.BLUE); g2d.fill(e2d2); g2d.setPaint(Color.BLACK); g2d.draw(e2d1); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago