#---------------------------------------------------------------------- # Sierpinski Gasket fractal # # Copyright (C) October 4, 2017 -- Dr. William T. Verts # # How can the code be improved? #---------------------------------------------------------------------- import random # I forgot to include this in the program in class def Main(): Canvas = makeEmptyPicture(1000,700) show(Canvas) P0X = getWidth(Canvas) / 2 # P0 fixed on top row, center P0Y = 0 P1X = 0 # P1 fixed at lower left corner P1Y = getHeight(Canvas) - 1 P2X = getWidth(Canvas) - 1 # P2 fixed at lower right corner P2Y = getHeight(Canvas) - 1 PX = P0X # P allowed to move around PY = P0Y Count = 0 while (True): N = random.randrange(3) if (N == 0): PX = (PX + P0X) / 2 PY = (PY + P0Y) / 2 C = red elif (N == 1): PX = (PX + P1X) / 2 PY = (PY + P1Y) / 2 C = green else: PX = (PX + P2X) / 2 PY = (PY + P2Y) / 2 C = blue PIX = getPixel(Canvas,PX,PY) setColor(PIX,C) Count = Count + 1 if Count == 10000: repaint(Canvas) Count = 0 return