You are on page 1of 2

2.1 What are the differences between object transformations and viewing transformations?

Transformasi objek mengubah bentuk dan lokasi dari objek visual untuktransformasi yang diterapkan. Transformasi melihat tidak mengubah model dunia maya, tapi mereka mengubah pandangan seluruh adegan pada ruang dunia.

2.2 Plot the following points in a 2D coordinate system:

(1, 3), (-2,1.5), (0, -2), (0, 0)

2.3 Find the coordinates of the vertices of the triangle (0,0) ; (2,3) ; (3,1)

2.4 Write the Java code to construct an ellipse of width 80 and height 100 centered at (100, 300).

package chapter2; import import import import java.awt.*; java.awt.event.*; javax.swing.*; java.awt.geom.*;

public class Hello2D extends JApplet { public static void main(String s[]) { JFrame frame = new JFrame(); frame.setTitle("Hello 2D"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 13 JApplet applet = new Hello2D(); 14 applet.init(); 15 frame.getContentPane().add(applet); 16 frame.pack(); 17 frame.setVisible(true); 18 } 19 20 public void init() { 21 JPanel panel = new Hello2DPanel(); 22 getContentPane().add(panel); 23 } 24 } 25 26 class Hello2DPanel extends JPanel { 27 public Hello2DPanel() { 28 setPreferredSize(new Dimension(640, 480)); 29 } 30 31 public void paintComponent(Graphics g) { 32 super.paintComponent(g); 33 Graphics2D g2 = (Graphics2D)g; 34 g2.setColor(Color.blue); 35 Ellipse2D e = new Ellipse2D.Double(-100, -50, 200, 100); 36 AffineTransform tr = new AffineTransform(); 37 tr.rotate(Math.PI / 6.0); 38 Shape shape = tr.createTransformedShape(e); 39 g2.translate(300,200); 40 g2.scale(2,2); 41 g2.draw(shape); 42 g2.drawString("Hello 2D", 0, 0); 43 } 44 }

You might also like