Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168730
Image: ubuntu2004
%cython def sierpinski(n): cdef float t GG=[] LL=[[1,0]] for m in xrange(n): t=random() if t<(1.0/3.0): g=[LL[m][0]/2.0,LL[m][1]/2.0] elif ((1.0/3.0)<t) & (t<(2.0/3.0)): g=[(LL[m][0]+2.0)/2.0,LL[m][1]/2.0] else: g=[(LL[m][0]+1.0)/2.0,(LL[m][1]+sqrt(3.0))/2.0] LL.append(g) return LL
S=sierpinski(500000) point(S, size=1, axes=false)
%cython def fernleaf(n): cdef float t GG=[] LL=[[0,0]] for m in xrange(n): t=random() if t<(.01): g=[0,.16*LL[m][1]] elif ((.01)<=t) & (t<(.86)): g=[0.85*LL[m][0]+0.04*LL[m][1], -0.04*LL[m][0]+0.85*LL[m][1]+1.6] elif (.86<=t) & (t<.93): g=[0.2*LL[m][0]-0.26*LL[m][1], 0.23*LL[m][0]+0.22*LL[m][1]+1.6] else: g=[-0.15*LL[m][0]+0.28*LL[m][1], 0.26*LL[m][0]+0.24*LL[m][1]+0.44] LL.append(g) return LL
C=fernleaf(100000)
point(C, size=1, color='green', axes=false)