jes

Mirroring an Image by its Diagonal in Jython

岁酱吖の 提交于 2019-12-06 14:21:30
So I need to mirror an image. The top right side of the image should be flipped over to the bottom left side. I created a function that flips the top left side of an image to the bottom right, but I just can't seem to figure out how to do it the other way. Here's the code: def mirrorPicture(picture): height = getHeight(canvas) width = height # to make mirroring easier, let us make it a square with odd number # of rows and columns if (height % 2 == 0): height = width = height -1 # let us make the height and width odd maxHeight = height - 1 maxWidth = width - 1 for y in range(0, maxWidth): for x

Fading a picture gradually

馋奶兔 提交于 2019-12-05 06:42:32
The idea of this function is to fade the top half only of the picture (make it gradually darker). Here is what I have but it seems to be making all of the top half solid black. def fadeDownFromBlack(pic1): w=getWidth(pic1) h=getHeight(pic1) for y in range(0,h/2): for x in range(0,w): px=getPixel(pic1,x,y) setBlue(px,y*(2.0/h)) setRed(px,y*(2.0/h)) setGreen(px,y*(2.0/h)) Let's look at just one line here: setBlue(px,y*(2.0/h)) and key part here is y*(2.0/h) y changes, as you go down. Let's try some simple values for y and h. Let's say h is 100 and we will examine when y is both 0 and 50 (h/2).

Drawing diagonal lines on an image

元气小坏坏 提交于 2019-12-02 10:31:28
问题 Hi im trying to draw diagonal lines across an image top right to bottom left here is my code so far. width = getWidth(picture) height = getHeight(picture) for x in range(0, width): for y in range(0, height): pixel = getPixel(picture, x, y) setColor(pixel, black) Thanks 回答1: Most graphic libraries have some way to draw a line directly. In JES there is the addLine function, so you could do addLine(picture, 0, 0, width, height) If you're stuck with setting single pixels, you should have a look

Drawing diagonal lines on an image

走远了吗. 提交于 2019-12-02 07:26:38
Hi im trying to draw diagonal lines across an image top right to bottom left here is my code so far. width = getWidth(picture) height = getHeight(picture) for x in range(0, width): for y in range(0, height): pixel = getPixel(picture, x, y) setColor(pixel, black) Thanks Most graphic libraries have some way to draw a line directly. In JES there is the addLine function, so you could do addLine(picture, 0, 0, width, height) If you're stuck with setting single pixels, you should have a look at Bresenham Line Algorithm , which is one of the most efficient algorithms to draw lines. A note to your

Flip horizontally an image in Python (JES)

那年仲夏 提交于 2019-12-01 20:26:26
I need to make a function that will copy an image, but mirrored. I created the code to mirror the image, but it isn't working and I don't know why because I traced the code and it should be mirroring the image. Here's the code: def invert(picture): width = getWidth(picture) height = getHeight(picture) for y in range(0, height): for x in range(0, width): sourcePixel = getPixel(picture, x, y) targetPixel = getPixel(picture, width - x - 1, height - y - 1) color = getColor(sourcePixel) setColor(sourcePixel, getColor(targetPixel)) setColor(targetPixel, color) show(picture) return picture def main()

Creating a movie in Jython/Python

回眸只為那壹抹淺笑 提交于 2019-12-01 09:39:55
I am trying to make a movie, whilst creating frames through a loop. It is saving, but only the first frame (which it plays as a movie - short movie!) I've tried various things and cannot figure out what I am doing wrong. Thanks def synthesiseFrame(folder): folder =r"D:\FOLDER" m=0.5 for x in range(1,121): pic=makeEmptyPicture(960,540) for x in range (0,960): for y in range (0,540): r=#some code g=#some code b=#some code color =makeColor (r,g,b) px= getPixel (pic, x, y) setColor(px, color) numStr=str(x) m=m+0.0125 if x<10: writePictureTo(pic, folder+"\pic00"+numStr+".png") if x >=10 and x<100:

Mirror Image Diagonally in Python

老子叫甜甜 提交于 2019-12-01 09:10:49
I'm taking a programming class on python, and we're working on mirroring images by defining a mirror point and then copying a pixel from one side to the other using nested for loops. For example, mirroring an image vertically would use the following code: def mirrorVertical(source): mirrorPoint = getWidth(source) / 2 width = getWidth(source) for y in range(0,getHeight(source)): for x in range(0,mirrorPoint): leftPixel = getPixel(source,x,y) rightPixel = getPixel(source,width - x - 1,y) color = getColor(leftPixel) setColor(rightPixel,color) I'm currently working on an assignment question asking

Creating a movie in Jython/Python

六眼飞鱼酱① 提交于 2019-12-01 08:07:13
问题 I am trying to make a movie, whilst creating frames through a loop. It is saving, but only the first frame (which it plays as a movie - short movie!) I've tried various things and cannot figure out what I am doing wrong. Thanks def synthesiseFrame(folder): folder =r"D:\FOLDER" m=0.5 for x in range(1,121): pic=makeEmptyPicture(960,540) for x in range (0,960): for y in range (0,540): r=#some code g=#some code b=#some code color =makeColor (r,g,b) px= getPixel (pic, x, y) setColor(px, color)

Mirror Image Diagonally in Python

元气小坏坏 提交于 2019-12-01 07:01:36
问题 I'm taking a programming class on python, and we're working on mirroring images by defining a mirror point and then copying a pixel from one side to the other using nested for loops. For example, mirroring an image vertically would use the following code: def mirrorVertical(source): mirrorPoint = getWidth(source) / 2 width = getWidth(source) for y in range(0,getHeight(source)): for x in range(0,mirrorPoint): leftPixel = getPixel(source,x,y) rightPixel = getPixel(source,width - x - 1,y) color

Scaling Part of a Picture

China☆狼群 提交于 2019-12-01 01:27:47
I want to scale up a part of a picture, in this example, a nose. I have a function to select the part of the picture I want to enlarge. def copyAndPaste(picture): height = getHeight(picture) width = getWidth(picture) newPicture = makeEmptyPicture(width, height) for x in range(width): for y in range(height): pxl = getPixel(picture,x,y) if (x>48 and x<59) and (y>58 and y<71): newPxl =getPixel(newPicture, #?,#?) else: newPxl = getPixel(newPicture, x,y) color = getColor(pxl) setColor(newPxl,color) return newPicture def d(): f=pickAFile() picture=makePicture(f) newPicture = copyAndPaste(picture)