In: Computer Science
Your task for this assignment is use the Java Canvas and Graphics classes to create an example of a computer generated image. This is an opportunity for you to explore computer graphics and exercise some individual creativity.
You should submit well-documented code, and once your program is done, create a presentation of your program. The presentation can be a PowerPoint or Word document, or something created with similar software. It could be a PDF file.
Tell us what your prject is and how it works. Consider briefly discussing what happened in the process of exploration and design for your project? How does your code work? How did you use other features of Java, such as branching routines or loops in your work? Tell us about the thoughts behind your finished work. What influenced your work?
Your work can be as simple or as complex as you would like, but be careful about taking on something that will be too time consuming. If you decide to work on figurative art, It might help to start with a single idea or concept, such as snowfall in the city, or along the Schuylkill. Abstract or figurative art can both be static or dynamic. Imagine how, for example, the Bedroom Window example at the end of this chapter could be subtly dynamic by havng flashing lights or twinkling stars.
Ask me if you are not sure about something or if you run into trouble.
Your finished image for this project should be suitable for a general audience.
GIVEN THAT:--
Program:
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class TryoutOval { public static void main(String[] args) { new TryoutOval(); } public TryoutOval() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { } JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TryoutPanel(Color.RED)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } public class TryoutPanel extends JPanel { private Color myColor; public TryoutPanel(Color c) { myColor = c; } @Override public Dimension getPreferredSize() { return new Dimension(400, 400); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int centerX = 280; int centerY = 300; int radius = 50; int diameter = radius * 2; int x = centerX - radius; int y = centerY - radius; g.setColor(Color.BLACK); g.drawRect(x, y, diameter, diameter); g.drawLine(x, y, x + diameter, y + diameter); g.drawLine(x + diameter, y, x, y + diameter); g.setColor(myColor); g.drawOval(x, y, diameter, diameter); g.fillOval(centerX - 5, centerY - 5, 10, 10); } } }
Sample output: