[MWForum]Lineweaver - questions, problems, and answers
Jeff Knope
mwforum@lists.mathcats.com
Mon, 6 Jan 2003 20:02:11 -0800
Hi-
First to Wendy: I'm glad the problems you were having cleared-up by
themselves. I have an old Volvo that often does the same thing. I don't
know what was going on. Possibily you were trying to use RING or ECHO
before closing DRAW FIGURE. Don't assume it was something you were doing or
something in the code. I was having a problem that whenever I did a call to
RING with a value above 15, it would trigger a call to PREP (the "Prep for
Save" procedure). Theoretically, this is impossible - because only a
mouseclick on the color "sky with a (first mousepos) - the "x" value -
above, I don't remember, 267 or something, could possibly trigger a call to
PREP. I changed two "if" statements in PREP into one "ifelse" statement,
and the problelm vanished. Go figure.
Wendy asked me how the value scales work. It's ironic that the key line of
code for this is the one addressed in the earlier "bugfix" missive. For
what it's worth, the same concept allows figuring out which menu tile has
been clicked on (since they're all the same color).
In my code, there are two complications I'd like to leave out of this answer
to your question. One is the fact that the scale crosses the boundry
between positive and negative "x" values. Let me first say that, in my
view, Seymour, et al, belong in the most elite pantheon of the 20th Century.
What is obvious in hindsight, to make LISP into a natural-language
"noun-verb-predicate" business, with real English words, was pure genius.
However, placing the graphics origin [0 0] in the dead-center of the
graphics field is simply a pain in the ... ah ... backside. I understand
that it is very helpful for young minds to grasp number theory (which was,
afterall, his main objective). But in terms of graphics programming, it's
just plain stupid.
The second thing I want to leave out is complications caused by the fact
that my menu tiles are of (at least) two different sizes. This necessitates
analyzing the mouseclicks in stages: first if it's among the larger tile
group, then something different if it's among the narrower tiles, and
finally a third thing because the "Prep for Save" tile is off by itself,
isolated from the other larger tiles.
Actually, there's a third complication caused by the -30 to +30 scale, which
crosses the LOGO xcor = 0 point at an arbitrary location. Let's skip that
one too.
So, let's not look at the specifics of my code. Let's just deal with the
concept.
Let's say we have a horizontal scale placed with its "0" (left-hand) point
at the LOGO xcor = 0 point. Let's say the scale is 200 turtlesteps long, so
it's far right end is at xcor = 200. Now, choose a value-range for the
scale: we want the user to choose values between, oh, say 0 and 25. We can
draw the scale with tick marks at the 0, 5, 10, 15, 20 and 25 value-points.
Each tick-mark is 200 / 5 or 40 turtle-steps apart. We can make a long,
narrow textbox that places these numbers above their respective tick-marks.
Now, the time has come for the user to click on the scale to tell the
program the value he/she wants. The method I use is, at the beginning of
the procedure I assign some value to a variable, say, make "foo 0. Then I
assign an action to a mouseclick on the color of the scale: set "yellow
"mouseclick [make "foo 1]. At the point you want the user to give a telling
mouseclick, write: waituntil [:foo = 1]. This suspends the running of the
program until there is a mouseclick on something with a yellow color. Once
:foo = 1, the program resumes. At this point, you immediately operate on
(first mousepos), which is the xcor value of the point clicked on. In this
case, you'd say: make "value int (first mousepos) / 8. You see, if the user
clicked on a point whose xcor, that is, (first mousepos), is 123, the
variable "value would be assigned: int 123 / 8, which is 15. In this way,
the user has selected a value on the scale you've offered.
Rereading that, I see the only thing I haven't made explicit is why divide
by 8. The answer is the total scale is 200 turtlesteps, the total
value-range is 25. Therefore the meaning of any (first mousepos) is its
value divided by 200 / 25, or 8.
Well, I hope you really wanted to know.
Regards,
-JEFF