Skip to content

Miaozaiye #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 138 additions & 148 deletions .idea/workspace.xml

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions miaozaiye/1-26 circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,35 @@
import random
import optparse
from stdpackage import stddraw
from stdpackage import stdarray
from stdpackage import stdaudio
import math

SPS = 44100
CONCERT_A = 440.0

pitch0 = 6





n = 200
p = 0.3
min = 0.05
max = 0.2

def play_tune(x,y,r):
pitch = (pitch0) * math.sqrt(x*x+y*y)/10
duration = float(r)*3
n1 = int(SPS*duration)
hz = CONCERT_A*(2**(pitch/12.0))
samples = stdarray.create1D(n1+1,0.0)
for i in range(n+1):
samples[i] = math.sin(2.0*math.pi*i*hz/SPS)
stdaudio.playSamples(samples)


def main():


Expand Down Expand Up @@ -45,6 +68,8 @@ def main():
stddraw.filledCircle(x,y,r)

i +=1

play_tune(x,y,r)
stddraw.show(10)


Expand Down
20 changes: 19 additions & 1 deletion miaozaiye/1-31-Spirograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@

import sys
import math
from stdpackage import stddraw,stdarray
from stdpackage import stddraw,stdarray,stdaudio

SPS = 44100
CONCERT_A = 220.0

pitch0 = 3
duration = 0.5

n = int(SPS*duration)


def play_tune(x,y):
pitch = (pitch0) * (x+y)/2
hz = CONCERT_A*(2**(pitch/12.0))
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)

def draw_spirograph(R,r,a):
stddraw.setXscale(-40,40)
Expand All @@ -32,6 +49,7 @@ def draw_spirograph(R,r,a):


stddraw.line(x[t],y[t],x[t+1],y[t+1])
play_tune(x[t],y[t])
stddraw.show(5)
stddraw.show()

Expand Down
23 changes: 20 additions & 3 deletions miaozaiye/G-ball.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#有重力效果的球


from stdpackage import stddraw
import math
from stdpackage import stddraw,stdarray,stdaudio

stddraw.setXscale(-1.0,1.0)
stddraw.setYscale(-1.0,1.0)
Expand All @@ -16,14 +16,31 @@
f = 0.005
position1 = [(r1x,r1y)]

SPS = 44100
CONCERT_A = 330.0
duration = 0.1
n = int(duration*SPS)
pitch = 1
hz = CONCERT_A*(2**(pitch/12.0))

samples = stdarray.create1D(n+1,0.0)
for i in range(n+1):
samples[i] = math.sin(2.0*math.pi*i*hz/SPS)

changepoint = []

while True:

if abs(r1x+v1x)+RADIUS>1.0: v1x = -v1x
if abs(r1x+v1x)+RADIUS>1.0:
v1x = -v1x

stdaudio.playSamples(samples)


v1y +=g
if abs(r1y + v1y)+RADIUS >1.0:
v1y = -v1y
stdaudio.playSamples(samples)

r1x = r1x+v1x
r1y = r1y + v1y
Expand Down
14 changes: 13 additions & 1 deletion miaozaiye/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@
'''

from stdpackage import stddraw
from stdpackage import stdarray
from stdpackage import stdarray,stdaudio
import math
import sys


SPS = 44100
CONCERT_A = 330.0
duration = 0.1
n = int(duration*SPS)
pitch = 1
hz = CONCERT_A*(2**(pitch/12.0))

samples = stdarray.create1D(n+1,0.0)
for i in range(n+1):
samples[i] = math.sin(2.0*math.pi*i*hz/SPS)

def draw_clock(H = 0,M = 0, S = 0):
stddraw.setXscale(-1.5,1.5)
stddraw.setYscale(-1.5,1.5)
Expand Down Expand Up @@ -91,6 +102,7 @@ def draw_clock(H = 0,M = 0, S = 0):
stddraw.setPenRadius(0.005)

stddraw.line(0,0,Sec_L*math.cos(-angle_s),Sec_L*math.sin(-angle_s))
stdaudio.playSamples(samples)
stddraw.show(1000)

def main():
Expand Down
28 changes: 27 additions & 1 deletion miaozaiye/dragon_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@

from stdpackage import stddraw
import math
from stdpackage import stdarray
from stdpackage import stdaudio


SPS = 44100
CONCERT_A = 440.0

pitch0 = 3
duration = 0.5

n = int(SPS*duration)




class DragonLine:
def __init__(self):
Expand All @@ -46,6 +60,17 @@ def turn_flow(self,wrap):

dragonline = DragonLine()

def play_tune(x,y):
pitch = (pitch0) * math.sqrt(x*x+y*y)


hz = CONCERT_A*(2**(pitch/12.0))
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)


def draw_line(dragonline,turn):
stddraw.setXscale(-5,5)
stddraw.setYscale(-5,5)
Expand Down Expand Up @@ -75,9 +100,10 @@ def draw_line(dragonline,turn):
stddraw.setPenColor(stddraw.BLACK)
stddraw.line(x_list[index],y_list[index],x_list[index+1],y_list[index+1])
stddraw.setPenColor(stddraw.RED)
play_tune(x,y)
# 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)


draw_line(dragonline,30)
draw_line(dragonline,20)
46 changes: 46 additions & 0 deletions miaozaiye/oscilloscope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#示波器,程序模拟示波器的输入,产生李萨如模式
'''

当两个相互垂直的周期扰动同时发生时,结果产生该模式图案

x(t) = A_x*sin(w_x*t+theta_x)
y(t) = A_y*sin(w_x*t+theta_y)

程序带六个命令行参数: A_x,A_y,w_x,w_y,theta_x,theta_y
'''

import math
import sys
from stdpackage import stddraw,stdaudio

def draw(x1,x0,y1,y0):
stddraw.line(x0,y0,x1,y1)
pass

def main():
A_x,A_y,w_x,w_y,theta_x,theta_y = sys.argv[1:]
A_x = float(A_x)
A_y = float(A_y)
w_x = float(w_x)
w_y = float(w_y)
theta_x = float(theta_x)
theta_y = float(theta_y)
i = 0
X = []
Y = []
stddraw.setXscale(-4,4)
stddraw.setYscale(-4,4)
while True:
x = A_x*math.sin(w_x*i+theta_x)
y = A_y*math.sin(w_y*i+theta_y)
X.append(x)
Y.append(y)
if i <1:
pass
else:
draw(X[i],X[i-1],Y[i],Y[i-1])
stddraw.show(20)
i +=1


main()