Thursday, November 29, 2007

Random colors

Most people did random colors by selecting one from a set of several using if statments (e.g., if :rn = 2 [...set pen to second color choice...]), but here's a way of making an even more unknown color:


to randomColor

make "myRed random 256
make "myGreen random 256
make "myBlue random 256

setpc (list :myRed :myGreen :myBlue)
setfc (list :myRed :myGreen :myBlue)

end


The syntax of making a list took a little while to figure out!

Supposing that you are calling the code for making a square frame in the center of the screen centerSquare, this code will fill it with color, over and over:


to go
cs

repeat 50 [
randomColor
centerSquare
fill

wait 35
]

end

Final project

It's a program with a lot of latitude and a few strict requirements. For complete information, click here.

I will be happy to help. It's best to e-mail me your code and then come see me. Second best: e-mail me your code and call me while you're at your computer. For design help, be sure to ask before final exams begin.

Due before Monday, December 17, at 6 p.m.

Logo day 5

Still looking for that sweet surprise...

Tuesday, November 27, 2007

Logo day 4

Today we will talk about x-y geometry in Logo. Then you can choose to use either x-y or turtle geometry in your program.

Working with your partner, finish the program surprise with (at least!) these three elements:

  • randomly chosen regular polygon

  • drawn in a randomly chosen location

  • in a randomly chosen color


Randomly means not known in advance, with each possible outcome equally likely.

Suggestion: work on the three required elements separately, then combine them. Everything you need to know is in the Logo handout! The beauty of programming is that you don't have to do it in a prescribed way; you are free to invent your own alternative way of doing things.

Submit your work by showing it to me at your desk, then copying the text of your program (with all its procedures) into an e-mail to me. Make sure that both programmers' names are included.

It is OK to make a diffeent program of equal complexity, but check with me first!

Monday, November 26, 2007

Tuesday, November 20, 2007

Logo day 3

Today's topics:


  • saving your program


  • making a regular polygon of n sides


  • using random numbers



Today's assignment: write a program called surprise that draws a regular polygon whose number of sides and color are randomly chosen. For this, you will need to decide in advance on a collection of colors.

If this is easy for you, then snazz it up — ask for suggestions if you need them.

Here's a link to my page of Logo miscellanies.

Logo colors galore

Last week we talked about how colors are made: a familiar topic, since we had looked at binary numbers and RGB before. The syntax of Logo requires a list of three values in the range [0, 255] for each color component: for example,

      setpc [255 0 0]

to set pencolor all red, no green, no blue.

We also talked about writing subprograms, such as:


to square :n
repeat 4 [
fd :n
rt 90
]
end


Page 16 of the handout tells us how to write a procedure that allows us to use color names of our own choosing:


to blue
op [0 0 255]
end


With this, we can say, setpc blue rather than setpc [0 0 255]. This excellent technique is one of many great things offered by Simone Rudge here.

I encourage you to make a palette of your own pet colors.

You can see my variations on the Rudge technique in these files — one, two.

Thursday, November 15, 2007

Logo day 2

Thoughts for the day:

  • It's a lot easier to think of drawing a square by saying

            square

    than by saying

            repeat 4 [fd 100 rt 90]

  • It's a lot easier to think about what you're doing if you say

            repeat 8 [ square rt 360/8 ]

    than if you say

            repeat 8 [ repeat 4 [ fd 100 rt 90 ] rt 360/8]

    — isn't it?


  • It sure would be nice if all the squares weren't the same size, wouldn't it?


  • And it sure would be cool if not all the polygons were squares.

Tuesday, November 13, 2007

Logo day 1

Today I will bring hard copies of my minimum opus on Logo, which you may also view here — click.

In case you're at a machine without Logo, download this, which is MSW Logo by George Mills et al.

I do hope that you will find this art site as inspirational as I do.

Here's a concise list of commands for Logo, which is taken from this wonderful complete college course in computing with Logo.

You can also read Brian Harvey's books online (scroll down the page) — click. Serious fun.

Thursday, November 08, 2007

Tuesday, November 06, 2007

Programming day 3

Here's a presentation on programming we've done so far: click

Today, flowcharts and some more looping and arithmetic. The big challenge: allow the user to enter numbers and find their average.