Sierpinski Triangle - Sierpinski Triangle Randomness and...

• 4

This preview shows page 1 - 2 out of 4 pages.

Sierpinski Triangle#----------------------------------------------------------------------# Randomness and the Sierpinski Gasket# See page 261 of the Computer Science Companion## Copyright (C) February 17, 2017 -- Dr. William T. Verts## Once the random library has been imported:# import random# then a whole bunch of functions become available:# random.random() returns a float >= 0.0 and < 1.0# random.randrange(N) returns an int >= 0 and < N# random.randint(M,N) returns an int >= M and <= N# random.choice(L) returns a value from the list L# random.seed(N) restarts the random sequence at N## I wish to create a drawing using randomness. First, pick three 2D# points P0, P1, and P2, where each has an X and Y value. For example,# point P0 would be defined by variables P0X and P0Y. Initially, the# three points are placed at the top center of the canvas, lower left# corner, and lower right corner. The three points don't move.## Pick a fourth point PP that will move around the screen. Start it# at P0. In an infinite loop: pick one of the three fixed points at# random, then move PP to a point halfway between its current position