code.org > Artista 2

1

Un triangolo

import turtle

WIDTH =500
HEIGHT=500

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 1")
turtle.shape('turtle')
turtle.pensize(5)

for i in range(3):
    turtle.forward(150)
    turtle.right(120)

2

Due triangoli con colore casuale

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 2")
turtle.shape('turtle')
turtle.pensize(5)

colore_casuale()
for j in range(3):
    turtle.forward(150)
    turtle.right(120)

turtle.right(90)

colore_casuale()
for j in range(3):
    turtle.forward(150)
    turtle.right(120)

3

Quattro triangoli con colore casuale

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 3")
turtle.shape('turtle')
turtle.pensize(5)

for i in range(4):
    colore_casuale()
    for j in range(3):
        turtle.forward(150)
        turtle.right(120)
    turtle.right(90)

4

Dieci triangoli con colore casuale

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 4")
turtle.shape('turtle')
turtle.pensize(5)

for i in range(10):
    colore_casuale()
    for j in range(3):
        turtle.forward(150)
        turtle.right(120)
    turtle.right(36)

5

Trentasei triangoli con colore casuale

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():    
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 5")
turtle.shape('turtle')
turtle.pensize(5)
turtle.speed(0)

for i in range(36):
    colore_casuale()
    for j in range(3):
        turtle.forward(150)
        turtle.right(120)
    turtle.right(10)

6

Un quadrato

import turtle

WIDTH =500
HEIGHT=500

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 6")
turtle.shape('turtle')
turtle.pensize(5)

turtle.left(90)
for i in range(4):
    turtle.forward(25)
    turtle.right(90)

7

Dieci quadrati con colore casuale

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 7")
turtle.shape('turtle')
turtle.pensize(5)
turtle.left(90)
turtle.penup()
turtle.backward(125)
turtle.pendown()

for i in range(10):
    colore_casuale()
    for j in range(4):
        turtle.forward(25)
        turtle.right(90)
    turtle.forward(25)

8

Un quadrato costruito con i quadratini con colore casuale

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():    
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 8")
turtle.shape('turtle')
turtle.pensize(5)
turtle.penup()
turtle.setposition(-125, -125)
turtle.setheading(90)
turtle.pendown()
turtle.speed(10)

for i in range(4):
    for j in range(10):
        colore_casuale()
        for k in range(4):
            turtle.forward(25)
            turtle.right(90)
        turtle.forward(25)
    turtle.right(90)

9

Variazione (angolo, posizione iniziale)

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():    
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 9")
turtle.shape('turtle')
turtle.pensize(5)
turtle.penup()
turtle.setposition(-70, -180)
turtle.setheading(120)
turtle.pendown()
turtle.speed(10)

for i in range(4):
    for j in range(10):
        colore_casuale()
        for k in range(4):
            turtle.forward(25)
            turtle.right(90)
        turtle.forward(25)
    turtle.right(80)

10

Variazione …

import random
import turtle

WIDTH =500
HEIGHT=500

def colore_casuale():    
    red  =random.random()
    green=random.random()
    blue =random.random()
    turtle.pencolor(red, green, blue)

turtle.setup(WIDTH, HEIGHT)
turtle.title("Artista 2 - 10")
turtle.shape('turtle')
turtle.pensize(5)
turtle.penup()
turtle.setposition(-150, -125)
turtle.setheading(90)
turtle.pendown()
turtle.speed(10)

for i in range(9):
    for j in range(10):
        colore_casuale()
        for k in range(4):
            turtle.forward(25)
            turtle.right(90)
        turtle.forward(25)
    turtle.right(80)

Lascia un commento