当前位置: 首页>>代码示例>>Python>>正文


Python Picture.set方法代码示例

本文整理汇总了Python中picture.Picture.set方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.set方法的具体用法?Python Picture.set怎么用?Python Picture.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在picture.Picture的用法示例。


在下文中一共展示了Picture.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Picture

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import set [as 别名]
pic = Picture()
for col in range(pic.width()):
    for row in range(pic.height()):
        # Compute pixel color.
        x = 1.0 * col / pic.width()
        y = 1.0 * row / pic.height()
        v = 0.0

        for i in range(n):
            v += charges[i].potentialAt(x, y)    
        v = (MAX_GRAY_SCALE / 2.0)  + (v / 2.0e10)
        if v < 0:
            grayScale = 0
        elif v > MAX_GRAY_SCALE:
            grayScale = MAX_GRAY_SCALE
        else:
            grayScale = int(v)            
        color = Color(grayScale, grayScale, grayScale)
        pic.set(col, pic.height()-1-row, color)

# Draw the Picture.
stddraw.setCanvasSize(pic.width(), pic.height())
stddraw.picture(pic)
stddraw.show()


#-----------------------------------------------------------------------

# python potential.py < charges.txt

开发者ID:davidhuizhou,项目名称:python,代码行数:31,代码来源:potential.py

示例2: int

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import set [as 别名]
# Accept the name of a JPG or PNG image file, an integer w, and
# an integer h as command line arguments. Read an image from the
# file, and display the image scaled to width w and height h.

fileName = sys.argv[1]
w = int(sys.argv[2])
h = int(sys.argv[3])

source = Picture(fileName)
target = Picture(w, h)

for tCol in range(w):
    for tRow in range(h):
        sCol = tCol * source.width() // w
        sRow = tRow * source.height() // h
        target.set(tCol, tRow, source.get(sCol, sRow))

stddraw.setCanvasSize(w, h)
stddraw.picture(target)
stddraw.show()

#-----------------------------------------------------------------------

# python scale.py mandrill.jpg 800 800

# python scale.py mandrill.jpg 600 300

# python scale.py mandrill.jpg 200 400

# python scale.py mandrill.jpg 200 200
开发者ID:davidhuizhou,项目名称:python,代码行数:32,代码来源:scale.py

示例3: Picture

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import set [as 别名]
width = source.width()
height = source.height()

stddraw.setCanvasSize(width, height)

pic = Picture(width, height)

for t in range(n+1):
    for col in range(width):
        for row in range(height):
            c0 = source.get(col, row)
            cn = target.get(col, row)
            alpha = float(t) / float(n)
            c = blend(c0, cn, alpha)
            pic.set(col, row, c)
    stddraw.picture(pic)
    stddraw.show(1000.0)

stddraw.show()


#-----------------------------------------------------------------------
    
# python fade.py mandrill.jpg darwin.jpg 7

# python fade.py mandrill.jpg darwin.jpg 5

# python fade.py mandrill.jpg darwin.png 7

# python fade.py mandrill.png darwin.jpg 7
开发者ID:davidhuizhou,项目名称:python,代码行数:32,代码来源:fade.py

示例4: Picture

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import set [as 别名]
import luminance
from picture import Picture

#-----------------------------------------------------------------------

# Accept the name of a JPG or PNG file as a command-line argument.
# Read an image from the file with that name. Create and show a
# gray scale version of that image.

pic = Picture(sys.argv[1])

for col in range(pic.width()):
    for row in range(pic.height()):
        pixel = pic.get(col, row)
        gray = luminance.toGray(pixel)
        pic.set(col, row, gray)

stddraw.setCanvasSize(pic.width(), pic.height())
stddraw.picture(pic)
stddraw.show()

#-----------------------------------------------------------------------

# python grayscale.py mandrill.jpg

# python grayscale mandrill.png

# python grayscale.py darwin.jpg

# python grayscale.py darwin.png
开发者ID:davidhuizhou,项目名称:python,代码行数:32,代码来源:grayscale.py

示例5: int

# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import set [as 别名]
# iterations before the Mandelbrot sequence for the corresponding
# complex number grows past 2.0, up to 255.

MAX = 255

n = int(sys.argv[1])
xc = float(sys.argv[2])
yc = float(sys.argv[3])
size = float(sys.argv[4])

pic = Picture(n, n)
for col in range(n):
    for row in range(n):
        x0 = xc - (size / 2) + (size * col / n)
        y0 = yc - (size / 2) + (size * row / n)
        z0 = complex(x0, y0)
        gray = MAX - mandel(z0, MAX)
        color = Color(gray, gray, gray)
        pic.set(col, n-1-row, color)

stddraw.setCanvasSize(n, n)
stddraw.picture(pic)
stddraw.show()


#-----------------------------------------------------------------------

# python mandelbrot.py 512 -.5 0 2

# python mandelbrot.py 512 .1015 -.633 .01
开发者ID:davidhuizhou,项目名称:python,代码行数:32,代码来源:mandelbrot.py


注:本文中的picture.Picture.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。