Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 a way to draw fat lines in a program(only a class)
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kit-kat-kid




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed May 05, 2004 2:56 pm   Post subject: (No subject)

you know, there's already Draw.ThickLine() available Thinking
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kit-kat-kid




PostPosted: Wed May 05, 2004 5:34 pm   Post subject: (No subject)

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




PostPosted: Wed May 05, 2004 6:22 pm   Post subject: (No subject)

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




PostPosted: Wed May 05, 2004 8:02 pm   Post subject: (No 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.
kit-kat-kid




PostPosted: Wed May 05, 2004 8:06 pm   Post subject: (No subject)

hey dosent matter as long as it works
Dan




PostPosted: Thu May 06, 2004 4:17 pm   Post subject: (No 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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
kit-kat-kid




PostPosted: Thu May 06, 2004 6:56 pm   Post subject: (No 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
the_short1




PostPosted: Thu May 06, 2004 7:41 pm   Post subject: (No 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..
Dan




PostPosted: Thu May 06, 2004 8:25 pm   Post subject: (No 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).
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
kit-kat-kid




PostPosted: Fri May 07, 2004 12:09 pm   Post subject: (No subject)

ok cool
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: