Esempio n. 1
0
def main():
    n = int(sys.argv[1])
    p = float(sys.argv[2])
    trials = int(sys.argv[3])
    histogram = Histogram(n + 1)
    for t in range(trials):
        heads = stdrandom.binomial(n, p)
        histogram.addDataPoint(heads)
    stddraw.setCanvasSize(500, 200)
    histogram.draw()
    stddraw.show()
Esempio n. 2
0
def fade(file1, file2):
    print('can support extension:', pygame.image.get_extended())
    source = Picture(file1)
    target = Picture(file2)

    n = 5

    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 = 1.0 * t / n
                pic.set(col, row, blend(c0, cn, alpha))
        stddraw.picture(pic)
        stddraw.show(2)
    stddraw.show()
Esempio n. 3
0
    result = stdarray.create1D(len(index), 0)
    for i in range(n):
        sum = dice_1[stdrandom.uniformInt(0, 5)] + dice_2[stdrandom.uniformInt(
            0, 5)]
        result[sum] += 1

    return result


def run(n):

    dice_1 = [1, 3, 4, 5, 6, 8]
    dice_2 = [1, 2, 2, 3, 3, 4]
    dice_s = [1, 2, 3, 4, 5, 6]

    result1 = dice(dice_1, dice_2, n)
    result2 = dice(dice_s, dice_s, n)

    print(result1, result2)

    stddraw.setYscale(0, 1.1 * max(max(result1), max(result2)))
    stdstats.plotLines(result1)
    stdstats.plotBars(result2)
    stddraw.show(50)


stddraw.setCanvasSize(1000, 400)
for n in range(50, 200):
    stddraw.clear()
    run(n)
Esempio n. 4
0
import sys
from stdpackage import stddraw,stdio
from stdpackage.color import Color
from stdpackage.picture import Picture


def luminance(c):
    red = c.getRed()
    green = c.getGreen()
    blue = c.getBlue()

    return .299*red + .587*green + .144*blue

def toGray(c):
    y = int(round(luminance(c)))
    return Color(y,y,y)

def areCompatible(c1,c2):
    return abs(luminance(c1) - luminance(c2))>=128.0


pic = Picture(sys.argv[1])
for col in range(pic.width()):
    for row in range(pic.height()):
        pixcel = pic.get(col,row)
        gray = toGray(pixcel)
        pic.set(col,row,gray)

stddraw.setCanvasSize(pic.width(),pic.height())
stddraw.picture(pic)
stddraw.show()
Esempio n. 5
0
#从命令行获取整数m, 从标准输入获取最近m个浮点数,并用动画展示出来

from stdpackage import stdarray, stddraw, stdio, stdstats
import sys

m = int(sys.argv[1])
list = []

stddraw.setCanvasSize(500, 500)
stddraw.setYscale(-1, 1)
for i in range(m):

    stddraw.clear()
    list.append([stdio.readFloat(), str(i)])
    print(list)
    stdstats.plotBars(list, text=True)
    stddraw.show(200)

stddraw.show()