import Graphics; import Graphics2D; import GUI; // Create a graphics resource and renderer int graphicsID = newGraphics( ); int rendererID = newGraphics2DRenderer( 800, 600, graphicsID ); // Create the display window int windowID = newWindow( 0, 0, 800, 600, " Hello 2DCG ! " ); int labelID = newImageLabel( 0, 0, 800, 600, graphicsID ); mountComponent( labelID, windowID ); // Set background to white and clear setGraphics2DColor( rendererID, 255, 255, 255, 255 ); clearGraphics2D( rendererID ); // ========================= // Drawing section starts here // ========================= // Draw a red line from (0, 0) to (100, 100) setDrawColor( rendererID, 255, 0, 0, 255 ); drawLine( rendererID, 0, 0, 100, 100 ); // Draw a filled blue rectangle at (100, 100), size 500 x 300 setDrawColor( rendererID, 0, 0, 255, 255 ); drawRectangle( rendererID, 100, 100, 500, 300, true ); // Draw a filled magenta ellipse at (100, 300), size 300 x 200 setDrawColor( rendererID, 255, 0, 255, 255 ); drawEllipse( rendererID, 100, 300, 300, 200, true ); // Prepare vertex arrays for polygon and polyline int x[ 3 ]; x[ 0 ] = 100; x[ 1 ] = 300; x[ 2 ] = 300; int y[ 3 ]; y[ 0 ] = 100; y[ 1 ] = 100; y[ 2 ] = 300; // Draw a filled yellow polygon using the vertex arrays setDrawColor( rendererID, 255, 255, 0, 255 ); drawPolygon( rendererID, x, y, true ); // Draw a red polyline using the same vertex arrays setDrawColor( rendererID, 255, 0, 0, 255 ); drawPolyline( rendererID, x, y ); // Draw black text at (300, 50) setDrawFontSize( rendererID, 30 ) ; // Set font size to 30pt string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; setDrawColor( rendererID, 0, 0, 0, 255 ); drawText( rendererID, 300, 50, 250, 35, text ); // Load and draw an image from "Test.png" at (300, 100) int testGraphics = newGraphics( "Test.png" ); drawImage( rendererID, 300, 100, 300, 300, testGraphics ); // ========================= // Drawing section ends here // ========================= // Draw the GUI paintComponent( labelID ); paintComponent( windowID );