program HowToDrawRandomShape; uses SwinGame,sgTypes; procedure Main(); var i : Integer; begin OpenGraphicsWindow('How To Draw Random Shape' ,800 ,600 ); LoadDefaultColors(); ClearScreen(ColorWhite ); repeat ProcessEvents(); i := Rnd(7 ); case i of 0 : DrawCircle(RandomColor() ,Rnd(800 ) ,Rnd(600 ) ,Rnd(300 ) ) 1 : DrawEllipse(RandomColor() ,Rnd(800 ) ,Rnd(600 ) ,Rnd(800 ) ,Rnd(600 ) ) 2 : DrawHorizontalLine(RandomColor() ,Rnd(600 ) ,Rnd(800 ) ,Rnd(800 ) ) 3 : DrawLine(RandomColor() ,Rnd(800 ) ,Rnd(600 ) ,Rnd(800 ) ,Rnd(600 ) ) 4 : DrawRectangle(RandomColor() ,Rnd(800 ) ,Rnd(600 ) ,Rnd(800 ) ,Rnd(600 ) ) 5 : DrawTriangle(RandomColor() ,Rnd(800 ) ,Rnd(600 ) ,Rnd(800 ) ,Rnd(600 ) ,Rnd(800 ) ,Rnd(600 ) ) 6 : DrawVerticalLine(RandomColor() ,Rnd(800 ) ,Rnd(600 ) ,Rnd(600 ) ) end; RefreshScreen(60 ); until WindowCloseRequested() or KeyTyped(vk_ESCAPE ) or KeyTyped(vk_q ); ReleaseAllResources(); end; begin Main(); end.
How To Draw Random Shapes
This intermediate level how to, walks you through creating random shapes. This is a neat, relatively simple how to that may teach you how to create a screan saver or add random selection to your project.
Level
IntermediateDetails
In the previous how to, Draw primitive shapes we saw how easy it was to . To randomize the drawing of a shape we simple add a random function and a switch statement to test the result.
Follow the code below and change the RefreshScreen rate to alter the result.
Possibilities
- In a new project construct a shape fro, primitives , such as a stick figure, a train or a house. Ensure the measurements are dynamic and run the program where the shape is drawn in random sizes.