Friday, December 13, 2019

"Pattern" Drawing by Functions


import numpy,pylab; pi=numpy.pi 
def randi(nmin,nmax): return numpy.random.randint(nmin,nmax)
def randc(a): return numpy.random.choice(a,1)[0]
a,c=(.5+numpy.random.random())*randc([-1,1]),.01*randi(1,99)**randc([-1,1])
b,d=randi(6,18),randi(3,6); t=numpy.arange(0,8*b*pi,1/(720.*b))
fx=numpy.sin(t/6)+a*numpy.sin(b*t)*numpy.cos(t)+c*numpy.sin(b*t)
fy=numpy.cos(t/6)+a*numpy.sin(b*t)*numpy.sin(t)+c*numpy.cos(d*b*t)
pylab.figure(figsize=(10,10)); ax=pylab.gca(); ax.set_facecolor('lightgray')
pylab.scatter(fx,fy,s=.1**4,c=[numpy.random.random(3)])
pylab.title(['a=%f'%a,'b=%d'%b,'c=%f'%c,'d=%d'%d]); pylab.grid(); pylab.show()

No comments:

Post a Comment