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

Username:   Password: 
 RegisterRegister   
 drawcircle
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bored_hacker




PostPosted: Sun May 29, 2005 2:04 pm   Post subject: drawcircle

i got bored so i made this proc to draw a circle. its practically worthless except for the way you see it drawn, some people would think its cool. Shocked

code:
proc drawcircle (x, y, radius, col : int)
    var i : real
    for q : 0 .. 72000
        i := q / 200
        drawdot (round (cosd (i) * radius) + x, round (sind (i) * radius) + y, col)
    end for
end drawcircle
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun May 29, 2005 3:10 pm   Post subject: (No subject)

drawfillcircle
Turing:

proc drawfillcircle (x, y, radius, clr : int)
    var row : real := -radius %start at bottom of the circle
    var col : real := 0.0
    var dir := 1    %1 is right, -1 is left
    var dist : real
    loop
        dist := (row ** 2 + col ** 2) ** 0.5
        if dist <= radius then
            drawdot (round (x + col), round (y + row), clr)
        elsif dist >= radius then
            dir *= -1
            row += 1
            loop    %jump back into the circle
                col += dir
                dist := (row ** 2 + col ** 2) ** 0.5
                exit when dist <= radius or row >= radius
            end loop
        end if
        col += dir
        exit when row >= radius
    end loop
end drawfillcircle
drawfillcircle (maxx div 2, maxy div 2, maxy div 2, green)


Would be a lot faster with more math and using lines, mind you. Or even using math and pixels, but once you've figured out how far the pixels must go (given a certain row and radius, using some math) you could just draw a line of pixels. That would be a lot faster, I'd imagine. Someone else can give that a try. Wink
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  [ 2 Posts ]
Jump to:   


Style:  
Search: