graphic Lines

DGXI 0 Tallied Votes 179 Views Share

i have created lines in graphwin but i did it the long way is there a simpler way using loops ?
cheers

def drawlines():
    win = GraphWin("lines", 200, 200)
 
    line = Line(Point(100, 100), Point(200, 200))
    line1 = Line(Point(100, 100), Point(150, 200))
    line2 = Line(Point(100, 100), Point(100, 200))
    line3 = Line(Point(100, 100), Point(50, 200))
    line4 = Line(Point(100, 100), Point(0, 200))
    line5 = Line(Point(100, 100), Point(200, 0))
    line6 = Line(Point(100, 100), Point(200, 50))
    line7 = Line(Point(100, 100), Point(200, 100))
    line8 = Line(Point(100, 100), Point(200, 150))

    line0 = Line(Point(100, 100), Point(100, -50))
    line10 = Line(Point(100, 100), Point(-50, 100))
    line20 = Line(Point(100, 100), Point(150, -50))
    line30 = Line(Point(100, 100), Point(-50, 150))
    line40 = Line(Point(100, 100), Point(-50, 50))
    line50 = Line(Point(100, 100), Point(50, -50))
    line60 = Line(Point(100, 100), Point(-200, -200))

    line.draw(win)
    line1.draw(win)
    line2.draw(win)
    line3.draw(win)
    line4.draw(win)
    line5.draw(win)
    line6.draw(win)
    line7.draw(win)
    line8.draw(win)
    line0.draw(win)
    line10.draw(win)
    line20.draw(win)
    line30.draw(win)
    line40.draw(win)
    line50.draw(win)
    line60.draw(win)
  
    
    
drawlines()
bvdet 75 Junior Poster

It appears that the first point is constant. Create a list of second point objects, then iterate on the list.

pointList = [Point(200, 200),
             Point(150, 200),
             ...............
             ]
for pt in pointList:
    Line(Point(100, 100), pt).draw(win)
DGXI 0 Newbie Poster

managed to get that to work thanks. is there a way to make the lines change colour by user input? tried a few ways but nothing seemed to work.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Note: this should be a regular post, not a code snippet post!

Code Snippets are for finished code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.