Sunday 15 August 2010

Drawing the Dominica Flag (Not Dominican) Using Python Turtle -



Drawing the Dominica Flag (Not Dominican) Using Python Turtle -

i trying draw commonwealth of dominica flag (not confused dominican flag) using python turtle. have in code except bird (which have no thought how either). can't seem figure out how 10 stars show within reddish circle no lines within stars. great if tips on how center stars within circle how go drawing bird in middle. thanks!

here image of it:

here code have far:

import turtle wn = turtle.screen() alex = turtle.turtle() def drawrect(): alex.speed(0) alex.up() alex.fillcolor("green") alex.begin_fill() alex.setpos(-250, -100) alex.down() in range(2): alex.forward(500) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() drawrect() def drawlines(): alex.speed(0) alex.fillcolor("yellow") alex.begin_fill() alex.penup() alex.setpos(-250, 70) alex.pendown() in range(2): alex.forward(500) alex.left(90) alex.forward(30) alex.left(90) alex.end_fill() alex.fillcolor("black") alex.begin_fill() alex.penup() alex.setpos(-250, 40) alex.pendown() in range(2): alex.forward(500) alex.left(90) alex.forward(30) alex.left(90) alex.end_fill() alex.pencolor("white") alex.fillcolor("white") alex.begin_fill() alex.penup() alex.setpos(-250, 10) alex.pendown() in range(2): alex.forward(500) alex.left(90) alex.forward(30) alex.left(90) alex.end_fill() alex.speed(0) alex.fillcolor("yellow") alex.begin_fill() alex.penup() alex.setpos(-40, -100) alex.pendown() in range(2): alex.forward(30) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() alex.speed(0) alex.fillcolor("black") alex.begin_fill() alex.penup() alex.setpos(-10, -100) alex.pendown() in range(2): alex.forward(30) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() alex.speed(0) alex.pencolor("white") alex.fillcolor("white") alex.begin_fill() alex.penup() alex.setpos(20, -100) alex.pendown() in range(2): alex.forward(30) alex.left(90) alex.forward(300) alex.left(90) alex.end_fill() drawlines() def drawcircle(): alex.speed(0) alex.up() alex.setpos(10, -50) alex.down() alex.fillcolor("red") alex.begin_fill() alex.circle(100) alex.end_fill() drawcircle() def drawstars(): alex.speed(0) alex.pencolor("green") alex.fillcolor("green") alex.begin_fill() in range(5): alex.forward(20) alex.right(144) def makestars(): alex.penup() alex.setpos(25, -10) alex.pendown() in range(11): drawstars() alex.left(35) alex.penup() alex.forward(45) alex.pendown() makestars()

is homework, or you're doing own self-learning? either way, drawing parrot not going easy! svg twotwotwo linked uses on 40 distorted ellipses , 30 linear paths; guess created in vector drawing programme (eg inkscape).

even if aren't familiar svg file may still useful you. since it's wikipedia, assume it's representation of current official commonwealth of dominica flag, sizes, positions, , colours of elements should accurate.

here of colours file:

yellow: "#fcd116" green: "#006b3f" red: "#d41c30"

the turtle module understands colours in format.

...

now, onto current problems.

i haven't used turtle graphics many years, inspired me install tkinter tinker code. first problem noticed alex.left(35) in makestars(), should 36, since 360°/10 = 36°.

i tried various things star circle correctly centred, , stars aligned properly, after hr or of frustration gave on simple drawing commands. i'm sure it'd breeze turtle expert, decided on more trigonometric approach.

due way turtle module filling, there's no easy way draw filled stars. vector drawing systems have alternate fill modes around problem, turtle doesn't appear so. either have fill in centre of star pentagon, or draw star 10 sided polygon.

i have written code draws filled stars centered , aligned. sizes in code aren't exactly same in svg, they're quite close. i'm happy post code here if own self-learning exercise. otoh, if homework shouldn't post whole thing...

ps. makes easier read code if define functions first, , phone call them @ bottom of programme (preferably within main() function). interspersing function calls function definitions bit messy.

python python-3.x turtle-graphics

No comments:

Post a Comment