How To Draw Primitive Shapes

This article will show you how to draw basic shapes in SwinGame.

howtodrawprimitiveshapes

Level

Beginner

Read these first

How To Refresh The Screen

Details

SwinGame allows you to draw triangle, rectangle, square, circle, ellipse. To draw these shape you need to:

  1. Make sure your code is opening SwinGame's graphic windows
  2. Clear the screen
  3. Work out what shape you want to draw, their color, and coordinates
  4. Call the required method to draw that particular shape
  5. Refresh the screen
  6. Set how long you want your windows to appear for
  7. Released all resources
  8. Run the program

Under Read These First is a screenshot showing what the program look like and below is the code for it.

Source Code Widget

  • program HowToDrawPrimitiveShapes;
    uses SwinGame,sgTypes;
    
    procedure Main();
    
    begin
        OpenGraphicsWindow('Primitive shapes' ,800 ,250 );
        LoadDefaultColors();
        ClearScreen(ColorWhite );
        DrawCircle(ColorBlack ,50 ,50 ,30 );
        DrawEllipse(ColorBlue ,150 ,20 ,120 ,60 );
        DrawLine(ColorGreen ,300 ,40 ,450 ,40 );
        DrawRectangle(ColorGrey ,500 ,20 ,100 ,60 );
        DrawTriangle(ColorPink ,650 ,80 ,750 ,80 ,700 ,20 );
        FillCircle(ColorMagenta ,50 ,160 ,30 );
        FillEllipse(ColorRed ,150 ,130 ,120 ,60 );
        FillRectangle(ColorTurquoise ,300 ,130 ,100 ,60 );
        FillTriangle(ColorYellow ,500 ,190 ,700 ,190 ,600 ,130 );
        RefreshScreen();
        Delay(5000 );
        ReleaseAllResources();
    end;
    begin
        Main();
    end.
    Download Now"
  • #include 
    #include "SwinGame.h"
    int main() 
    {
    
        open_graphics_window("Primitive shapes" ,800 ,250 );
        load_default_colors();
        clear_screen(color_white );
        draw_circle(color_black ,50 ,50 ,30 );
        draw_ellipse(color_blue ,150 ,20 ,120 ,60 );
        draw_line(color_green ,300 ,40 ,450 ,40 );
        draw_rectangle(color_grey ,500 ,20 ,100 ,60 );
        draw_triangle(color_pink ,650 ,80 ,750 ,80 ,700 ,20 );
        fill_circle(color_magenta ,50 ,160 ,30 );
        fill_ellipse(color_red ,150 ,130 ,120 ,60 );
        fill_rectangle(color_turquoise ,300 ,130 ,100 ,60 );
        fill_triangle(color_yellow ,500 ,190 ,700 ,190 ,600 ,130 );
        refresh_screen();
        delay(5000 );
        release_all_resources();
        return 0;
    }
    
    Download Now"
  • Source Code Coming Soon

  • Source Code Coming Soon

  • Source Code Coming Soon


Possibilities

  • Draw different object and thing using shape such as human stick, tank, boat, magnifying glass, snow man.
  • Impress your friend by being creative :)