Hi everyone,
I've been using Squeak to write little tools to help my students drill various maths skills. Since modern students have major issues working with fractions (due, I believe, to too much calculator too soon) I want to produce a morph that displays a simple arithmetic problem. The student attempts to solve the problem, and then clicks on the morph, which then displays the solution. If the student clicks on the morph again it shows a new (randomly selected) problem. I've used the idea with a few other types of problem quite successfully.
My problem is how to display a fraction so it looks like a fraction, and not like (2/5) + (7/8). I want the vinculum to be a horizontal line:
2 7 61 --- + --- = ---- 5 8 40
Can anyone point me at example code on how to get things formatted nicely? It looks as if I have to somehow calculate how many pixels wide and high each character is, and place each character nicely individually, which seems like an insane amount of work to do something that seems like it should be straightforward. Should I have 5 text morphs imbedded in a rectangle morph, using automatic sizing and keeping track of the bounds of each so I can draw lines to put the vinculums in place, or is there a cleaner way that requires less management code? Things seem awfully messy catering for the different things that could come up (like 2/15, 15/2, 2/123 etc).
Pointers to existing code would be ideal, so I can understand things, rather than just dropping a solution on me.
Thanks in advance,
John Foster.
Hi John,
JF> My problem is how to display a fraction so it looks like a fraction, and JF> not like (2/5) + (7/8). I want the vinculum to be a horizontal line:
JF> 2 7 61 JF> --- + --- = ---- JF> 5 8 40
JF> Can anyone point me at example code on how to get things formatted nicely?
each Fraction understands numerator and denominator so you have the numbers. Just try in a Workspace 1234567 printString asMorph openInHand.
Now you have your Morphs, each of which understands bounds to give you the top left and bottom right corner.
Then with position: topLeftCorner you can move them around and draw your vinculum (thanks for a new word :-)) as a LineMorph with the class side method from: startPoint to: endPoint color: lineColor width: lineWidth between your numbers
Then add them with addMorph: to whatever you use as a display.
JF> Pointers to existing code would be ideal, so I can understand things, JF> rather than just dropping a solution on me.
Well hope that helps with understanding.
Cheers,
Herbert
On Monday 10 May 2010 12:01:58 am John Foster wrote:
My problem is how to display a fraction so it looks like a fraction, and not like (2/5) + (7/8). I want the vinculum to be a horizontal line:
2 7 61 --- + --- = ---- 5 8 40
You could use a Column morph with its border width set to zero and fill style set to transparent color. You may have to override cell positioning to bottom right to get numbers to align right (halo for Column ->menu->layout->table layout->cell positioning -> bottom right). Replace Red and Green morphs with Text containing numerator and denominator. Set Yellow morph's color to black, length to 3 and width to the max (numerator width, denominator width).
Create Column morphs for first fraction, +, second fraction, =, total fraction and put them into a Row Morph.
HTH .. Subbu
beginners@lists.squeakfoundation.org