help in assignment

This is the place for queries that don't fit in any of the other categories.

help in assignment

Postby soraya » Mon Feb 11, 2013 11:28 pm

Hi, I am given this assignment that should be run in Jython. The assignment says that the program consists of a Java application with a canvas and a textarea for
turtle code. I need to create a Jython application that takes turtle code from the Java application, parses it with regular expressions and calls setPixel(x,y)
in the Java application to draw a rectangle. the Java program ,setPixel(x, y) is used to control the painting and getCode() to get the code entered in to the turtle
code textarea. These methods are both defi ned in the DYPL Java class.
Code: Select all
import Translater

class Jtrans(Translater):

    def __init__(self):
        pass

    def actionPerformed(self, event):
        print("Button clicked. Got event:")
        self.obj.setPixel(100,10)
        self.obj.setPixel(101,10)
        self.obj.setPixel(102,10)

def move(self, x,y):
        move(50, 90) # is move a built in function
        move(100, 90)
        move(50, 90)
        move(100, 90)

    def put(self, x,y,a):
        put(150, 150, 0)
        for x in range(0,4): #how come it doesn't draw a rectangle as mentioned?
            move(50, 90)
        end
   
       
        eval("self."+self.obj.getCode()+"()")#why do we need this?

    def setDYPL( self, obj ):
        print("Got a DYPL instance: ")
        print(obj)

if __name__ == '__main__':
    import DYPL
    DYPL(Jtrans())



I also attach a zip file containing classes like Translater.class,DYPLCanvas.java etc if you need it. so does anyone know how I should start?
Attachments
assignment.zip
Zip file containing classes to the above assignment
(6.33 KiB) Downloaded 37 times
soraya
 
Posts: 2
Joined: Mon Feb 11, 2013 11:10 pm

Re: help in assignment

Postby stranac » Tue Feb 12, 2013 1:09 am

It seems to me, from the text of the assignment, that you need to:
  • Parse the turtle code
  • Turn the result into calls to python functions/methods which will return lists of pixels
  • Use the DYPL and JythonTranslater.Jtrans classes to draw actual pixels

I would recommend doing this one step at a time.
  1. Parse the file. (details of the format are included in the assignmen text, along with ho example regular expressions)
  2. Make python call the correct function for each turtle function. You can just mock calling them for now(e.g. just print 'This or that function called')
  3. Implement the turtle functions one at a time. Make sure they're returning the correct lists of pixels.
  4. Interface this with the provided classes.

Try doing this starting from step one.
If you run into any problems, post again about the specific problem you're having.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 885
Joined: Thu Feb 07, 2013 3:42 pm

Re: help in assignment

Postby soraya » Tue Feb 12, 2013 1:34 am

Thank you for the reply. the line
Code: Select all
self.obj.setPixel(100,10) 
self.obj.setPixel(101,10) 

can draw a pixel which is in Jtrans , so do you mean that I should type it again below the
Code: Select all
if __name__ == '__main__':
    import DYPL
    DYPL(Jtrans())

? Also how do I parse a file? do you mean i should run it in python instead of jython and run it line by line?

thank you for your time
soraya
 
Posts: 2
Joined: Mon Feb 11, 2013 11:10 pm

Re: help in assignment

Postby stranac » Tue Feb 12, 2013 11:12 am

Yes, you should use the DYPL class instance to draw a pixel.
You should do this for every pixel your code will produce(so a loop might be a good idea).

soraya wrote:Also how do I parse a file? do you mean i should run it in python instead of jython and run it line by line?

Well, jython is python.
But yes, you should read it one line at a time, determine what that line is supposed to do, and then execute a matching piece of python code.
The assignment wants you to do the determine what that line is supposed to do part by using regex.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 885
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: DrakeMagi and 6 guests