Computer Science Canada

Is there any reason why my teacher makes us use a for loop to draw static objects?

Author:  MrMac [ Wed Mar 11, 2015 10:24 pm ]
Post subject:  Is there any reason why my teacher makes us use a for loop to draw static objects?

Let's say I want to draw a filled object. For example, a box.


Our teacher makes us, instead of using
Turing:

drawfillbox(0,0,100,100,black)

We actually do:
Turing:

for x : 0..100
drawline(x,0,x,100,black)
end for


She doesn't care if we use a for loop if the object is moving, however. Is there any real reason why she makes us do the for loop for a static filled object? I can't figure it out for the life of me.

Author:  DemonWasp [ Wed Mar 11, 2015 10:53 pm ]
Post subject:  RE:Is there any reason why my teacher makes us use a for loop to draw static objects?

The only reason I can think of is that she wants you to demonstrate that you know how to use the 'for' loop correctly.

There's no technical advantage over drawfillbox or Draw.FillBox. In fact, it's probably a lot slower -- though that won't matter to school assignments.

Author:  Dan [ Wed Mar 11, 2015 11:01 pm ]
Post subject:  RE:Is there any reason why my teacher makes us use a for loop to draw static objects?

The only reason I could think of is that it is part of the assignment to teach you how to use for loops. Otherwise it seems rather unnecessary and is likely even less efficient.

Edit: Did not see DemonWasp's post when I posted, looks like he beat me to it. If any one wanted to figure out if it really is slower or why, I know drawfillbox eventually calls the Rectangle function in the Gdi32.lib Library (https://msdn.microsoft.com/en-us/library/windows/desktop/dd162898%28v=vs.85%29.aspx), my guess would be that windows optimizes the drawing of a polygon like a rectangle over a bunch of line segments (but I am to lazy to research it).


: