Oliy va o’rta mahsus ta’lim vazirligi namangan davlat universiteti gulshod yunusova


Pythonda ko’p burchakni akslantirish uchun


Download 5.84 Mb.
bet26/40
Sana15.09.2023
Hajmi5.84 Mb.
#1678635
1   ...   22   23   24   25   26   27   28   29   ...   40
Bog'liq
python 1 qism дарслик Г.Юнусова (1)

Pythonda ko’p burchakni akslantirish uchun quyidagi protsedura obj = Polygon(Point(x1, y1), Point(x2, y2),…, Point(xn, yn)) protsedura qo’llaniladi
x1, y1, x2, y2,…, xn, yn – ko’pburchakning uchlari koordinatalari.
Pyhonda beshburchakni grafik oynada akslantiruvchi from graphics import *
win = GraphWin("Окно для графики", 400, 400)
obj = Polygon(Point(10, 10), Point(300, 50), Point(200, 300), Point(150,
150), Point(70, 70))
obj.draw(win) win.getMouse() win.close()

Pythonda grafik ob’ektni bo’yashning rangini aniqlash


Pythonda grafik ob’ektni bo’yash quyidagi obj.setFill("rang") buyruq qo’llaniladi


Bo’yalgan ko’k aylanani chizuvchi pythondagi dasturga misol.


from graphics import *


win = GraphWin("Окнодляграфики", 400, 400)

100
obj = Circle(Point(200, 200), 50) obj.setFill("blue")


obj.draw(win) win.getMouse() win.close()
Pythonda ob’ektlar chegaralarinin tahrirlash uchun quyidagi prtseduradan foydalaniladi setOutline(“chegara rangi”)va setWidth(chegara kengligi).
obj.setOutline("blue") – obj ob’ekt chegara bilan ko’k rangda akslanadi. obj.setWidth(5) – объект obj ob’ekt 5 piksel chegara kengligi bilaan akslanadi. avtomatik tarzda Поумолчаниюграфическийобъектв Pythonda ob’ekt qora rangli chegaralar bilan 1 piksel kengligida akslanadi. Pythonda grafik oynada ko’k rangli chegarali figurani aslantirishga misol.
from graphics import *
win = GraphWin("grafika uchun oyna", 310, 310)
obj = Polygon(Point(10, 10), Point(300, 50), Point(200, 300), Point(150, 150),
Point(70, 70)) obj.setOutline("blue") obj.setWidth(5) obj.setFill("cyan") obj.draw(win) win.getMouse() win.close()

101



Pythonga grafik ob’ektni kuchirsak, quyidagi protsedura
qo’llaniladi: move(dx, dy), u o’z nabatida ob’ektni dx pikselga o’nga va dy pikselga pastga suradi.
obj.move(50, 50) obj ob’ektni 50 pikselga o’nga va 50 pikselga pastga suradi. Ob’ektlarni klonlashtirish uchun quyidagi clone() protsedurasi qo’llaniladi newObj = obj.clone()
bu buyruq orqali yangi grafik ob’ekt yaratiladi newObj, u o'znavbatida и obj ob’ektiga o’hshash.
ekrandan figuralarni uchirish uchun undraw() rotsdurasi qo’llaniladi.ob’ekt grafik ynadan uchiriladi lekin hotiradan olib tashlanmaydi.
obj.undraw()

Download 5.84 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   ...   40




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling