0% found this document useful (0 votes)
17 views

Module 3 Py

The document provides information about turtle graphics in Python. It discusses turtle operations like forward(), backward(), left(), right(), and pencolor(). It provides examples of drawing shapes with turtles like squares, stars, and spirals. It also discusses examining an object's attributes, taking random walks, and image processing techniques like converting images to black and white. The examples demonstrate how to manipulate turtles to draw different patterns and explore their properties.

Uploaded by

Ankitha Praveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Module 3 Py

The document provides information about turtle graphics in Python. It discusses turtle operations like forward(), backward(), left(), right(), and pencolor(). It provides examples of drawing shapes with turtles like squares, stars, and spirals. It also discusses examining an object's attributes, taking random walks, and image processing techniques like converting images to black and white. The examples demonstrate how to manipulate turtles to draw different patterns and explore their properties.

Uploaded by

Ankitha Praveen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

MonLE

GRAPHIC

Simple Gapics vaimg TuRTLE

Tuntle
iwetimq
tud paukaqe t hwte impot
t -"TuouHeC)

he ((0D) 0Mw luod pointng Eot (o°)


ortn pt or

odus oatve haodang


= tw nt")
e tHeoding N (9)

Uo) w Fok o)

CcvoY-daut vlauk (216) Pu um


- iial 4 pixe

whetho it u upjdourn
LTme dram
onas
False m fouhng
2Doum
*Tutls ta toncist of A ambus
-

uodina, Culor i d (h
dons Mnruw mibekane
TURTLF OPERATIONS
*

Ot
t-Tuie( ) vwals nouo Tutte doj vvdsuw Ofeins

homa ) movest (0,0) and paids c° duu Fast (defouk)


tup )
tdou )
e l hodva 'doarro,) =ojat tunto by doaaa
t tfdsas3>r lalo u t t t a at tdicyas) olate nahi
tge () move pos (My )
m a n d (ietome): ove t y duet M cuureut dleL

tpeueior (9.b)
tAldo (b)/ong
egn-fll () {

treud.feuO
dan0
uoidH (pines)
1 tndehtfo ) &howtokte()
poc1hntehumy (xy)
twodhng C dMec
isAoun () =
up deu?
T-dewm

1 ) Dra a gquaNe

ronn tuwuHe impost Twtte


t- Tuatte (O
:
pr A AM Aduge C4)
owad (so)
g t C90)

oe -dove )

2) Dsom a sta

wm fte Ampost Tute


sTuntie)

s aigu C7
stpaud (l00)
o mM romge (q)
s aiqnl Cru4)
sornand 1oD)
s.end-kil)
tutte done C)
3) Rxaqov)

-tvke Tuatle()
sile - 7o
augls =360/6 6o°
AAM Nge (6):
horwond(do)
-uut Comgte)
tuut dene ()

4)ToAnauo etla Tm olors

twtdh (2
tleht Cqp
owaud C50)
tlogtCq0
t-upt
Eowand( )
t-setkeaacdva D)
tpencoto ("nd")
bun C)
oviaud (20)
oide hwt C)
Sprol tteun
rom ua tpot Twtic

Aw = Soeen)
Twti ()
Lspad (20)

tcco (5x)
tOcl(-bti)

6)Rodval Horac

del todal Heyogens (n evath)


tov CewYt (cwe (n):
Muoqw (t,lkvath )

t t (340/)
ExAMIN ING. am OBTFCT'S ATTRIBUTESs

1 pogthevv C) Ouebr mutnndstnal fahwms Valus


hoadng )

atibvlis
Hudakr ndoeds Clogemawipulate

TURTF SReEN

&wivdao- Veignt () Jocats deu bamdanies


votndso-vdh ()
:

*Toqe nd y vams / h ) | | 2
uger)
vidhc)

TAKING A RANDDM WALK


on hoe Anpot Tu
impt owdom
de Yowd boalk CEtuovd,distwmuc= 20)
for x m rouge (howu)

2 - =
O:
tet (vadpmiowdint (0270))
oNge
nigni (Anmd Sadink (o210))
|Jenatn Bo
Mger JonqAh x2
oro Paem (
pouao P -wcun t AMct
om houtle impost Ttle
t Tuntie ) Louint,lonath)
oowlalew (t
cefsaane (t\ngrh): -voidh tAviGet
- e i g k +ANLt

sqane, wwt, luoth)


fl Clong)
tlot C9o) Jengh-20
nget-veth *3
d haxogw (Llength) ohowPediem (t,
for sids aim vowar (6 ): wrokh-Amgek,
d Clangh)
|oav adem (t,
dak rodialPelygern(tsope,n,lengtn) wah-1gct
iaut tve hupogo,
COwmt am (omqe (n) .
cewnk Jougtw
Shape (Eovqth)
fFrom twHe Ampoyt Twmtle
p pry os ampot *

ampot vandom
da draunfatien 8npeAnwnt,kuglu ) ;
egn.-il 0

thaodng ()
coucw ()
tSUen ovwode (255)
tloetor ( Aandhom Towewt (D/255) Kandam.Yamdmt(oya)
roundem avdint (D,25-))
Todial Poyeevn (t,ehope, Cewnt ouatu)
defwaun ():
Speed (20
wnt =1C0
wid t shueN -wveeto uiolKh t Il2
hoindat t SOOn. hdswhdilL [ )/l,
MAGE TROCE S6ING

vuog bk -
euhinuous nowa f values
icoutz values
agital tko -

ampin- tech ued An pous of Cnwoting /mapping euk avolog


nko ow o Teal v sval sne) Anh seh ofoviawete dirtl yalues

-meaw docouke colow valMes


desrivt polns pels
Fiv oanwls -naneng faves all fomged mk o auge
-

Ubmpve gsed Amgs uged ew PEG1,TF,ekc


o Data CovpEion seVevnts tn 3PECG-
L osls lompvesDV
Oly post thens f pixe. wivh oww.ou cfows voilw o gidshpred

.deuopnegio vestpye3 upvor vauea wofo omy Amo lo


Loy vpvegsic
ORpmy oo volus o pres in M a a is stored
dubvuNegten ures Amg wh oporox ors (webu to
uwoM ye) wlh kos of Bowe mko

sp1) CemarRabv Step 2)Juom1VM-


Phoe SAgoavaliaa3 tobor gamples Ondeuovwveysio ,aloo u GJ
.Builds a otov palok{e Kous&covcs paleke
Pha tach Sawwp Am qnd As ustrie qvd of pvelu
Msted repaud ith o y stnome but wDk
ky ofdoset aior Am wu AWas win laqelataseas
paleti
Tnoge Mamipulatuo
Rolate onw ho graysialk - covorttlten e d ovea -Bluus

rvol wmyugen-
peu-nat ngnhus EAge Detecha Rosne
-

-
gmageopovnies
c b g ns eadsd nto a P

pom Amg v
so reuk-anea
ofcotoused pal
cii lo maps bils

Sueen covdnmë
(idtn-1,tqit-1
Cii) Coor vahe =r (1g/o)

Amoqes Modue: ahems koad om awmagr &en


Mownpulatu At

fom Amaqes smp0t mage

Amoge- Jmagt ("peqit


Awage dnaw ()

NeWhods

d-Iwogt (koname)
A Tvmaqe (wia,aiaut) lwa blrmk Aug
dgotoidka ) a teiauk ()
RUnB viu
-gerPirel (x >retwws huplu o teqeu rep

get Prel ( x (7g)) replae8 Uumt RG valme y

.dvauN (K displays dM anndow dow doge fo rehum


.love ( py vehameel (As \alunowne )
64we Clevona ) Save/save as

ionme
oidha
Gnid
2 4

Poirt (csumn mw

V(R)
Lecpschvne kor Row Maro Tavesad (eacncwmn m each ow )

OLLeSS
( A rge (<huig t -): 2

Amage qnd. kr x m romae (<width >)

int( , evd -" ")


<do sowethng

Converhi tmg to B& W

Cmpute owa g6) Vauasof Ag


S rgbag cege Fo o en get (vg.b)-ee0)re l3tck

h g g cdee to ayo Meun ge (ngb)- (ss, 2s,2ss)te


whib
det Bandw (Amane)
blaukPixel = (o,0,0)
tshlaPixel -(255,259,265
A n s0ma tmage qetRaiout t)) :
M vOmge Amag qotwidlu()):
b ) Amage qet Pxol )
(v+6) 3
Avg</28
inage c t
Fal
(x.y, blakePixel )
e
Auage. setPxel (>wyusite Poxel)
*HwmoM smor engtrve to R2G ham B
pe

To aeuou or umi ncwae e d ergul cevYs tb Y,gm

D-294434 o:581 X-t0 1Irb )


wg- 0 58T
Ws = 0 299 LOgt wy t

T ra (avuaqe)
w rounqe inage qetkegint (O) :

for x In raar ( Amog tWiM* (O):


a.b)- imoge getPireb(7
ivt (s A0.299)
Ant Cq * b-587)
b Ant ( b o l4)

imngeePial ((um,wm,wn

*bvalig a cione wilh exac sama athbus (eqal smuehually


bu daed by empy thng vwot Aawne) n- cdona )
Bwwing am taqR

xPx ilahon = jad/rougu edge3 ton pe removed b

wovin c

Travalsa on 1) * uadim-2, heiauk-2)


de w (umaag)

def toplo sun (biple 1, mpe


2):

(lglb)
=
bfple 1
(2, 2,b2) -
hiple2
rehon 3142,34t92, bltb2)

Mew Aage. tlone ()

A rovngt )-1)
(,imaqa geteigt
ey An
ramg (1, tmaep.qottoidh () - 1)
old P waqeqeticek (n)
o t = image qeiPinal ( -

nt mage get Picel lyy)

pollom mage qetixel (*qpuwwo t


Jodute bnpleBumm, Lbldegt)iaut,top/bettomJ)
wmmE=( r 943,2) g (+gwatted poxcl i oriqnail)

avesages= upleMup(dowmbda x; xl/5 ,Sms))


t g-/52g/t5 , ibi/5) 4e Tasgevg hava)
raO getPrel.avenaqes)
o0422

ED6F DETECTION

to edaa/cuthnas is
amaves ul oslor unuove

To dutect edga - exawwne Aekt 2 boffom Migubovws

w i yewmie of pel dffw po


ux 2 by loa
onvk theu cUnt pel ts tn 9

edae pt9et blaaeyel


es set shibPiye
Lwm Vounua Mçe tom xperimevt win AMe u i t

del datectEaes (amage awownt)


def wqe Chiple):

oghortuvew (74q1b)//3
Plauk (eA)
w - 95, 25512b5,
(Ch-1)
w Amaap clonm ()

ah n (umag qtaiqat() -1):


r awmainage 9ptbouth) A)
bidP mag ge¥yel )
Aot Jimnge ekkixel (-1,4
borvoon= Amuge ptRiy el (,
41)
o14lwm =
aNaaas (odP)
atlun =oveLage ( ) Shn

bolonum aNeaag oothowm)


=

AavsMdLuw- utwwm)>moun
obs
(olduwn -Vetlomlunn) > amwcumk
KEDUCING| TME IMAGE SKF

*lge deperds n anghk voidm å reso nton


I t A2 w o A o e redutod by N image o r v a u o e

sedued o4 uhr N M vecult Amg

*RauMg (áge pvoves stote spau Load hme


Sze nedu" pesones Amoqes Aspeet Ratio Votd f noierwk fu wdth

S= mg red b \,
*opVrowUSSDrqal (Aanger) mg and skips posthos by inowmenhing
coveae by AMe Eounkoar achoynow Amg oop AUUMeMts as val

Onignal shomeM Amg


OxO X

S-2

def zmok (amage facror):


voidm -Anoge qethtlth )
Awigut =
VenF mnge (adh // fackor ,Meignt actor

MDY
siile oldY < huig wt factoy
od x = O
ww X = 0
wie oAX <width -

{atvr
otd P mage qt PiKel (otd x,s[dY
new Set Pixel (
Venw X,nen Y, old P
tldx4adtoy
dlAY + acto
rowY +-]
GRAPH ICAL UsER INTERFACF S GUI

Tewinol Basgd Pyoqams GU Paced pama

covtumd wvyiol ovNa evey dtven -bagd


ugEL Mtuadibus-
nvSe ps -p 2
aueps
1o way tv chovnaa ordu
ed gquenu o vteung
p s to e quiey
f qve w ips - eed uses veidoez ond elAs cdack2
-

Event Drive qtarnmima

NS Vauis kor uge-druven events dhat mago opeaAbns

a-
8stombiat dogu fwindew (omponu
ve,
3ostuo opoMents on Mc ndevð
4Raatn a med ur each coponuwwt vsoR eVeMt
os
5pehvu wew- vonding weknods
Dehemaw wd Ingantiat
woin app indow
Cocding mple Giui-Poged Poqrams

lomdaole Moduk inte (rayythengud is aueluus of i s )

A navw wihdew ens exteu ds- FaM fYome ils

hom vcenyMPythovgui impotEasyhawne


Cass LAel Dewno ( Easyrame) labe Devmo tntends tasy hawme
de ib- (ssf)
Las ame iiEsct ) EeryFrana.mt-- (self, buaut-
welkhAt
Sf.addLabel (text -"Rllo WnAd', we =0, ahumn = O
dek main ()

labelDewo (). mamloop ()

-name = Ma W-
wmaim C)

Dektne cays labelDemo hat arttends Easyhams dass An 61Ul-pka

a) Dektne i t malnod clays lalelpenuo Mal muns i t of pannl


3)ek omponoMs nudad

hot vealis ob o labelDemo clous awmd


4) Dekdne main k
aoiuelouo is dogecl t i a
own &t oo" (maim loop) wnil
ame

nhwubamw
Easytvam

LabdDewo
Templat o 61Dl Þg

bww oYcuPythonqui Ampostasy reme


otinee Ampots
clas ApPNem ( Fosayhame)

e Amcl menod domton


Deinitovm of eNet amduMa meAnods

Applicottpn Nawne (). mann oop )

A-Vome == -mum
ZDNiNDOWS and WINpow OMpoNENTS

Mai olknowjs

He C*" by dohaulk )
void 2 hoighk (n piels)

RasigavihyTe by defaut )

o tthval atmoudks nk-ovapd ovwvid tomporoMt S plaud.


atelas
To ange Keigktdtw durung fomu ouebon.
Fasuhawe.ii (kMatgvt -200 widkn- 200, ti - "Test")

Ucong vondews athmbute dictionay


s [<otoute = vaue
a el Tboakqoumd "] ="ycllouo "

3 en4 wivow meods'


Seheackaumd (coto
set Restig aa (o Boban

szl S (ust(hwiaut )
cerTrtle (titu)

Window ouemt

*Covponends an Raid eut a oDqmd

salf eddlabel (text= "(o,0),oe= 0,esinvn - o)


| C00)
cel.cddlobe Cioct "ta)",souw=l,alvmn =1)
U)
9mnewrapped windeuo
Sttuky Afnbute stice
4 valeg N,S,E,W Mer
cowonnahv
NSE" sheteh Mall 4 dvrechins

oefaut aignnent="NW"

*Tosretch asogs mwutiple ons /wk- towmnspam obwlspam


atibute

A a

S
7pew = 2

oLo- tuumn 0
o sw3
Crwmungpemd

Types omponmtu&thelr Afibul

self.addklomponent Type>(oogiment>,
vO v s qwM e detault vaues

o twais Mstamue retms it.

Lobel rtegea iad eny) Roa at Field (enuy)


ToxtTextField () 6 Texlrea () t
ButonsPawds, Nauus, djalgcs, Salo,cawwas
Pepaying ms

u a tmg lahes
Pvom tnteu impot Photo Tmege

dapvitCcef)

dernatlalbel-Losthravrrttvt
wnqe labd - self.odlabel (text-" to-0,05umi =6,
Stcky- "NSE W

self.Amage PeboInage(tk o f ")


-

JiogsLabelLAmge" salfamage

Chomginy font-

fhen tunte mpot Font

slant= "Atah)
Hbru = fomB C feumily- "Veudoma", sige- 20

totiabel L"font "] = fnt


"
lu
teettalel " praqvamdl "1
o

OMMAND BuTTONS and FEqoNDING To EvENTS

Butfons
g e addBrutfon nekwnd
evalod (nopwmal stats-dofeutt)/diaod kate
Lu shrimg /Amage n
deplo
Fxamele:
Aags butonDemo (Fasyhrama)
daf--Amit-(s )
EosyFrawa.--nit- se)

"CCan"
self cleca Btn- sef -add Buetfow (text =

W = , tahwmn = 6)

selr. Yestre Phn =e-oddluttontectResve"


YO0=1 Cawmn = l,

stat = "disale d")

t tobs
Cuotkd Restre Drsado
cleasBhn Rstore en
Evewls thoud On chckina cuan Dicall2clac
cleou dne eontevlhO
euable Resiove
To porm Cvent Mandhng buroni comwamd ofrbue nasds to beset

wil a mekmod tall o/o a aamevts

sef.ckeu Bm = l.oddButhon (... towmand 9elf.clkan)


s .raore Bm eladheutvon ( towwomd =
el4 reslive)
ole can( sel)
sal.Jabel T"et"] tset text atmoub. > evnpy sh

sf ceerehtan ["stat" ] = "dealed" tet etekeotn 'bute


f . r e s t p r ee b n l°stede" = "nemal" " nmmal

de raera ( )
#veatove bet
sel oloel "tent"]-."l, tond #redtoe cluauBhn
scf. eta eln sfete"I "namal" =
atdhisale kastore
3el Yestrve En Letate"J "daluod = Bt

Z2 INPVT TEXT ENTRY

Cuake iowponeut salf. oddTextFTeld (.


*cpoakivs eTeut () loc widh otmbute ago
getTect C

enomple
dlas Tetfiddpevmo Ensy hrome):
d A i t - (elf):

0 Cmd vw- I ,Cd= o


a l d lapek ak 900=0, 5t=

gel inpud Field 4add "", 26U-0, cot )


letheld Clxt = -

gel.eutput keld getf .ad'Textheld (test -" d-),st-1.


State-"adonly")
tutfoM Convea wilu emmamc =SeLoyek
de tawenk e )
O
tt self. input Fld 2etTer
Yegul text uppen ()

sel-utpuutReld gct Texct rek)

input Hell
Otput HELLO

Coyat|

Numau'c nput Ted Hields - addIuteae fidd


acdd Fleat Fiedd ()

OFPAaduond tNwmber C)

setNumber ()
&ncteed o text)atmau Value

2 lop-UP DIALDG Boxr s

self. mesonpBox trte = "eRPOR",


mexs 0 g e " Frror desoiphion"

You might also like