Draw Rotated Squares using Python with Turtle Graphics


RotatedSquares.py, Python script to draw Rotated Squares using Turtle Graphics.
(code copied from https://deborahrfowler.com/MathForVSFX/RotatedSquares.html)
# Rotated Squares
#
# program to draw continually shrinking squares to give an interesting pattern
#
# Author: Deborah R Fowler
# Date: Jan 11, 2020
#
# input: none
# output: interesting pattern
#

import turtle

def drawSquare(t,size,angle):
    t.left(angle)
    halfsize = size * .5
    t.pu()
    t.setpos(0,0)
    t.backward(halfsize)
    t.left(90)
    t.backward(halfsize)
    t.right(90)
    t.pd()

    for i in range(0,4):
        t.fd(size)
        t.left(90)


def drawSquarePattern(t):
    t.color("black")
    drawSquare(t,700,0)
    for i in range(0,20):
        size = 700 * pow(1/1.2,i+1)
        drawSquare(t,size,12.5)
    t.ht()

def main():
    turtle.setup(750,750)
    turtle.title("Rotated Squares")
    t = turtle.Pen()
    t.width(2)
    t.speed(0)
    drawSquarePattern(t)
    turtle.exitonclick()

main()



Comments

Popular posts from this blog

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.

CameraWebServe: ESP32-S3 (arduino-esp32) + OV5640 camera module