Pendahuluan
Assalamualaikum Warrohmatullahiwabarokatuh
Pada postingan kali ini ana akan sharing tentang Turtle di Python, sebelumnya bagi yang belum mengenal Turtle Python siapa angkat tangan . :]
Yup, Turtle Python merupakan sebuah modul yang tentu saja memiliki berbagai fungsi seperti bagaimana peran modul dalam Python.
Modul Turtle ini banyak sekali fungsinya, yang akan dibahas mada pembahasan di bawah nanti.
Modul Turtle ini cocok sekali dibawakan sebagai pengantar pemrograman untuk anak untuk memicu minat siswa yang baru mengenal Programming.
Bagi kamu kami yang
ingin memulai membuat Game, tutorial ini wajib kamu baca.
Persiapan
Sebelum memulai bermain dengan Turtle kita perlu menginstall dulu Modulnya, karena tidak semua modul langsung tersedia
untuk berbagai modul Python bisa dicari di //pypi.python.org/pypi
atau langsung saja pakai cara yang ana berikan jika anda menggunakan Linux
Tentu saja anda harus mempunyai akses Internet.
Jika tidak ketemu modulnya lakukan dulu command berikut .
root # yum update [Fedora & CentOS]
root # apt update [Ubuntu & Debian Family]
Ana menggunakan Geany untuk editor nya karena menghemat waktu Eksekusi juga tidak membebani RAM dan yg terpenting support untuk compile hampir semua bahasa pemrograman.
PELAKSANAAN
Untuk Permulaan mari kita Munculkan Turtle nya
Lalu jalankan jika sudah benar maka akan terdapat tanda panah / Turtle di tengah layar Output.
Setelah itu coba kembangkan Codenya seperti Gambar Dibawah
Jika benar maka akan muncul Output Seperti ini :
Silahkan anda ulik codenya sehingga membentuk berbagai bentuk yang beragam,
mari kita lanjut ke tutor berikutnya,
pada code dibawah kan diberikan cara untuk menaruh turtle di Coordinat [CO] tertentu.
Coba anda pelajari Code di bawah
jalankan Code di atas dan lihat Outputnya,
jika benar maka akan terdapat Output Sebuah Lingkaran Merah
Apakah sudah berhasil guys ?
Mari kita tambahkan code dibawah menjadi seperti ini dan lihat Outputnya
Input :
Output :
Silahkan Code diatas sehingga teman teman dapat belajar lebih banyak.
KESIMPULAN
Ya, pada Turtle ini memungkinkan kita membuat banyak objek yang berbeda dalam satu lembar kerja dan Turtle merupakan slah satu pemrograman desktop bertipe GUI, jadi sangat cocok dipakai sebgai pengantar dalam materi Pemrograman.
QUIZ
Sebelum kita akhiri perjumpaan kiata marilaah kita sedikit memutar otak , coba buatlah turtle membentuk Objek seperti ini :
Selamat berjuang. Hamazah
REFERENSI
Prerequisite: Turtle Programming in Python
“Turtle” is a Python feature like a drawing board, which lets us command a turtle to draw all over it! ”turtle” comes packed with the standard Python package and need not be installed externally.
Step 1: Import turtle and math module in Python.
import turtle import math
Step 2: Choose a background color for your output screen. You can choose any color, we will use yellow color just to make it attractive.
screen = turtle.Screen[] screen.bgcolor["yellow"]
Step 3: Choose the color and speed of your turtle[pen] who will draw the house on the screen.
t.color["black"] t.shape["turtle"] t.speed[1]
Step 4: Now, we need to draw the base of your house and for that, you need to draw a rectangle.
You can fill any color in your of your choice just by changing the color name in the t.fillcolor[‘ ‘] command.
t.fillcolor['cyan'] t.begin_fill[ ] t.right[90] t.forward[250] t.left[90] t.forward[400] t.left[90] t.forward[250] t.left[90] t.forward[400] t.right[90] t.end_fill[]
The base of the house will look this:
//media.geeksforgeeks.org/wp-content/uploads/20200913124224/Rectangle.mp4
Step 5: Now you created the base, the next step is to create the top of the house. Draw a triangle for the upper portion, just to keep it simple.
# for creating triangle # i.e top of the house t.fillcolor['brown'] t.begin_fill[] t.right[45] t.forward[200] t.right[90] t.forward[200] t.left[180] t.forward[200] t.right[135] t.forward[259] t.right[90] t.forward[142] t.end_fill[]
Step 6: We must secure our house by Putting the Door and also windows for ventilation. Here is the code for that-
# for windows and # for creating door t.right[90] t.forward[400] t.left[90] t.forward[50] t.left[90] t.forward[150] t.right[90] t.forward[200] t.right[180] t.forward[200] t.right[90] t.forward[200] t.right[90] t.forward[150] t.right[90] t.forward[200] t.right[90] t.forward[150] t.right[90] t.forward[100] t.right[90] t.forward[150] t.right[90] t.forward[100] t.right[90] t.forward[75] t.right[90] t.forward[200]
Complete Code:
Python3
import
turtle
t
=
turtle.Turtle[]
screen
=
turtle.Screen[]
screen.bgcolor[
"yellow"
]
t.color[
"black"
]
t.shape[
"turtle"
]
t.speed[
1
]
t.fillcolor[
'cyan'
]
t.begin_fill[]
t.right[
90
]
t.forward[
250
]
t.left[
90
]
t.forward[
400
]
t.left[
90
]
t.forward[
250
]
t.left[
90
]
t.forward[
400
]
t.right[
90
]
t.end_fill[]
t.fillcolor[
'brown'
]
t.begin_fill[]
t.right[
45
]
t.forward[
200
]
t.right[
90
]
t.forward[
200
]
t.left[
180
]
t.forward[
200
]
t.right[
135
]
t.forward[
259
]
t.right[
90
]
t.forward[
142
]
t.end_fill[]
t.right[
90
]
t.forward[
400
]
t.left[
90
]
t.forward[
50
]
t.left[
90
]
t.forward[
150
]
t.right[
90
]
t.forward[
200
]
t.right[
180
]
t.forward[
200
]
t.right[
90
]
t.forward[
200
]
t.right[
90
]
t.forward[
150
]
t.right[
90
]
t.forward[
200
]
t.right[
90
]
t.forward[
150
]
t.right[
90
]
t.forward[
100
]
t.right[
90
]
t.forward[
150
]
t.right[
90
]
t.forward[
100
]
t.right[
90
]
t.forward[
75
]
t.right[
90
]
t.forward[
200
]
t.right[
180
]
t.forward[
200
]
t.right[
90
]
t.forward[
75
]
t.left[
90
]
t.forward[
15
]
t.left[
90
]
t.forward[
200
]
t.right[
90
]
t.forward[
15
]
t.right[
90
]
t.forward[
75
]
Output:
//media.geeksforgeeks.org/wp-content/uploads/20200913125802/House.mp4