Turn on thread page Beta
    • Thread Starter
    Offline

    0
    ReputationRep:
    Hello,

    I have been set a task using pyscripter to create a "patchwork" of designs, and have just created the code for my first segment (a criss cross of red lines) however it is far too long and I was wondering if anyone could help me shorten it? I'm sure I'm doing something wrong!

    Here is a bit the code for the segment I have created to show what I mean;

    win=GraphWin(width=100, height=100)
    line1 = Line(Point(0,100), Point(100,0))
    line1.setOutline("red")
    line1.draw(win)
    line2 = Line(Point(0,80), Point(80,0))
    line2.setOutline("red")
    line2.draw(win)
    line3 = Line(Point(0,60), Point(60,0))
    line3.setOutline("red")
    line3.draw(win)
    line4 = Line(Point(0,40), Point(40,0))
    line4.setOutline("red")
    line4.draw(win)

    And it continues on for quite a few lines.

    If anyone could help it'd be really appreciated!
    Offline

    0
    ReputationRep:
    for your example,
    Code:
    win=GraphWin(width=100, height=100)
    for p in xrange(2, 6):
          xy=(7 - p)*20
          linen = Line(Point(0, xy), Point(xy, 0))
          linen.setOutline("red")
          linen.draw(win)
    • Thread Starter
    Offline

    0
    ReputationRep:
    It's sort of working, but it's opening each line in a new graphic window?
    Offline

    0
    ReputationRep:
    Can you paste all your code?
    Offline

    14
    ReputationRep:
    I would just use 2 line variables like 'line1' and 'line2' and have variables for the x and y for the Points of each co-ordinate of the line. Then use a while loop and increment one of the x and y's and experiment with it.

    I am doing this assignment also, with 2 incredibly difficult symbols to work with. Deadline is next week so it doesn't look good for me.
    Offline

    0
    ReputationRep:
    If you really want to show off you could implement fractals or if you aren't up for that challenge, maybe a 2D random walk.

    Random walk: http://mathworld.wolfram.com/RandomW...mensional.html
    Fractals: http://www.wolframalpha.com/examples/Fractals.html | http://mathworld.wolfram.com/Fractal.html
    • Thread Starter
    Offline

    0
    ReputationRep:
    def drawPatchWindow():
    win=GraphWin(width=100, height=100)
    line1 = Line(Point(0,100), Point(100,0))
    line1.draw(win)
    line2 = Line(Point(0,80), Point(80,0))
    line2.draw(win)
    line3 = Line(Point(0,60), Point(60,0))
    line3.draw(win)
    line4 = Line(Point(0,40), Point(40,0))
    line4.draw(win)
    line5 = Line(Point(20,0), Point(0,20))
    line5.draw(win)
    line6 = Line(Point(20,100), Point(100,20))
    line6.draw(win)
    line7 = Line(Point(40,100), Point(100,40))
    line7.draw(win)
    line8 = Line(Point(60,100), Point(100,60))
    line8.draw(win)
    line9 = Line(Point(80,100), Point(100,80))
    line9.draw(win)
    line10 = Line(Point(100,100), Point(100,100))
    line10.draw(win)


    line1 = Line(Point(0,0), Point(100,100))
    line1.draw(win)
    line2 = Line(Point(0,20), Point(80,100))
    line2.draw(win)
    line3 = Line(Point(0,40), Point(60,100))
    line3.draw(win)
    line4 = Line(Point(0,60), Point(40,100))
    line4.draw(win)
    line4 = Line(Point(0,80), Point(20,100))
    line4.draw(win)
    line1 = Line(Point(20,0), Point(100,80))
    line1.draw(win)
    line2 = Line(Point(40,0), Point(100,60))
    line2.draw(win)
    line3 = Line(Point(60,0), Point(100,40))
    line3.draw(win)
    line4 = Line(Point(80,0), Point(100,20))
    line4.draw(win)

    That's my full code. Will have to mess around with loops, I'm hopeless with them though ahah.

    Are you in Portsmouth, nmr1991?

    And thank you Lelcats! I'll have a look!
    Offline

    0
    ReputationRep:
    Im in Portsmouth! deadline Friday, got no hope.
    Done the same as you, patch works but far to much coding, don't know how i would loop it useless

    from graphics import *

    def drawpatch1():
    win= GraphWin("Patch", 100,100)
    tenth= Rectangle(Point(0,100),Point(100 ,0))
    tenth.setFill("White")
    tenth.setOutline("White")
    tenth.draw(win)
    ninth= Rectangle(Point(0,100),Point(90, 10))
    ninth.setFill("red")
    ninth.setOutline("red")
    ninth.draw(win)
    eigth= Rectangle(Point(0,100),Point(80, 20))
    eigth.setFill("White")
    eigth.setOutline("White")
    eigth.draw(win)
    seventh= Rectangle(Point(0,100),Point(70, 30))
    seventh.setFill("red")
    seventh.setOutline("red")
    seventh.draw(win)
    sixth= Rectangle(Point(0,100),Point(60, 40))
    sixth.setFill("White")
    sixth.setOutline("White")
    sixth.draw(win)
    fith= Rectangle(Point(0,100),Point(50, 50))
    fith.setFill("red")
    fith.setOutline("red")
    fith.draw(win)
    fourth= Rectangle(Point(0,100),Point(40, 60))
    fourth.setFill("White")
    fourth.setOutline("White")
    fourth.draw(win)
    third= Rectangle(Point(0,100),Point(30, 70))
    third.setFill("red")
    third.setOutline("red")
    third.draw(win)
    second= Rectangle(Point(0,100),Point(20, 80))
    second.setFill("White")
    second.setOutline("White")
    second.draw(win)
    first= Rectangle(Point(0,100),Point(10, 90))
    first.setFill("Red")
    first.setOutline("red")
    first.draw(win)
    • Thread Starter
    Offline

    0
    ReputationRep:
    I'm so happy I'm not the only one hahaha. I've been sat in the library for hours trying to work something out but it's just too confusing for me, I'm so bad with the coding.

    Portsmouth for us, ey!
    Offline

    0
    ReputationRep:
    haha, you know. im hoping someone can help!! got a few energy drinks to keep me up tonight. what's your first and last number in your student id?
    Offline

    14
    ReputationRep:
    I've only just figured out how to do the 7th patchwork on the last number on my student number, and while that's out of the way I gotta do the semi-circle pattern for the penultimate number 4 of the patches.

    To make it easier on myself I am going by these steps:

    1. Do just the one patch (it was the hardest at the time so I wanted to get it out of the way)
    2. Do the next patch but in a separate graphics window in the same co-ordinates as the first
    3. Put them both alongside each other.
    4. Create user input to change the colour of the patchwork. (already figured that one out)
    5. Duplicate the patchwork in a chessboard layout. (that will be tricky)
    6. Create user input to swap patches around. And that will be it!

    I probably won't be able to solve the 4th and 6th steps but the mark scheme looks at functionality of the code, so I hope I at least get something. Better than submitting nothing though right?

    Yeah, I am at university of portsmouth.
    • Thread Starter
    Offline

    0
    ReputationRep:
    Mines 88, not too bad but I'm sticking to one patch .

    And yeah I've managed to create one, get the user input, but I'm just gonna leave it at that and try to figure out how to actually get my patch to go INTO the graphic window, which is what's causing me problems ahahah.

    Hate life. And coding.
    Offline

    0
    ReputationRep:
    i have given up hope
    Offline

    14
    ReputationRep:
    My coursework specification said that in order to achieve the pass mark, I could actually just have it output my two patch symbols and in turn demonstrating the use of functions, while loops etc. I just submitted it so I hope for the best.
    • Thread Starter
    Offline

    0
    ReputationRep:
    Yup. I'm finished. Can't do it. Never agtain.
    Offline

    14
    ReputationRep:
    Theres going to be one for java next term so theres no escaping another similar assignment, especially when the python was worth 20% of total mark and Java coursework will hold 30% of total mark for the unit. The other 50% being the in-class tests which thus far I have pretty much failed all of them.

    I predict I will get 8% out of 20% from the Python coursework.
    My target for the Java coursework will be at least 15-20% in turn giving me a chance to get around 30% for coursework. I will try harder for the java tests so if python tests this term made up 25% then I would have about 2% of that percentage. I would have to get roughly 8% more marks in order to pass the unit.
 
 
 
Reply
Submit reply
Turn on thread page Beta
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: November 29, 2013
Poll
Black Friday: Yay or Nay?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.