An warware: takardun kunkuru

Hotunan kunkuru sanannen hanya ce ta gabatar da shirye-shirye ga yara. Da farko wani bangare ne na yaren shirye-shiryen Logo wanda Wally Feurzig da Seymour Papert suka tsara a cikin 1966. A Python, muna da ษ—akin karatu na kunkuru, wanda ke ba mu damar ฦ™irฦ™ira da sarrafa zanen kunkuru cikin sauฦ™i. A cikin wannan labarin, za mu bincika takardun Kunkuru, mu fahimci ayyukanta, kuma mu koyi yadda ake warware takamaiman matsala ta amfani da wannan ษ—akin karatu.

Kunkuru Library da Muhimmancinsa

The kunkuru ษ—akin karatu shine madaidaicin ษ—akin karatu na Python wanda ke ba da sauฦ™in fahimta don zana siffofi da hotuna akan zane mai kama-da-wane. Yana da amfani musamman ga masu farawa saboda yana ba su damar koyon dabarun tsara shirye-shirye a gani. Samfurin zane na kunkuru yana amfani da kunkuru, wanda shine ainihin siginan kwamfuta a cikin sifar triangle, wanda ke motsawa akan jirgin sama mai girma biyu yana bin takamaiman umarni.

Laburaren kunkuru yana ba mu damar ฦ™irฦ™irar hotuna masu rikitarwa da raye-raye, koyar da warware matsala, ฦ™ira, da yadda za a rushe manyan ayyuka zuwa ฦ™ananan matakan sarrafawa. Wasu mahimman fasali da ayyukan ษ—akin karatu na kunkuru sune:

  • Ayyukan zane mai sauฦ™i don matsawa gaba, baya, juya dama, da juya hagu.
  • Sarrafa alฦ™alamin kunkuru, gami da launi, kauri, da siffofi masu cikawa.
  • Nagartattun fasalulluka kamar kunkuru na cloning, canza siffofi, da shirye-shiryen da ke haifar da aukuwa.

Magani ga Matsala: Zana Karkace

A matsayin misali, bari mu yi tunanin muna son zana karkace ta amfani da ษ—akin karatu na kunkuru. Za mu rubuta shirin Python don ฦ™irฦ™irar wannan karkace, tafiya ta kowane mataki don fahimtar lambar da ke ciki. Maganin mu zai ฦ™unshi amfani da madaukai, ayyukan motsi na kunkuru, da sarrafa bayyanar alkalami.

import turtle

wn = turtle.Screen()
wn.bgcolor("black")

t = turtle.Turtle()
t.speed(0)
t.color("white")

def draw_spiral(t, length, angle):
    for i in range(100):
        t.forward(length)
        t.right(angle)
        length = length + 2

draw_spiral(t, 5, 89)

wn.mainloop()

Bayanin mataki-mataki na Code

Na farko, mu shigo da ษ—akin karatu na kunkuru kuma ฦ™irฦ™irar taga don nuna zane-zanenmu. Mun saita launin baya zuwa baki kuma mun ฦ™irฦ™iri wani abu kunkuru mai suna 't' tare da launin farin alฦ™alami da iyakar gudu.

import turtle

wn = turtle.Screen()
wn.bgcolor("black")

t = turtle.Turtle()
t.speed(0)
t.color("white")

Na gaba, muna ayyana aiki draw_spiral() wanda ke ษ—aukar sigogi guda uku: abin kunkuru, tsawon farkon ษ“angaren karkace, da kusurwar juyawa. A cikin wannan aikin, muna amfani da a don madauki don sake maimaita adadin matakan da ake so, motsa kunkuru gaba, juya shi, da haษ“aka tsayin sashi.

def draw_spiral(t, length, angle):
    for i in range(100):
        t.forward(length)
        t.right(angle)
        length = length + 2

A ฦ™arshe, muna kira da draw_spiral() aiki tare da abin kunkuru, tsayin farawa, da kusurwar juyawa. Daga nan sai mu fara babban madauki na taga zanen kunkuru, wanda ke nuna karkace har sai mun rufe taga.

draw_spiral(t, 5, 89)

wn.mainloop()

Wannan shirin Python yana nuna ainihin yadda ake amfani da ษ—akin karatu na kunkuru, daga kafa yanayi zuwa ayyana aiki don ฦ™irฦ™irar karkace. Gwaji tare da tsayin farko da kusurwoyi daban-daban zai haifar da sifofin karkace daban-daban.

A ฦ™arshe, ษ—akin karatu na kunkuru wani kayan aiki ne mai mahimmanci ga masu farawa da masana, suna ba da hanya mai ban sha'awa don koyo da koyar da dabarun tsara shirye-shirye. ฦ˜aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan ฦ™aฦ™ฦ™arfan fasali da ayyuka, ya sa ya zama manufa don duba hadaddun ra'ayoyi da ฦ™irฦ™irar raye-raye masu ban sha'awa.

Shafi posts:

Leave a Comment