processing源码分享(2)----数学之美cox与sin

本文介绍了四个类(bWold,aWold,dWold,cWold)的实例化、方法(Fdot,Fprint)以及图形绘制过程,通过三角函数计算并动态更新坐标,展示了一个基础的编程实践应用。
摘要由CSDN通过智能技术生成

本代码方法下次再讲

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值