Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Blog
Views: 63
Author: Vincent J. Matsko Date: 8 November 2015, Day012 Post: Evaporation II
from sage.plot.colors import rgbcolor def RGBValue (r): # Makes sure r is in the correct range (that is, between 0 and 1). if r < 0: return 0 else: if r > 1: return 1 else: return r def RandomColor(base, tolerance): return rgbcolor([RGBValue(base[count] - tolerance*random()) for count in range(3)]) # Parameters which may be changed: ## width : (number of circles) ## height: (number of circles) ## color : in RGB values ## exp : the exponent for the gradient (1 for linear, 2 for quadratic, etc.) ## r : base radius for circles ## rvar : how much randomness to add to circle radii ## seed : random number seed - keep track of this, since it really does affect your image! def Evaporation(width, height, color, exp, r, rvar, seed): disks = [] # Saves the points in the final image. set_random_seed(seed) for i in range(width): for j in range(height): disks.append(plot(disk((i,j), r + rvar * random(), (0,2*pi), rgbcolor=RandomColor(color,((height-j)/height)^exp)))) P = sum(disks) show(P, aspect_ratio=1, svg=True, axes=False, xmin=-1, xmax=width+1, ymin=-1, ymax=height+1) save(P, os.path.join(SAGE_TMP, 'test.svg')) Evaporation(10, 10, [0.0,0.9,0.9], 2, 0.4, 0.25, 47)