Randomness Practice

posted by: Ms. Martin 28 February 2011 No Comment

You will show Ms. Martin at least 2 of these to get checked off.  You are expected to be focused and work to the best of your abilities.

1: Flashing lights

Write a Turtle Graphics program that makes the screen flash different colors one after the other.  You will want to use the bgcolor function which works just like color but changes the color of the full screen.

2: Squiggles

Write a Turtle Graphics program that draws random squiggles. Your turtle should go forward a random amount, turn a random amount and draw a line of a random color. Your program should produce output similar to the image at left.

Make sure you understand what the type and range of parameters to forward, right and color are and pick random values that fit.
It turns out random walks have very interesting properties.  Read a little about them if you have time.

3: Colorful pole

Write a Turtle Graphics program that produces a shape similar to the one at the left.  Your pen width will have to change over time and you will have to pick a random color every time you go forward.  Alternately, you could draw circles of increasing radius.

4: ASCII box

Write a function draw_box that takes in three parameters: a width, a height and a character to print. Note that you can multiply text by a number to repeat it — “*” * 10 is “**********”.

draw_box(5, 4, “#”) should output:

#####
#   #
#   #
#####

draw_box(10, 6, “.”) should output:

..........
.        .
.        .
.        .
.        .
..........

5: Random art

Have some fun with this.  What can you come up with?

Believe it or not, the image at the left was randomly generated using a Python program.  Doing something exactly like that requires slightly more advanced material than what we’ve covered but some of you will be perfectly able to do this by the end of the semester!

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 3.75 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>