本文整理汇总了Python中picture.Picture.width方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.width方法的具体用法?Python Picture.width怎么用?Python Picture.width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类picture.Picture
的用法示例。
在下文中一共展示了Picture.width方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import width [as 别名]
# corresponding points. Draw the resulting image to standard draw.
MAX_GRAY_SCALE = 255
# Read charges from standard input into an array.
n = stdio.readInt()
charges = stdarray.create1D(n)
for i in range(n):
x0 = stdio.readFloat()
y0 = stdio.readFloat()
q0 = stdio.readFloat()
charges[i] = Charge(x0, y0, q0)
# Create a Picture depicting potential values.
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)
示例2: Picture
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import width [as 别名]
#-----------------------------------------------------------------------
import sys
import stddraw
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
示例3: int
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import width [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
示例4: int
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import width [as 别名]
# Accept strings sourceFile and targetFile and integer frameCount
# as command-line arguments. Read images from sourceFile and targetFile.
# Then, over the course of frameCount frames, gradually replace the
# image from sourceFile with the image with the image from targetFile.
# Display to standard draw each intermediate image. The images in the
# files can be in either JPG or PNG formats.
sourceFile = sys.argv[1]
targetFile = sys.argv[2]
n = int(sys.argv[3]) # number of intermediate frames
source = Picture(sourceFile)
target = Picture(targetFile)
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)