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

Username:   Password: 
 RegisterRegister   
 Is there a way to repeatedly draw a pic using 1 or 2 lines?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
KONjbnj




PostPosted: Thu May 26, 2005 11:01 am   Post subject: Is there a way to repeatedly draw a pic using 1 or 2 lines?

I want to have this

code:
    Pic.Draw (line, 200, 450, picMerge)
    Pic.Draw (line, 250, 450, picMerge)
    Pic.Draw (line, 300, 450, picMerge)
    Pic.Draw (line, 350, 450, picMerge)
    Pic.Draw (line, 400, 450, picMerge)
    Pic.Draw (line, 450, 450, picMerge)
    Pic.Draw (line, 500, 450, picMerge)
    Pic.Draw (line, 300, 400, picMerge)
    Pic.Draw (line, 350, 400, picMerge)
    Pic.Draw (line, 400, 400, picMerge)
    Pic.Draw (line, 450, 400, picMerge)
    Pic.Draw (line, 500, 400, picMerge)


But I would need to do that many other times. I realize that it would take a lot of lines to do, and I was wondering if there waas a way to do that but in fewer lines.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu May 26, 2005 12:17 pm   Post subject: (No subject)

Yep, for loops. Check the tutorial section if you dont' know them. There's a link to the tutorial in the sticky at the top of the turing tutorials thread. Here's how:
code:

for decreasing y : 450 .. 400 by 50
    for x : 200 .. 500 by 50
        Pic.Draw (line, x, y, picMerge
    end for
end for

Actually, after looking closer at your code I see that doesn't exactly fit the requirements. This would draw an extra two lines at y = 400. To prevent the ones at (200, 400) & (250, 400) from being drawn, you could use an if statement.
code:

for decreasing y : 450 .. 400 by 50
    for x : 200 .. 500 by 50
        if y = 400 and x >= 300 then
            Pic.Draw (line, x, y, picMerge
        end if
    end for
end for

However you do this, look for patterns in your code. Sometimes there is no pattern, sometimes there's a semi-pattern, as is the case here. Whenever there is a pattern, there is an easier way of doing it then just writing every coordinate.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: