Пример #1
0
from pystdlib import stddraw as sd

print("spiral")

DIM = 30

IMAGE_SIZE = 1024

sd.setCanvasSize(IMAGE_SIZE, IMAGE_SIZE)

sd.setXscale(-DIM, DIM)
sd.setYscale(-DIM, DIM)

sd.clear(sd.PINK)

x = [0]
y = [0]

POINTS = 1000

delta_alpha = 6 * math.pi / POINTS

for i in range(1, POINTS + 1):
    angle = i * delta_alpha
    x.append(angle * math.cos(angle))
    y.append(angle * math.sin(angle))

    sd.line(x[i - 1], y[i - 1], x[i], y[i])

sd.show()
Пример #2
0
stddraw.setXscale(-SCALE_SIZE, SCALE_SIZE)
stddraw.setYscale(-SCALE_SIZE, SCALE_SIZE)

angle = 2 * math.pi / n

while True:
    stddraw.clear(stddraw.WHITE)
    stddraw.setPenColor(stddraw.LIGHT_GRAY)

    for i in range(n):
        for j in range(i, n):
            if random.random() > p:
                continue

            x0 = math.cos(angle * i)
            y0 = math.sin(angle * i)
            x1 = math.cos(angle * j)
            y1 = math.sin(angle * j)

            stddraw.line(x0, y0, x1, y1)

    stddraw.setPenColor(stddraw.BLACK)

    for i in range(n):
        x = math.cos(angle * i)
        y = math.sin(angle * i)

        stddraw.point(x, y)

    stddraw.show(DT)
Пример #3
0
    for j in range(n):
        p[i][j] = stdio.readFloat()

hits = stdarray.create1D(n, 0)

# Start at page 0.
page = 0

for i in range(moves):
    r = random.random()
    total = 0.0
    for j in range(n):
        total += p[page][j]
        if r < total:
            page = j
            break

    hits[page] += 1

    if i % 1000 == 0:
        stddraw.clear()
        for k in range(n):
            stddraw.filledRectangle(k - 0.25, 0.0, 0.5, hits[k])
        stddraw.show(10)

for v in hits:
    stdio.writef(f"{v / moves:8.5f}")
stdio.writeln()

stddraw.show()