# Using loops and control statements to draw lines

• October 29th, 2010, 07:27 AM
Using loops and control statements to draw lines
hey all...i have a homework and really i don't know how to solve this questions ...this is a period of exams and i don't have enough time to do alot of homeworks..please help me..

Q1) Using loops and control statements to draw lines can lead to many interesting designs.
a) Create the design in the left screen capture of Fig. 4.21. This design draws lines from
the top-left corner, fanning out the lines until they cover the upper-left half of the panel.
One approach is to divide the width and height into an equal number of steps (we found
15 steps worked well). The first endpoint of a line will always be in the top-left corner
(0, 0). The second endpoint can be found by starting at the bottom-left corner and
moving up one vertical step and right one horizontal step. Draw a line between the two
endpoints. Continue moving up and to the right one step to find each successive end-
point. The figure should scale accordingly as you resize the window.
b) Modify your answer in part (a) to have lines fan out from all four corners, as shown in
the right screen capture of Fig. 4.21. Lines from opposite corners should intersect along
the middle.

4.2 Figure 4.22 displays two additional designs created using while loops and drawLine.
a) Create the design in the left screen capture of Fig. 4.22. Begin by dividing each edge
into an equal number of increments (we chose 15 again). The first line starts in the top-
left corner and ends one step right on the bottom edge. For each successive line, move
down one increment on the left edge and right one increment on the bottom edge. Con-
tinue drawing lines until you reach the bottom-right corner. The figure should scale as
you resize the window so that the endpoints always touch the edges.
right screen capture of Fig. 4.22.
• January 19th, 2012, 05:02 AM
hbaysal
Re: Using loops and control statements to draw lines
...edited by moderator
• January 19th, 2012, 07:05 AM
Norm
Re: Using loops and control statements to draw lines
@hbaysal
What is the purpose of the code you posted?
You have not explained why you have coded it the way that you have.

Spoonfeeding answers to OPs is discouraged.

Whoops, missed the age of this thread!!!
• January 19th, 2012, 08:51 AM
copeg
Re: Using loops and control statements to draw lines
@hbaysal,