from kandinsky import * import ion W, H = 320, 240 XMIN, XMAX = -9.0, 9.0 YMIN, YMAX = -7.5, 7.5 # Couleurs BG = (5, 15, 35) RED = (255, 75, 85) ROSE = (255, 130, 160) LPINK = (255, 190, 210) DPINK = (220, 50, 80) ORANGE = (255, 165, 75) YELLOW = (255, 230, 90) LYELLOW = (255, 245, 180) GREEN = (60, 195, 100) DGREEN = (35, 140, 70) LGREEN = (140, 230, 140) WHITE = (250, 250, 255) GOLD = (255, 215, 100) SKY = (180, 220, 255) def to_pixel(x, y): px = int((x-XMIN)*(W-1)/(XMAX-XMIN)) py = int((YMAX-y)*(H-1)/(YMAX-YMIN)) return px, py def dot(px, py, c, r=1): for dx in range(-r, r+1): for dy in range(-r, r+1): x2, y2 = px+dx, py+dy if 0<=x2<W and 0<=y2<H: set_pixel(x2, y2, c) def line(x0,y0,x1,y1,c,r=1): dx, dy = x1-x0, y1-y0 s = max(abs(dx), abs(dy)) if s == 0: dot(x0, y0, c, r) return for i in range(s+1): x = int(x0+dx*i/s) y = int(y0+dy*i/s) dot(x, y, c, r) def dim(c, k=0.25): return (int(c[0]*k),int(c[1]*k),int(c[2]*k)) def curve(f,xa,xb,c,th=1,n=None): if n is None: n = max(60, int((xb-xa)*90)) prev = None for i in range(n+1): x = xa+(xb-xa)*i/n y = f(x) px, py = to_pixel(x, y) if 0<=px<W and 0<=py<H: if prev: line(prev[0],prev[1],px,py,c,th) else: dot(px, py, c, th) prev = (px, py) else: prev = None def gc(f,xa,xb,c,th=1): curve(f,xa,xb,dim(c,0.22),th+1) curve(f,xa,xb,c,th) def sym(f,xa,xb,c,th=1): gc(f,xa,xb,c,th) gc(lambda x,fr=f: fr(-x),-xb,-xa,c,th) # Fond fill_rect(0, 0, W, H, BG) # Morceaux de tige tige_centres = [] yy = -6.3 while yy < 1.5: tige_centres.append(yy) yy += 0.8 for yc in tige_centres: gc(lambda x, yy=yc: -55*x**2 + yy + 0.7, -0.13, 0.13, GREEN, 2) # Courbure tige gc(lambda x: 0.008*x**3 + 0.12*x**2 + 0.25*x - 2.6, -0.13, 0.13, DGREEN, 2) # Feuille droite # Bord superieur gc(lambda x: -0.35*(x-2.2)**2 - 3.2, 0.0, 4.2, GREEN, 2) # Bord inferieur gc(lambda x: 0.30*(x-2.2)**2 - 4.2, 0.0, 3.9, GREEN, 2) # Arrete gc(lambda x: -0.025*(x-2.2)**3 - 0.02*(x-2.2)**2 - 3.7, 0.15, 3.6, LGREEN, 1) # Feuille gauche gc(lambda x: -0.30*(x+2.5)**2 - 4.0, -4.8, 0.0, DGREEN, 2) gc(lambda x: 0.25*(x+2.5)**2 - 5.0, -4.5, 0.0, DGREEN, 2) # Arrete gc(lambda x: 0.020*(x+2.5)**3 - 0.015*(x+2.5)**2 - 4.5, -4.2, -0.15, LGREEN, 1) # Feuille droite haute gc(lambda x: -0.50*(x-1.5)**2 - 0.8, 0.0, 3.0, GREEN, 1) gc(lambda x: 0.45*(x-1.5)**2 - 1.6, 0.0, 2.8, GREEN, 1) # Arrete gc(lambda x: -0.015*(x-1.5)**3 - 0.02*(x-1.5)**2 - 1.2, 0.15, 2.5, LGREEN, 1) # Feuille gauche gc(lambda x: -0.45*(x+1.5)**2 - 1.2, -3.0, 0.0, DGREEN, 1) gc(lambda x: 0.40*(x+1.5)**2 - 2.0, -2.8, 0.0, DGREEN, 1) # Arrette gc(lambda x: 0.015*(x+1.5)**3 - 0.02*(x+1.5)**2 - 1.6, -2.5, -0.15, LGREEN, 1) # PETALE sym(lambda x: -1.8*x**2 + 6.5, 0.0, 1.7, RED, 2) sym(lambda x: -0.9*x**2 + 4.0, 0.0, 1.5, RED, 2) sym(lambda x: -1.4*x**2 + 5.8, 0.0, 1.3, ROSE, 1) sym(lambda x: -1.1*x**2 + 5.0, 0.0, 1.1, LPINK, 1) # PETALE HAUT DROIT gc(lambda x: -0.38*(x-3.8)**2 + 4.8, 1.2, 6.4, DPINK, 2) gc(lambda x: -0.22*(x-3.5)**2 + 2.5, 0.8, 5.8, DPINK, 2) gc(lambda x: -0.32*(x-3.7)**2 + 4.1, 1.6, 5.8, ROSE, 1) gc(lambda x: -0.28*(x-3.6)**2 + 3.4, 1.8, 5.2, LPINK, 1) # PETALE HAUT GAUCHE gc(lambda x: -0.38*(x+3.8)**2 + 4.8, -6.4, -1.2, DPINK, 2) gc(lambda x: -0.22*(x+3.5)**2 + 2.5, -5.8, -0.8, DPINK, 2) gc(lambda x: -0.32*(x+3.7)**2 + 4.1, -5.8, -1.6, ROSE, 1) gc(lambda x: -0.28*(x+3.6)**2 + 3.4, -5.2, -1.8, LPINK, 1) # PETALE BAS DROIT gc(lambda x: -0.15*(x-4.0)**2 + 1.8, 1.0, 6.5, ORANGE, 2) gc(lambda x: 0.020*(x-3.8)**4 - 1.2, 1.2, 5.8, ORANGE, 2) gc(lambda x: -0.12*(x-3.9)**2 + 1.0, 1.8, 5.8, YELLOW, 1) gc(lambda x: -0.10*(x-3.8)**2 + 0.2, 2.2, 5.2, LYELLOW, 1) # PETALE BAS GAUCHE gc(lambda x: -0.15*(x+4.0)**2 + 1.8, -6.5, -1.0, ORANGE, 2) gc(lambda x: 0.020*(x+3.8)**4 - 1.2, -5.8, -1.2, ORANGE, 2) gc(lambda x: -0.12*(x+3.9)**2 + 1.0, -5.8, -1.8, YELLOW, 1) gc(lambda x: -0.10*(x+3.8)**2 + 0.2, -5.2, -2.2, LYELLOW, 1) # Cercle exterieur sym(lambda x: -3.5*x**2 + 2.8, 0.0, 0.85, GOLD, 2) sym(lambda x: 3.5*x**2 + 1.2, 0.0, 0.85, GOLD, 2) # Cercle interieur sym(lambda x: -5.0*x**2 + 2.5, 0.0, 0.62, YELLOW, 2) sym(lambda x: 5.0*x**2 + 1.5, 0.0, 0.62, YELLOW, 2) # Centre sym(lambda x: -18*x**2 + 2.25, 0.0, 0.28, LYELLOW, 1) sym(lambda x: 18*x**2 + 1.75, 0.0, 0.28, LYELLOW, 1) gc(lambda x: -25*(x-0.3)**2 + 2.15, 0.2, 0.4, WHITE, 1) gc(lambda x: -25*(x+0.3)**2 + 2.15, -0.4, -0.2, WHITE, 1) gc(lambda x: -30*x**2 + 2.35, -0.12, 0.12, WHITE, 1) gc(lambda x: 3.5*x**2 + 1.2, -0.45, 0.45, GREEN, 2) gc(lambda x: -8.0*x**2 + 1.5, -0.35, 0.35, DGREEN, 1) gc(lambda x: -40*x**2 + 1.4, -0.15, 0.15, GREEN, 2) gc(lambda x: -40*x**2 + 0.9, -0.14, 0.14, GREEN, 2) # motif petale haut sym(lambda x: -6*(x-0.7)**2 + 5.6, 0.5, 0.9, WHITE, 1) sym(lambda x: 5*(x-0.7)**2 + 5.2, 0.55, 0.85, WHITE, 1) # motif petale haut-droit gc(lambda x: -4*(x-4.2)**2 + 4.0, 3.9, 4.5, WHITE, 1) gc(lambda x: 3.5*(x-4.2)**2 + 3.6, 3.95, 4.45, WHITE, 1) # motif petale haut-gauche gc(lambda x: -4*(x+4.2)**2 + 4.0, -4.5, -3.9, WHITE, 1) gc(lambda x: 3.5*(x+4.2)**2 + 3.6, -4.45, -3.95, WHITE, 1) # motifs petale bas-droit gc(lambda x: -3*(x-4.5)**2 + 0.5, 4.1, 4.9, WHITE, 1) gc(lambda x: 2.8*(x-4.5)**2 + 0.0, 4.15, 4.85, WHITE, 1) # motif petale bas-gauche gc(lambda x: -3*(x+4.5)**2 + 0.5, -4.9, -4.1, WHITE, 1) gc(lambda x: 2.8*(x+4.5)**2 + 0.0, -4.85, -4.15, WHITE, 1) # ETOILES DECORATIVES pts = [(-7,5.5),(-6,6.2),(6.5,5.8), (7.2,4.5),(-7.5,3),(7,-3), (-5.5,-6),(5,-5.8),(-3,6.8), (3.5,6.5),(-8,-1),(8,1), (-7,-4.5),(7.5,-5),(0,-7)] for p in pts: xc, yc = p r = 0.15 gc(lambda x,xc=xc,yc=yc: -12*(x-xc)**2+yc+0.15, xc-r, xc+r, SKY, 1) gc(lambda x,xc=xc,yc=yc: 12*(x-xc)**2+yc-0.15, xc-r, xc+r, SKY, 1) # POLLEN vers centre pollen = [(1.5,3.5),(-1.2,3.8),(2.8,2.5), (-2.5,2.8),(0.5,3.2),(-0.8,2.9), (1.8,1.5),(-1.6,1.2),(0.3,3.9), (-0.4,1.0)] for p in pollen: xc, yc = p gc(lambda x,xc=xc,yc=yc: -20*(x-xc)**2+yc+0.08, xc-0.08, xc+0.08, GOLD, 1)