# fleur.py

Created by andreanx

Created on February 03, 2019

1.28 KB

Draws a flower. Requires version 10.0.0 or newer (turtle module). See example at the end of the script.

Usage : fleur(n,k,l,f,c) with :

n: number of petals

k: number of leafs

l: length of stalk (drawn with the current position and orientation of the turtle)

f: a factor for the size of the leafs and petals, default is 1

c: color of the petals

```from turtle import *
import kandinsky

def forbackward(d):
forward(d)
backward(d)

def pf(d=1,gd=-1,nervure=False):
n=9
pos=position()
for j in range(2):
for k in range(n):
forward(d)
right(gd*90/n)
right(gd*90)
if nervure:
right(gd*40)
forbackward(5*d)
right(-gd*40)

def fleur(npetales=8,nfeuilles=2,ltige=160,kfeuille=1,c=kandinsky.color(255,255,0)):
d=ltige/(nfeuilles+1)
color(0,191,0)
for j in range(nfeuilles):
forward(d)
pf(kfeuille,2*(j%2)-1,True)
forward(d)
color((c>>11)<<3,((c>>5)%64)<<2,(c%32)<<3)
for j in range(npetales):
pf(kfeuille,-1)
left(360/npetales)

#example
from math import *

def hsv2color(h,s=1,v=1):
c=v*s
x=c*(1-abs((h%120)/60-1))
m=v-c
k=int(h/60)
r=255*(m+x*(k==1 or k==4)+c*(k==5 or k==0))
g=255*(m+c*(k==1 or k==2)+x*(k==3 or k==0))
b=255*(m+x*(k==2 or k==5)+c*(k==3 or k==4))
return kandinsky.color(round(r),round(g),round(b))

def horiz(y,col):
for x in range(320):
kandinsky.set_pixel(x,y,col)

for j in range(112):
horiz(111-j,hsv2color(210,0+1*j/111,1))
horiz(111+j,hsv2color(30,.1+.9*j/111,.7))

sw=320
sh=222
ymax=sh/2
ymin=ymax-sh+1
xmin=-sw/2
xmax=xmin+sw-1
penup()
goto(0,ymin)