In the ACCC Labs that have JES, it can be found by:
def cropImage(): #Allow the user to pick up an image file file = pickAFile() pic = makePicture(file) # decide the size of new image newWidth = 100 newHeight = 150 new_pic = makeEmptyPicture(newWidth, newHeight) # now decide starting with which part of image # we should crop the image start_x = 50 start_y = 100 # so we will crop the image starting from pixel # at row 100 column 50 and size of the image would be # 100 columns and 150 rows. for x in range(1, newWidth+1): for y in range(1, newHeight+1): # get pixel from original image orig_pixel = getPixel(pic, x+start_x, y+start_y); new_pixel = getPixel(new_pic, x, y); # get the color from original pixel c = getColor(orig_pixel) setColor(new_pixel, c) # Now return the new image return(new_pic) |
In the above code the first loop uses the variable x as its index variable. This loop is often called the "outer loop". The second loop uses the variable y as its index variable. This loop is ofter called the "inner loop". The inner loop will be completely executed during each iteration of the outer loop. So in the above code the value of x will be 1 while the value of y changes from 1 to 150. Then while the value of x is 2, the value of y again changes from 1 to 150. This continues until the value of x finally becomes 100.
For this assignment, you are to write a JES function that will take two parameters and print out the family of multiplication sentences based on those parameters.
The multiplication sentences are to be of the form:
multiplier * multiplicant = productWhere the multiplier is to range from 0 to the first parameter
and the multiplicant is to range from 0 to the second parameter.
For example, if the parameters given to the function are 2 and 3, the function should write out the following:
0 X 0 = 0 0 X 1 = 0 0 X 2 = 0 0 X 3 = 0 1 X 0 = 0 1 X 1 = 1 1 X 2 = 2 1 X 3 = 3 2 X 0 = 0 2 X 1 = 2 2 X 2 = 4 2 X 3 = 6
Note, don't worry if you fill up the JES command window with all of these statements. That is to be expected for just about any parameter value. However, the space between the sentence families is something that you are to create.
The primary approach to be used for this assignment is to use 2 for loops where one loop is nested inside the other. The above example of output assumes the outer loop interates on the multiplier (the first operand in the sentences) while the inner loop iterates on the muliplicant (the second operand in the sentences).
Create a file using JES that will: