This code is a Python script that utilizes the turtle
module to draw shapes based on coordinates and colors extracted from a Microsoft Word document.
- Python 3.x
- turtle module
- re module
- docx module
- Make sure you have Python 3.x installed on your system.
- Install the required modules by running the following command:
pip install turtle docx
- Replace the value of the
source
variable with the name of the Word document (without the file extension) that you want to extract coordinates and colors from. Place the Word document in the same directory as the script. - Run the script using the following command:
python script.py
- The script will read the Word document and extract coordinate and color data from it.
- A turtle graphics window will open, and the script will draw shapes based on the extracted data.
- The script imports the necessary modules:
turtle
,re
(regular expressions), anddocx
(for working with Word documents). - It initializes some variables including the
source
which specifies the name of the Word document. - The script opens the Word document using the
docx
module and reads its paragraphs. - For each paragraph, it uses regular expressions to extract coordinate tuples and color tuples from the text.
- The extracted data is stored in the
coordinates
andcolour
lists. - The script creates a turtle object and a turtle screen.
- Various settings are configured for the turtle graphics, such as speed, hiding the turtle, and setting the screen to fullscreen mode.
- The script iterates over the extracted coordinates and colors, and for each set, it sets the pen color and begins filling.
- It then iterates over the coordinate pairs and draws lines between them to form shapes.
- Finally, it ends the fill, hides the turtle, and starts the turtle screen main loop to display the drawn shapes.
Note: The script ignores any paragraphs in the Word document that do not match the expected coordinate and color patterns.
Feel free to customize the code according to your needs or incorporate it into a larger project. Happy drawing!