本代码方法下次再讲
import math
class bWold():
def __init__(self,x,y):
self.x=x
self.y=y
def Fdot(self):
self.x=self.x+1
line(self.x,self.y,self.x,self.y)
def Fprint(self):
return self.x
class aWold():
def __init__(self):
self.wold=[]
def sx(self,x,y):
a=bWold(x,y)
self.wold.append(a)
num=0
for i in self.wold:
i.Fdot()
x=i.Fprint()
if x>800:
del self.wold[num]
num=num+1
class dWold():
def __init__(self,x,y):
self.x=x
self.y=y
def Fdot(self):
self.y=self.y-1
line(self.x,self.y,self.x,self.y)
def Fprint(self):
return self.y
class cWold():
def __init__(self):
self.wold=[]
def sx(self,x,y):
a=dWold(x,y)
self.wold.append(a)
num=0
for i in self.wold:
i.Fdot()
x=i.Fprint()
if x>800:
del self.wold[num]
num=num+1
def trianglefunction(x,y,r,an):
xz=x+r*math.cos(an*3.141592653589793238462643383279502884797169399875105820474944/180 )
yz=y+r*math.sin(an*3.141592653589793238462643383279502884797169399875105820474944/180 )
return xz,yz
def setup():
global an,wold,ys,yszf,wold2,yun,ie
size(800,800)
wold=aWold()
wold2=cWold()
an=0
yun='cos和sin'
ys=1
ie=0
yszf=True
def draw():
global an,wold,ys,yszf,wold2,yun,ie
background(255)
if yun=='cos和sin':
fill(255)
colorMode(HSB)
stroke(ys,255,255)
strokeWeight(5)
ellipse(100,700,200,200)
colorMode(RGB)
stroke(0)
#line(300,100,300,700)
x,y=trianglefunction(100,700,100,an)
line(100,700,x,y)
strokeWeight(2)
line(x,y,100,y)
strokeWeight(5)
wold.sx(100,y)
wold2.sx(x,700)
if yszf:
ys=ys+1
else:
ys=ys-1
if ys<1:
yszf=True
if ys>358:
yszf=False
stroke(0)
strokeWeight(2)
line(x,y,x,700)
fill(0)
textSize(50)
text('x=O+r*cos('
+str(an%360)
+'\n*3.14/180)\n'
+'\ny=O+r*sin('
+str(an%360)
+'\n*3.14/180)\n\n'
+'r=100\nO=(100,700)',300,50)
an=an+1