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

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator