This is the last lab I have to deal with before the end of the semester and I'm stuck beyond reason it really is interesting though but...so many exams and I just can't figure it out

1.The program begins by displaying the following picture in a window labeled "Original Picture".

##the picture to work with is this picture http://tinman.cs.gsu.edu/~raj/2010/sp10/lab6.html##

2.#The jpg image is 720x480 in size.

3. Then, the program cuts the image into 6 pieces, each 240x240 in size, and scrambles the six pieces randomly and displays the scrambled image in a separate window labeled "Scrambled Image".

4. Then, the program continually prompts the user for two cell numbers (each cell number ranges from 1 to 6; where cells 1, 2 , and 3 correspond to the 3 images in the first row and cells 4, 5, and 6 correspond to the 3 images in the second row).

Cell number (1-6) to exchange: 1
Cell number (1-6) to exchange: 2

5.If the first cell number entered by the user is 0, the program stops. Otherwise, the program exchanges the the two images at the two cells and displays the altered image in a window labeled "Exchanged Picture".

from myro import *

#def moveCell(pic1,cell1,pic2,cell2):
# pic1 and pic2 are the two picture objects and
# cell1 and cell2 are numbers in the range 1..6
# the function moves the image located in cell1
# of pic1 to location cell2 of pic2

#def exchangeCell(pic1,cell1,pic2,cell2):
# pic1 and pic2 are the two picture objects and
# cell1 and cell2 are numbers in the range 1..6
# the function exchanges the images located in cell1
# of pic1 and cell2 of pic2

``````from myro import *

def moveCell(pic1,cell1,pic2,cell2):
pic1 = "atlantaBraves.jpg"
pic2 = "atlantaBraves.jpg"
cell1 = range(1,7,1)
cell2 = range(1,7,1)
for i in cell1:
this
that
the other
for i in cell2:
this
that
the other

def exchangeCell(pic1,cell1,pic2,cell2):
pic1 = "atlantaBraves.jpg"
pic2 = "atlantaBraves.jpg"
pixel = getPixel(newPic, x, y)
newpic = makePicture(pic1, pic2, makeColor(R,G,B))
cell1 = range(1,7,1)
cell2 = range(1,7,1)
for x in range(pic1):
for y in range(pic2):
setColor(pixel, white)
repaint(newPic)

def main():
p = makePicture("atlantaBraves.jpg")
show(p, "Original Picture")
moveCell(pic1,cell1,pic2,cell2)
exchangeCell(pic1,cell1,pic2,cell2)
return p``````

I have not time to think algorithms but what you wrote I would rewrite something like this.

``````from myro import *

defpic = "atlantaBraves.jpg"

def moveCell(pic1 = defpic, cell1,pic2  = defpic, cell2):
cell1 = range(1,7,1)
cell2 = range(1,7,1)
for i in cell1:
this
that
the other
for …``````

## All 7 Replies

I have not time to think algorithms but what you wrote I would rewrite something like this.

``````from myro import *

defpic = "atlantaBraves.jpg"

def moveCell(pic1 = defpic, cell1,pic2  = defpic, cell2):
cell1 = range(1,7,1)
cell2 = range(1,7,1)
for i in cell1:
this
that
the other
for i in cell2:
this
that
the other
return movedpic

def exchangeCell(pic1 = defpic, cell1,pic2  = defpic, cell2):
pixel = getPixel(newPic, x, y)
newpic = makePicture(pic1, pic2, makeColor(R,G,B))
cell1 = range(1,7,1)
cell2 = range(1,7,1)
for x in range(pic1):
for y in range(pic2):
setColor(pixel, white)
repaint(newPic)
return newpic

def picture():  ## this function is not called
p = makePicture(defpic)
show(p, "Original Picture")
p = moveCell(pic1,cell1,pic2,cell2)
p = exchangeCell(pic1,cell1,pic2,cell2)
return p

### write here main program``````

Thanks for cleaning it up but that's basically what I have so far....i just want to know where to go from there? preferably the "this that and the other"'s that I have up there...I have no clue even the skeleton that I'm supposed to use with them

##for intialization
define right size label for image pieces
produce those pieces one by one and put them list pieces[0..5]
make list of order of pieces initially range(6)

## when must show the current picture do
for i in pieceorder:
nextrowl,nextcol=divmod(number of piece,3) ##3=number of pieces per line
put image[pieceorder] to label in next place

## when user has given changing numbers
accept choice when two different values in range (1..6)
decrease by one to become in range (0..5)
take numbers for those pieces from order list and exchange then

Something like this.

from myro import *

What is connection to robots for this program?
http://homepages.ius.edu/rwisman/C490/html/PythonandRobots.htm

Maybe this is more usefull for you
http://www.pythonware.com/library/pil/handbook/introduction.htm

Specifically this part
crop

im.crop(box) => image

Returns a rectangular region from the current image. The box is a 4-tuple defining the left, upper, right, and lower pixel coordinate.

This is a lazy operation. Changes to the source image may or may not be reflected in the cropped image. To get a separate copy, call the load method on the cropped copy.

``````#picture size 720x480, 6 * 240x240 subpictures
for i in range(6):
print i
col,row=divmod(i,3)
leftup=(col*240,row*240)
rightdown=(leftup[0]+240,leftup[1]+240)
print "left upper right lower (%i,%i,%i,%i)" % (leftup+rightdown)
print``````