Rhombus Madness

Use Python and Turtle and Random library to draw the 50 random Rhombus shapes as shown in the following figure.

50 Random Rhombus

Hints:

  • Make a function that draws a rhombus given the center, width, height, and the direction.
  • Use random library’s uniform function to generate positions, size, direction, and color

Related Projects:

Projects with similar difficulty

Geometry

Circle of Isosceles Triangles with Python and Turtle

Use the Isosceles triangle function created in this project, draw the circle of isosceles triangles as shown below. Your code should easily change the number of triangles, and radius and height of the triangles.

Source Code:

from turtle import *
import math
import random

title('Isosceles Triangle Circle - PythonTurtle.Academy')
setup(1000,1000)
setworldcoordinates(-500,-500,500,500)
hideturtle()
tracer(0,0)

# x,y is the center of the base, width: length of base, height: height of triangle from the top to base
# direction:direction from the center of base to top
def IsoscelesTriangle(x,y,width,height,direction,c):
    up()
    goto(x,y)
    seth(direction-90)
    fd(width/2)
    p1x, p1y = xcor(), ycor() # first point: bottom right
    back(width)
    p2x, p2y = xcor(), ycor() # second point: bottom left
    goto(x,y)
    seth(direction)
    fd(height)
    p3x, p3y = xcor(), ycor() # third point: top
    goto(p1x,p1y)
    down()
    fillcolor(c)
    begin_fill()
    goto(p2x,p2y)
    goto(p3x,p3y)
    goto(p1x,p1y)
    end_fill()

n=12
r=300
width=2*r*math.sin(math.radians(180/n))
height=200
for i in range(n):    
    IsoscelesTriangle(r*math.cos(math.radians(180/n))*math.cos(math.radians(i*360/n)),
                      r*math.cos(math.radians(180/n))*math.sin(math.radians(i*360/n)),width,height,i*360/n,'blue')
    
update()

Related Projects:

Geometry

Loops

Isosceles Triangle Madness

Use Python and Turtle and Random library to draw the 50 random isosceles triangles as shown in the following figure.

50 Random Isosceles Triangles

Hints:

  • Make a function that draws isosceles triangle given the center of the base, length of the base, height, and the direction from the base to the top of the triangle.
  • Use random library’s uniform function to generate positions, size, direction, and color.

Source Code:

from turtle import *
import math
import random

title('Isosceles Triangle Madness - PythonTurtle.Academy')
setup(1000,1000)
setworldcoordinates(-500,-500,500,500)
hideturtle()
tracer(0,0)

# x,y is the center of the base, width: length of base, height: height of triangle from the top to base
# direction:direction from the center of base to top
def IsoscelesTriangle(x,y,width,height,direction,c):
    up()
    goto(x,y)
    seth(direction-90)
    fd(width/2)
    p1x, p1y = xcor(), ycor() # first point: bottom right
    back(width)
    p2x, p2y = xcor(), ycor() # second point: bottom left
    goto(x,y)
    seth(direction)
    fd(height)
    p3x, p3y = xcor(), ycor() # third point: top
    goto(p1x,p1y)
    down()
    fillcolor(c)
    begin_fill()
    goto(p2x,p2y)
    goto(p3x,p3y)
    goto(p1x,p1y)
    end_fill()

for _ in range(50):
    IsoscelesTriangle(random.uniform(-400,400),random.uniform(-400,400),
                      random.uniform(30,300), random.uniform(30,300),
                      random.uniform(0,360),
                      (random.uniform(0,1),random.uniform(0,1),random.uniform(0,1)))
              
update()

Related Projects

Pentagon Spiral with Python and Turtle

Draw the following spiral with pentagon shape. In each loop, increase the forward length and turn slightly less than 72 degrees.

Pentagon Spiral

Source Code:

import turtle
screen = turtle.Screen()
screen.title('Pentagon Spiral - PythonTurtle.Academy')
turtle.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()

for i in range(10,1175,4):
    turtle.fd(i)
    turtle.left(71.5)

Square Spiral with Python and Turtle (Source Code)

Draw the following spiral with square shape. In each loop, increase the forward length and turn slightly less than 90 degrees.

Square Spiral

Source Code:

import turtle
screen = turtle.Screen()
screen.title('Square Spiral - PythonTurtle.Academy')
turtle.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()

for i in range(10,1800,6):
    turtle.fd(i)
    turtle.left(89.7)

Triangle Spiral with Turtle (Source Code)

Draw the following spiral with triangle shape. In each loop, increase the forward length and turn slightly less than 120 degrees.

Triangle Spiral with Python and Turtle

Source Code:

import turtle
screen = turtle.Screen()
screen.title('Triangle Spiral - PythonTurtle.Academy')
turtle.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()

for i in range(10,1550,9):
    turtle.fd(i)
    turtle.left(119.3)

Sixteen-Petal Flower with Python Turtle

Knowing how to draw a football shape, draw a sixteen petal flower with loop and custom function.

16-Petal Flower with Python Turtle

Code:

import turtle
turtle.title('Sixteen Petals - PythonTurtle.Academy')
turtle.setworldcoordinates(-2000,-2000,2000,2000)

def draw_football(x,y,tilt,radius):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    turtle.seth(tilt-45)
    turtle.circle(radius,90)
    turtle.left(90)
    turtle.circle(radius,90)

for tilt in range(0,360,30): 
    draw_football(0,0,tilt,1000)