Home > Archive > Tcl > May 2004 > Teaching [canvas]
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| John Seal 2004-05-16, 7:31 pm |
| I am in the process of teaching Tcl to a 6th grader. I introduced
[canvas] with this toy program that illustrates what I consider to be
its two great strengths, tagging and binding:
# Draw a smiley face.
canvas .c -width 300 -height 300 -highlightthickness 0
grid .c
..c create oval 0 0 300 300 -fill yellow -width 0
..c create oval 80 70 120 130 -fill black -width 10 -tag eye
..c create oval 180 70 220 130 -fill black -width 10 -tag eye
..c create arc 0 0 300 230 -fill black -tag mouth \
-style arc -start 225 -extent 90 -width 20
# Add rollover animation for opening mouth.
..c bind mouth <Enter> {.c itemconfigure mouth -style chord}
..c bind mouth <Leave> {.c itemconfigure mouth -style arc}
# Add rollover animation for winking eyes.
..c bind eye <Enter> {.c itemconfigure current -fill yellow}
..c bind eye <Leave> {.c itemconfigure current -fill black}
What do you think would be a logical next step in teaching [canvas]?
It's such a complex widget that I could spend a great deal of time
teaching every nook and cranny, which I don't intend to do. What
[canvas] concepts have the best "payoff" in terms of power, simplicity,
and utility?
I think changing the coords of an item is one, probably by illustrating
a drag binding. Scaling is probably another. What else? What are your
favorite [canvas] features?
| |
| Arjen Markus 2004-05-17, 5:31 am |
| John Seal wrote:
>
> I am in the process of teaching Tcl to a 6th grader. I introduced
> [canvas] with this toy program that illustrates what I consider to be
> its two great strengths, tagging and binding:
>
> # Draw a smiley face.
> canvas .c -width 300 -height 300 -highlightthickness 0
> grid .c
> .c create oval 0 0 300 300 -fill yellow -width 0
> .c create oval 80 70 120 130 -fill black -width 10 -tag eye
> .c create oval 180 70 220 130 -fill black -width 10 -tag eye
> .c create arc 0 0 300 230 -fill black -tag mouth \
> -style arc -start 225 -extent 90 -width 20
>
> # Add rollover animation for opening mouth.
> .c bind mouth <Enter> {.c itemconfigure mouth -style chord}
> .c bind mouth <Leave> {.c itemconfigure mouth -style arc}
>
> # Add rollover animation for winking eyes.
> .c bind eye <Enter> {.c itemconfigure current -fill yellow}
> .c bind eye <Leave> {.c itemconfigure current -fill black}
>
> What do you think would be a logical next step in teaching [canvas]?
> It's such a complex widget that I could spend a great deal of time
> teaching every nook and cranny, which I don't intend to do. What
> [canvas] concepts have the best "payoff" in terms of power, simplicity,
> and utility?
>
> I think changing the coords of an item is one, probably by illustrating
> a drag binding. Scaling is probably another. What else? What are your
> favorite [canvas] features?
You might find one of the doodle scripts on the Wiki of interest.
I like the way you can order items, as this gives you the opportunity
to do 3D graphics in a cheap way, but that might be a bit troublesome
to teach ...
Now here is a script that might impress users (not so much the
code, as well as the ability of Tk to create very convoluted
polygons): <http://mini.net/tcl/8854> - look at the end of that
page and set the parameter alpha to different values (including > 1)
Regards,
Arjen
| |
| Donal K. Fellows 2004-05-18, 5:31 am |
| John Seal wrote:
> I am in the process of teaching Tcl to a 6th grader. I introduced
> [canvas] with this toy program that illustrates what I consider to be
> its two great strengths, tagging and binding:
[...]
> What do you think would be a logical next step in teaching [canvas]?
[...]
> I think changing the coords of an item is one, probably by illustrating
> a drag binding. Scaling is probably another. What else? What are your
> favorite [canvas] features?
I think you've got a good plan there. :^)
Other features to think about are scrolling, key bindings, altering
coordinates of single control points, and animation. Once they've got
all those things, the world will be their oyster.
Complex item selection, window embedding, response to resizing and
postscript generation are probably features to ignore for now. They're
really powerful and neat, but can probably wait until they're in the 7th
grade... ;^)
Donal.
| |
| John Seal 2004-05-18, 9:35 am |
| Donal K. Fellows wrote:
> Complex item selection, window embedding, response to resizing and
> postscript generation are probably features to ignore for now. They're
> really powerful and neat, but can probably wait until they're in the 7th
> grade... ;^)
I've convinced Raytheon to let me teach a Tcl course later this summer;
I told them I could probably take the 6th grade course and dumb it down
for engineers!
So far I've completed eight lessons, all with either exercises or sample
programs. Most have been developed "one lesson ahead of the student".
My approach, which has worked out very well, has been to present
programs that do something interesting but are beyond the student's
current level of understanding, then teach the new concepts needed to
understand them. (This maintains a "That's Cool!" attitude, although
the actual expression elicited is "That's Pimp!".) It was very
gratifying to see the speed with which the student picked up "by
example" when to use what kind of braces and quotes, and other idiomatic
patterns.
So far the "big" sample programs have been an interactive tic-tac-toe
board and a sliding tile puzzle. I'm teaching Tk as an integral part of
the language. In other words, no traditional language-learning
exercises that read stdin and write stdout; all I/O is through widgets,
although I did have lots of command-line exercises for [puts].
That reminds me of an anomaly I encountered when setting up the
student's ancient Mac Performa 575 33MHz 68K machine. I installed both
a full Tcl/Tk (although I don't recall exactly what version) and a
Tclkit of the same version. Both take *forever* to launch! I tried to
add a ::tk::mac::openDocument handler to the full version, so we could
drag&drop exercises, but I can't get it to work; just having an empty
handler by that name prevents it from starting up properly, so we have
been using the Tclkit instead. Any idea what's up with that?
Another question that I have is, should I explicitly teach the
Endekalogue at some point, or just refer to it when certain important
idioms show up?
| |
| Donal K. Fellows 2004-05-18, 11:33 am |
| John Seal wrote:
> Another question that I have is, should I explicitly teach the
> Endekalogue at some point, or just refer to it when certain important
> idioms show up?
I wouldn't focus on it too much except perhaps as reference material.
It's one of these documents that is written very precisely, but which
people often read expecting it to be non-normative. Not many people are
ready to grasp that it means exactly what it says until they've had a
few months successful Tcl'ing. ;^)
Donal.
| |
|
|
|
|
|