首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JES中镜像镜像

在JES中镜像镜像
EN

Stack Overflow用户
提问于 2014-04-03 05:37:32
回答 3查看 2.1K关注 0票数 0

我在试着镜像一个图像。也就是说,如果一个人面朝左,当程序终止时,我希望这个人现在面朝右。

我理解JES中的镜像是如何工作的,但我不确定如何在这里进行。下面是我正在尝试的;请注意,image是在另一个函数中声明的全局变量。

代码语言:javascript
复制
def flipPic(image):
  width = getWidth(image)
  height = getHeight(image)
  for y in range(0, height):
    for x in range(0, width):
       left = getPixel(image, x, y)
       right = getPixel(image, width-x-1, y)
       color = getColor(left)
       setColor(right, color)
  show(image)
  return image
EN

回答 3

Stack Overflow用户

发布于 2014-04-09 07:04:50

尝尝这个

代码语言:javascript
复制
width = getWidth(pic)
height = getHeight(pic)
for y in range (0,height):
    for x in range (0, width/2):
        left=getPixel(pic, x, y)
        right=getPixel(pic, width-x-1,y)
        color1=getColor(left)
        color2=getColor(right)
        setColor(right, color1)
        setColor(left, color2)
repaint(pic) 
票数 0
EN

Stack Overflow用户

发布于 2015-04-16 16:06:47

我个人发现repaint对于新手(比如我!)来说是令人困惑的。我建议这样做:

代码语言:javascript
复制
def mirrorImage(image):

width = getWidth(image)
height = getHeight(image)
for y in range (0,height):
    for x in range (0, width/2):
        left=getPixel(pic, x, y)
        right=getPixel(pic, width-x-1,y)
        color1=getColor(left)
        color2=getColor(right)
        setColor(right, color1)
        setColor(left, color2)
        show(image)
        return image
mirrorImage(image)
票数 0
EN

Stack Overflow用户

发布于 2015-10-21 17:41:19

这似乎工作得很好..我放了一些注释,这样你就可以用你自己的风格重写了。

请随时提问,但我认为您的问题可能已经得到回答^^

代码语言:javascript
复制
#this function will take the pixel values for a selected picture and 
#past them to a new canvas but fliped over! 
def flipPic(pict):
#here we take the height and width of the original picture
  width=getWidth(pict)
  height=getHeight(pict)
#here we make and empty canvas  
  newPict=makeEmptyPicture(width,height) 
#the Y for loop is setting the range to working for the y axes the started the X for loop 
  for y in range(0, height):
#the X for loop is setting the range to work in for the x axis 
    for x in range(0, width):
#here we are collecting the colour information for the origional pix in range of X and 
      colour=getColor(getPixel(pict,x,y))
#here we are setting the colour information to its new position on the blank canvas
      setColor(getPixel(newPict,width-x-1,y),colour)
      #setColor(getPixel(newPict,width-x-1,height-y-1),colour)#upsidedown
  show(newPict)

#drive function
pict = makePicture(pickAFile())
show(pict)
flipPic(pict)

如果你先把它复制到JES上,可能会更容易阅读:D

顺便说一句,我在我的编程入门课上得到了满分;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22823603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档