Skip to content

engoti/design_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

design_python

Checkerboard Drawing Program This Python program uses the turtle graphics library to draw a 5x5 checkerboard pattern on the screen. Each square alternates between black and white, creating a classic checkerboard appearance.

Requirements Python 3.x turtle library (comes pre-installed with Python) Code Overview Constants The program begins by defining several constants:

ANIMATION_SPEED: Controls the speed of the turtle's movement. Set to 0 for the fastest drawing. SCREEN_WIDTH and SCREEN_HEIGHT: Define the width and height of the drawing area. NUM_SQUARES_IN_A_ROW and NUM_SQUARES_IN_A_COL: Set the number of squares per row and column in the checkerboard. SQUARE_WIDTH: Calculates the width of each square based on the screen width and the number of squares in a row. SCREEN_LEFT_EDGE_X and SCREEN_TOP_EDGE_Y: Set the coordinates for the top-left corner of the drawing area. FIRST_X, LAST_X, FIRST_Y, LAST_Y: Define the starting and ending coordinates for rows and columns to position each square on the board. square Function The square function is used to draw an individual square. It takes the following parameters:

x and y: Coordinates for the lower-left corner of the square. width: Side length of the square. color: Fill color for the square. The function positions the turtle at (x, y), fills the square with the specified color, and draws four sides by turning 90 degrees after each line.

main Function The main function sets up the drawing area and turtle properties, then draws the checkerboard pattern.

Steps: Sets up the screen size. Initializes the turtle speed and hides the turtle for a cleaner drawing. Loops over each row and column within the defined screen boundaries to position each square. Alternates the color between black and white to create the checkerboard pattern. Running the Program To run the program, simply execute the script. The turtle graphics window will open, and a 5x5 checkerboard will be drawn on the screen.

Example python Copy code

Run the code to generate a 5x5 checkerboard with alternating black and white squares

main() This program can be modified by adjusting the constants to create checkerboards of different sizes or colors.

Notes Ensure that the turtle graphics window remains open until you manually close it. The code uses basic decision structures and looping to alternate colors and position squares. License This program is open-source and free for personal or educational use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages