Desenha a teia(triângulo) de Sierpinski.
# Título ##################################################### # # Sierpinski V 16-02-2023 # ############################################################## # # Carlos Paulo A. Freitas (cpaulof@gmail.com) # https://zonaexacta.blogspot.com # https://sites.google.com/view/cpaulof-prog-calc # ############################################################## import time import random import kandinsky from math import * #Cores: vou deixar 8 cores F=255 cores = [ [0,0,0], #0 preto [F,F,F], #1 branco [F,0,0], #2 vermelho [0,F,0], #3 verde [0,0,F], #4 azul [F,0,F], #5 violeta [F,F,0], #6 vermelho+verde= [0,F,F], #7 [204,153,0] #8 ] C,S=cos(pi/6),sin(pi/6) vertices=[ [C,-S], [0,1], [-C,-S] ] LARGURA=320 ALTURA=220 U=LARGURA/ALTURA A=1.5 X_MIN =-A*U/2 X_MAX =A*U/2 Y_MIN =-0.5 Y_MAX =1 ################################ def plot(x,y,cor): c = int(LARGURA*((x - X_MIN)/(X_MAX - X_MIN))) l = int(ALTURA*(1-(y - Y_MIN)/(Y_MAX - Y_MIN))) if(0 <= l < ALTURA): if(0 <= c < LARGURA): col = kandinsky.color(cores[cor][0],cores[cor][1],cores[cor][2]) kandinsky.set_pixel(c,l,col) ################################ kandinsky.fill_rect(0,0,LARGURA,ALTURA+20,cores[0]) x = 0 #random.random() y = 1 #random.random() cor = random.randint(1,8) for i in range(10000): n = random.randint(0,2) x,y =0.5*(x+vertices[n][0]),0.5*(y+vertices[n][1]) plot(x,y,cor)