Advertisement
Juan101

rectangulo

Dec 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from turtle import *
  2. from random import *
  3.  
  4. colormode(255)
  5.  
  6. def randomcolor():
  7.     red = randint(0, 255)
  8.     green = randint(0, 255)
  9.     blue = randint(0, 255)
  10.     color(red, green, blue)
  11.  
  12. def randomplace():
  13.     penup()
  14.     x = randint(-200, 200)
  15.     y = randint(-200, 200)
  16.     goto(x, y)
  17.     pendown()
  18.  
  19. def randomheading():
  20.     numero = randint(1, 360)
  21.     setheading(numero)
  22.    
  23. def area(largo, alto):
  24.     return alto * largo
  25.  
  26. def perimetro(largo, alto):
  27.     return 2 * (largo + alto)
  28.  
  29. def drawrectangulo():
  30.     randomcolor()
  31.     randomplace()
  32.     #randomheading()
  33.     hideturtle()
  34.     largo = randint(100, 150)
  35.     alto = randint(100, 150)
  36.     begin_fill()
  37.     forward(largo)
  38.     right(90)
  39.     forward(alto)
  40.     right(90)
  41.     forward(largo)
  42.     right(90)
  43.     forward(alto)
  44.     right(90)
  45.     end_fill()
  46.    
  47.     penup()
  48.     goto(0, 0)
  49.     pendown()
  50.     write("Area: " + str(area(largo, alto)))
  51.    
  52.     penup()
  53.     goto(0, -10)
  54.     pendown()
  55.     write("perimetro: " + str(perimetro(largo, alto)))
  56.  
  57.  
  58. shape()
  59. speed(0)
  60.  
  61.  
  62.  
  63. clear()
  64. setheading(0)
  65.  
  66. for i in range (1):
  67.     drawrectangulo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement