Computer Science Canada

a way to draw fat lines in a program(only a class)

Author:  kit-kat-kid [ Wed May 05, 2004 7:47 am ]
Post subject:  a way to draw fat lines in a program(only a class)

code:
%File "turtlefat.tu"
%A class for creating a turtle that can draw
%with different widths of lines
unit
class TurtleFatCl

    inherit TurtleCl in "turtlecl.tu"
    export SetWidth

    proc ball (xc, yc, radius, clr : int)
        Draw.FillOval (xc, yc, radius,radius,  clr)
    end ball
    var width : int := 1
    proc SetWidth (newWidth : int)
        width := newWidth
    end SetWidth
    proc drawFatLine (x1, y1, x2, y2, clr, width : int)
        const len : real := sqrt ( (x2 - x1) ** 2 + (y2 - y1) ** 2)
        const sinTheta : real := (y2 - y1) / len
        const cosTheta : real := (x2 - x1) / len
        const radius := width div 2 + 1
        const dx : real := radius * cosTheta / 2
        const dy : real := radius * sinTheta / 2

        var xpos : real := x1
        var ypos : real := y1

        loop
            ball (round (xpos), round (ypos), radius, clr)
            xpos += dx
            ypos += dy
            exit when sqrt ( (x2 - xpos) ** 2 + (y2 - ypos) ** 2) < (radius
                / 2)
        end loop
    end drawFatLine

    body procedure Move (distance : int)
        const newx := round (x + cosd (angle) * distance)
        const newy := round (y + sind (angle) * distance)
        if showing then
            if width = 1 then
                Draw.Line (x, y, newx, newy, clr)
            else
                drawFatLine (x, y, newx, newy, clr, width)
            end if
        end if
        x := newx
        y := newy
    end Move
end TurtleFatCl

Author:  Tony [ Wed May 05, 2004 2:56 pm ]
Post subject: 

you know, there's already Draw.ThickLine() available Thinking

Author:  kit-kat-kid [ Wed May 05, 2004 5:34 pm ]
Post subject: 

i know that already but this way you only have to import it

Author:  Paul [ Wed May 05, 2004 6:22 pm ]
Post subject: 

Huh? u don't have to import anything in Draw.ThickLine.

Author:  Delos [ Wed May 05, 2004 8:02 pm ]
Post subject: 

What they're saying is that you won't have to type
"Draw.ThickLine()"
just
"..."
where '...' represents the name of their class...in other words, just saves you a few characters of code.

That and it shows off that they know how to make something like that.

Pretty pointless otherwise.

Author:  kit-kat-kid [ Wed May 05, 2004 8:06 pm ]
Post subject: 

hey dosent matter as long as it works

Author:  Dan [ Thu May 06, 2004 4:17 pm ]
Post subject: 

kit-kat-kid wrote:
hey dosent matter as long as it works


Aucaly it dose, using your method whould eat up more memory then using the turing way b/c it has to read and load that class in to the ram and then exuite it rather then just the turing ones that it will be loading in to the memory any how.

Also alougth it dose shorten the line by 4-5 letters, you have to add the import line at the top of your file and include your file with it for it will not work.

Author:  kit-kat-kid [ Thu May 06, 2004 6:56 pm ]
Post subject: 

it also depends on how many lines you wanna make. with your way you have to do alot more work. with mine you just have to import the class

Author:  the_short1 [ Thu May 06, 2004 7:41 pm ]
Post subject: 

i dont get what u mean..
with ur way u only have to import the class..??


what...
u import the clas... then
u still have to do turtlethickline or w/e u draw it...
so.. its the same amout really..


cool... and u can make it yourself..Wink...but not really useful..

hers 5 bits for the time it took u..

Author:  Dan [ Thu May 06, 2004 8:25 pm ]
Post subject: 

kit-kat-kid wrote:
it also depends on how many lines you wanna make. with your way you have to do alot more work. with mine you just have to import the class


short1 is right, it is no more lines. Aucaly if u look at it at the compiler level your way is more lines b/c it has to read the class file.

Any how it is good that u figgered out how to do it on your own, it is all ways nice to know how things work (or could work).

Author:  kit-kat-kid [ Fri May 07, 2004 12:09 pm ]
Post subject: 

ok cool


: