Example #1
0
def draw_line(dragonline, turn):
    stddraw.setXscale(-5, 5)
    stddraw.setYscale(-5, 5)
    stddraw.setFontSize(20)

    theta = 0
    x_list = [0, 1]
    y_list = [0, 0]
    stddraw.line(x_list[0], y_list[0], x_list[1], y_list[1])
    x = 1
    y = 0
    List = dragonline.turn_flow(turn)
    Turn = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for index in range(2 * (turn - 1) + 1):
        det_theta = 1 if List[index] == 'L' else -1
        theta = (theta + det_theta) % 4

        det_x = Turn[theta][0]
        det_y = Turn[theta][1]
        x = x + det_x
        y = y + det_y

        x_list.append(round(x))
        y_list.append(round(y))

        stddraw.setPenColor(stddraw.BLACK)
        stddraw.line(x_list[index], y_list[index], x_list[index + 1],
                     y_list[index + 1])
        stddraw.setPenColor(stddraw.RED)
        # stddraw.text(x_list[index],y_list[index],'({0},{1}) to ({2},{3})'.format(x_list[index],y_list[index],x_list[index+1],y_list[index+1]))
        # stddraw.text(x_list[index],y_list[index],str(index))
        stddraw.show(50)
Example #2
0
    def line(self):
        stddraw.setYscale(-1.5, 1.5)
        stddraw.setXscale(-1.5, 1.5)
        # try:
        done_point = []
        for (x1, y1) in zip(self.x, self.y):
            if (x1, y1) not in done_point:

                done_point.append((x1, y1))

                for (x2, y2) in zip(self.x, self.y):
                    if (x1, y1) != (x2, y2) and self.possibility():
                        color_list = [
                            stddraw.LIGHT_GRAY, stddraw.RED, stddraw.BLUE
                        ]
                        color_choice = random.sample(color_list, 1)
                        stddraw.setPenColor(stddraw.BOOK_LIGHT_BLUE)
                        stddraw.setPenRadius(r=0.01)
                        stddraw.line(x1, y1, x2, y2)
                        stddraw.show(20)
                    else:
                        pass
            else:
                pass
        for (x, y) in zip(self.x, self.y):
            stddraw.setPenRadius(r=0.02)
            stddraw.setPenColor(stddraw.BLACK)
            stddraw.point(x, y)
def draw_spirograph(R,r,a):
    stddraw.setXscale(-40,40)
    stddraw.setYscale(-40,40)
    l = 1500
    x = stdarray.create1D(l,0)
    y = stdarray.create1D(l,0)
    for t in range(l):
        x[t] = (R+r)*math.cos(t) - (r+a) * math.cos((R+r)*t/r)
        y[t] = (R+r)*math.sin(t) - (r+a) * math.sin((R+r)*t/r)

    for t in range(l+1):
        if t >= l-1:
            pass
        else:
            if t ==0:
                stddraw.setPenColor(stddraw.RED)
            if t==l/3:
                stddraw.setPenColor(stddraw.DARK_BLUE)
            if t == 2*l/3:
                stddraw.setPenColor(stddraw.BOOK_BLUE)


            stddraw.line(x[t],y[t],x[t+1],y[t+1])
            stddraw.show(5)
    stddraw.show()
def draw_move(dict, a, c, location):
    print('enter move')
    stddraw.line(0, -1, 10, -1)
    stddraw.setFontSize(50)
    stddraw.line(location['a'][0], location['a'][1], location['a'][2],
                 location['a'][3])
    stddraw.line(location['b'][0], location['b'][1], location['b'][2],
                 location['b'][3])
    stddraw.line(location['c'][0], location['c'][1], location['c'][2],
                 location['c'][3])

    for d in dict.keys():
        stddraw.text(location[c][0], 9, a + '-->' + c)
        n = len(dict[d])
        if n == 0:
            pass
        else:
            for i in range(1, n + 2):
                print(i)
                stddraw.line(location[d][0] - i / n, 8 * (n + 1 - i) / (n + 1),
                             location[d][0] + i / n, 8 * (n - i + 1) / (n + 1))
                stddraw.text(location[d][0] - i / n - 0.5, 8 * (n - i) / n,
                             str(i))
            pass
    stddraw.show(300)
def draw_possibility():
    print('enter draw_possibility')
    stddraw.setYscale(-0.5,100)
    stddraw.setXscale(-50,400)
    for i in range(len(possibility)-1):
        stddraw.line(i,possibility[i],i+1,possibility[i+1])

    stddraw.show()
Example #6
0
def draw(list):
    for i in range(len(list) - 1):
        x0 = list[i][0]
        y0 = list[i][1]
        x1 = list[i + 1][0]
        y1 = list[i + 1][1]
        stddraw.line(x0, y0, x1, y1)
        stddraw.show(20)
def draw_setup(n):
    stddraw.setYscale(-1, 11)
    stddraw.setXscale(-1, 11)
    stddraw.line(0, -1, 10, -1)
    location = {'a': (3, 0, 3, 8), 'b': (6, 0, 6, 8), 'c': (9, 0, 9, 8)}

    stddraw.line(3, 0, 3, 8)
    stddraw.line(6, 0, 6, 8)
    stddraw.line(9, 0, 9, 8)
    for i in range(1, n + 2):
        print(i)

        stddraw.line(3 - i / n, 8 * (n + 1 - i) / (n + 1), 3 + i / n,
                     8 * (n - i + 1) / (n + 1))
        stddraw.text(3 - i / n - 0.5, 8 * (n - i) / n, str(i))

    return location
Example #8
0
    def blome(self):
        stddraw.setXscale(-1.2, 1.2)
        stddraw.setYscale(-1.2, 1.2)
        x_list = []
        y_list = []
        for i in range(1, self.n + 1):
            theta = self.theta
            for n in range(100):

                x = math.sin(theta) * math.cos(theta)
                y = math.sin(theta) * math.sin(theta)
                x_list.append(x)
                y_list.append(y)
                if n > 0:
                    stddraw.line(x_list[n - 1], y_list[n - 1], x_list[n],
                                 y_list[n])
                    stddraw.show(50)

                theta += n * self.theta / 100
    def audio_note(self):
        stddraw.setXscale(0, 50)
        stddraw.setYscale(-10, 10)

        print('enter audio_note')
        duration = self.f
        hz = notes[self.n - 1]
        n = int(SPS * duration)
        samples = stdarray.create1D(n + 1, 0.0)
        for i in range(n + 1):
            samples[i] = math.sin(2.0 * math.pi * i * hz / SPS)
        print(samples)
        for i in range(0, n - 100, 100):
            stddraw.line(i / 500, samples[i], (i + 100) / 500,
                         samples[i + 100])
        stddraw.show()
        stdaudio.playSample(samples)
        print('play')
        stdaudio.wait()
def draw_count(countlist):
    # stddraw.setCanvasSize(100,100)
    stddraw.setXscale(-1,10)
    stddraw.setYscale(-0.1,0.5)
    stddraw.setPenColor(stddraw.GRAY)
    stddraw.line(0,0,100,0)
    stddraw.line(0,0,0,5000)
    for List in countlist:
        for i in range(1,len(List)):
            stddraw.line(i-1,List[i-1],i,List[i])
Example #11
0
def recursive_tree(n, A0, r, x0, y0):
    if n == 0:

        return
    xa = x0 + r * math.cos((A0 + A) / 360 * 2 * math.pi)
    ya = y0 + r * math.sin((A0 + A) / 360 * 2 * math.pi)
    stddraw.line(x0, y0, xa, ya)
    stddraw.show(50)
    recursive_tree(n - 1, A0 + A, r * a, xa, ya)

    xb = x0 + r * math.cos((A0 + B) / 360 * 2 * math.pi)
    yb = y0 + r * math.sin((A0 + B) / 360 * 2 * math.pi)
    stddraw.line(x0, y0, xb, yb)
    stddraw.show(50)
    recursive_tree(n - 1, A0 + B, r * b, xb, yb)

    xc = x0 + r * math.cos((A0 + C) / 360 * 2 * math.pi)
    yc = y0 + r * math.sin((A0 + C) / 360 * 2 * math.pi)
    stddraw.line(x0, y0, xc, yc)
    stddraw.show(50)
    recursive_tree(n - 1, A0 + C, r * c, xc, yc)
Example #12
0
import math
from stdpackage import stdarray
from stdpackage import stdaudio
from stdpackage import stdio
from stdpackage import stddraw

SPS = 44100
CONCERT_A = 440.0

stddraw.setXscale(0,50)
stddraw.setYscale(-20,20)
height = 1
while not stdio.isEmpty():

    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = CONCERT_A*(2**(pitch/12.0))
    n = int(SPS*duration)
    samples = stdarray.create1D(n+1,0.0)
    for i in range(n+1):
        samples[i] = math.sin(2.0*math.pi*i*hz/SPS)
    stdaudio.playSamples(samples)


    for i in range(0,n-100,100):
        stddraw.line(i/500,samples[i]+20-height,(i+100)/500,samples[i+100]+20-height)
    stddraw.show(duration*1000)
    height +=2

stdaudio.wait()
Example #13
0
def draw_clock(H=0, M=0, S=0):
    stddraw.setXscale(-1.5, 1.5)
    stddraw.setYscale(-1.5, 1.5)

    R = 1.1
    Hour_L = 0.4
    Min_L = 0.55
    Sec_L = 0.7
    Hour_count = 0

    Hour_X = stdarray.create1D(12, 0)
    Hour_Y = stdarray.create1D(12, 0)

    for i in range(1, 13):
        Hour_X[i - 1] = 1 * math.cos(-(i / 12 * 2 * math.pi - 1 / 2 * math.pi))
        Hour_Y[i - 1] = 1 * math.sin(-(i / 12 * 2 * math.pi - 1 / 2 * math.pi))

    stddraw.setFontSize(25)

    if H > 11:
        print('H is {0}'.format(H))
        H = H % 12
        Hour_count = 1

    while True:
        while H < 13:

            angle_H = H * 2 * math.pi / 12 - 1 / 2 * math.pi
            print('H is {0}'.format(H))
            if H == 12:
                H = 0
                Hour_count += 1

            H += 1

            if Hour_count % 2 == 0:
                text = 'morining'
            else:
                text = 'afternoon'

            while M < 61:

                angle_M = M * 2 * math.pi / 60 - 1 / 2 * math.pi
                print('m is {0}'.format(M))

                if M == 60:
                    print('m is 60')
                    M = 0
                    break
                else:
                    M += 1
                while S < 61:
                    angle_s = S * 2 * math.pi / 60 - 1 / 2 * math.pi
                    print('s is {0}'.format(S))

                    if S == 60:
                        S = 0
                        print('s is 60')
                        break
                    else:
                        S += 1

                    stddraw.clear()
                    stddraw.circle(0, 0, R)
                    for i in range(1, 13):
                        stddraw.text(Hour_X[i - 1], Hour_Y[i - 1], str(i))
                    stddraw.text(0, 0.85, text)

                    stddraw.setPenRadius(0.02)
                    stddraw.line(0, 0, Hour_L * math.cos(-angle_H),
                                 Hour_L * math.sin(-angle_H))
                    stddraw.setPenRadius(0.01)
                    stddraw.line(0, 0, Min_L * math.cos(-angle_M),
                                 Min_L * math.sin(-angle_M))
                    stddraw.setPenRadius(0.005)

                    stddraw.line(0, 0, Sec_L * math.cos(-angle_s),
                                 Sec_L * math.sin(-angle_s))
                    stddraw.show(1000)
Example #14
0
from stdpackage import stddraw

stddraw.setXscale(0,10)
stddraw.setYscale(0,10)

stddraw.line(0,0,10,10)
stddraw.show()
Example #15
0
# stddraw.show()

# stddraw.square(.2,.8,.1)
# stddraw.filledSquare(.8,.8,.2)
# stddraw.circle(.8,.2,.2)
# xd=[.1,.2,.3,.2]
# yd=[.2,.3,.2,.1]
# stddraw.filledPolygon(xd,yd)
# stddraw.text(.2,.5,'black text')
# stddraw.setPenColor(stddraw.WHITE)
# stddraw.text(.8,.8,'white text')
# stddraw.show()

from miaozaiye.stdpackage1 import stdarray

n = 2000

x = stdarray.create1D(n + 1, 0.0)
y = stdarray.create1D(n + 1, 0.0)

for i in range(n + 1):
    x[i] = math.pi * i / n
    y[i] = math.sin(4.0 * x[i]) + math.sin(20.0 * x[i])

stddraw.setXscale(0, math.pi)
stddraw.setYscale(-2.0, +2.0)
for i in range(n):
    stddraw.line(x[i], y[i], x[i + 1], y[i + 1])

stddraw.show()