import Graphics; import Graphics2D; import GUI; // グラフィックスデータとレンダラーの生成 int graphicsID = newGraphics( ); int rendererID = newGraphics2DRenderer( 800, 600, graphicsID ); // 表示画面の生成 int windowID = newWindow( 0, 0, 800, 600, " Hello 2DCG ! " ); int labelID = newImageLabel( 0, 0, 800, 600, graphicsID ); mountComponent( labelID, windowID ); // 背景色を白に設定してクリア setGraphics2DColor( rendererID, 255, 255, 255, 255 ); clearGraphics2D( rendererID ); // ========================= // 描画処理 ここから // ========================= // (0,0)と(100,100)を結ぶ線を描画(赤色) setDrawColor( rendererID, 255, 0, 0, 255 ); drawLine( rendererID, 0, 0, 100, 100 ); // (100,100)を左上とする(500×300)の長方形を描画(青色) setDrawColor( rendererID, 0, 0, 255, 255 ); drawRectangle( rendererID, 100, 100, 500, 300, true ); // (100,300) を左上とする(300×200)の楕円を描画(マゼンタ) setDrawColor( rendererID, 255, 0, 255, 255 ); drawEllipse( rendererID, 100, 300, 300, 200, true ); // 多角形、折れ線スプライト用のx 配列、y 配列を用意 int x[ 3 ]; x[ 0 ] = 100; x[ 1 ] = 300; x[ 2 ] = 300; int y[ 3 ]; y[ 0 ] = 100; y[ 1 ] = 100; y[ 2 ] = 300; // x 配列、y 配列を頂点とする多角形を描画(黄色) setDrawColor( rendererID, 255, 255, 0, 255 ); drawPolygon( rendererID, x, y, true ); // x 配列、y 配列を頂点とする折れ線を描画(赤色) setDrawColor( rendererID, 255, 0, 0, 255 ); drawPolyline( rendererID, x, y ); // (300,50)にテキストを描画(黒色) setDrawFontSize( rendererID, 30 ) ; // 文字サイズを 30pt に string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; setDrawColor( rendererID, 0, 0, 0, 255 ); drawText( rendererID, 300, 50, 250, 35, text ); // 画像ファイル「Test.png」を読み込んで描画 int testGraphics = newGraphics( "Test.png" ); drawImage( rendererID, 300, 100, 300, 300, testGraphics ); // ========================= // 描画処理 ここまで // ========================= // 画面の描画 paintComponent( labelID ); paintComponent( windowID );