Seorang programmer pemula biasanya lebih suka mempelajari hal-hal yang berbau grafik di awal-awal dia belajar bahasa pemrograman, termasuk saya. Ada banyak cara bagaimana menuliskan program grafik di Python, salah satunya menggunakan modul Show { 1 } Aktifkan Python di mode
{ 2 } Ketikkan perintah untuk menampilkan lokasi terkini dan arah dari si kura-kura.
Pemrograman grafik menggunakan modul { 3 } Ketikkan perintah berikut untuk menggambar sebuah teks.
{ 4 } Ketikkan perintah berikut untuk menggerakkan mata panah maju sejauh 100 piksel dalam bentuk garis.
{ 5 } Ketikkan perintah berikut untuk membelokkan arah ke kanan 90 derajat, mengubah warna garis menjadi merah, dan membuat garis sepanjang 50 pixel arah lurus ke depan.
{ 6 } Sekarang, kita buat perintah agar mata panah berbelok ke kanan 90 derajat, mengubahnya menjadi warna hijau, dan bergerak maju membuat garis sepanjang 100 piksel.
{ 7 } Dan akhirnya, kita buat perintah berputar ke kanan 45 derajat, dan membuat garis lurus sepanjang 80 piksel.
{ 8 } Kita tutup jendela Turtle dan keluar dari Python. Mudah bukan? So…Tunggu artikel selanjutnya tentang Turtle Python…tentunya di website kesayangan kita ini http://www.KlinikPython.wordpress.com In this Python tutorial, we will learn How to create colors in Python Turtle and we will also cover different examples related to Turtle colors. And, we will cover these topics.
Table of Contents Python turtle colorIn this section, we will learn about how to create colors in Python Turtle. Turtle is a feature of Python in which we can draw various shapes and also fill colors in between these shapes. Turtle is working as a drawing board and we can also create classes and define functions. Code: In the following code, we generate some colors such as “green”, “pink” we fill these colors to make output attractive.
Output: After running the above code we get the following output we see the cursor move forward with green color and make the triangle and fill the triangle with pink color. Read: How to draw a shape in python using Turtle Python turtle colors RGBIn this section, we will learn how to create RCB colors in Python turtle. As we know turtle is a feature used in Python is used as a drawing board we can draw any shape of any color in this. We create an RCB color to make a shape. Code: in the following code, we import the turtle package as import turtle and give the turtle shape to the cursor and also give the pen color as “RGB”.
Output: In the following output, we see a square is created with three beautiful colors “RGB”. Black is the default color. Read: Draw colored filled shapes using Python Turtle Python turtle colors fillIn this section, we will learn how to fill the colors in Python turtle. Python turtle has some function for moving the turtle i.e forward(), backward() and there are fill functions also for filling the shape choose the color and fill the shape i.e fillcolor(). Code: In the following code, we creating a turtle pen for drawing the hexagonal shape. And also set the fill color that filled in a hexagonal shape.
Output: After running the above code we get the following output in which we see a hexagon is filled with yellow color. Read: How to Create a Snake game in Python using Turtle Python turtle color chartIn this section, we will learn how to create a color chart in Python turtle. The chart is defined as giving information in the form of a graph or table. Color char is used for giving the information different colors that are filled inside the chart. Code: In the following code, we import the turtle package as import turtle and define the function that draws the turtle as def drawbar(tur, height, color): we create a bar chart and filled this bar with color.
Output: In the following output, we create a bar chart, and this bar chart is filled with different colors shows the color chart. Read: Python Turtle Commands Python turtle color codesIn this section, we will learn how to create color code in Python turtle. Color code works on a different platform to provide a beautiful frontend for user sight which helps us to make the view pages user-friendly. Code: In the following code, we import the package as import turtle and give the color to the turtle when the turtle moves the color change to green and then change to red and we mention these colors in the form of code also. turtle.forward(50) is used to move forward direction.
Output: In the following output, we see there is a turtle with the default color black, and then the turtle moves in the forward direction with different beautiful colors. Read: How to attach an image in Turtle Python turtle color randomIn this section, we will learn how to generate random colors in Python turtle. Random color is defined as taking some color randomly without using any function. The color is generated randomly which gives the beautiful look to the screen. Code: In the following code, we import the module from random import randint for generating random colors which attract the viewer’s eyes.
Output: After running the above code, we get the following output in which we see some random circle is generated which looks very pretty. Read: Matplotlib change background color Python turtle color gradientIn this section, we will learn about how to create color gradients in Python turtle. Color gradient identifies a range of positions in which the color is used to fill the region. The gradient is also known as a continuous color map. Code: In the following code, we define some colors and set a target we also create a screen and give width and height in which the color gradient identifies the range of position in which the color is used to fill the region.
Output: In the following output, we see different colors are shown on the screen as a continuous color map. Read: Python Tkinter Colors Python turtle color changeIn this section, we will learn how to change the color of the Python turtle. We change the color of the things to give an attractive look. In turtle, we change the color by pencolor() it changes the color of the ink of the turtle and the default color is black. Code: In the following code, we know the default color of the turtle is black we change the turtle color black to “purple”.
Output: After running the above code, we get the following output in which we see the arrow move forward they have the default color black and after in few seconds, the color changes into purple. You may like the following Python tutorials:
So, in this tutorial, we discussed Python turtle colors and we have also covered different examples related to its implementation. Here is the list of examples that we have covered.
Bijay Kumar Python is one of the most popular languages in the United States of America. I have been working with Python for a long time and I have expertise in working with various libraries on Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… I have experience in working with various clients in countries like United States, Canada, United Kingdom, Australia, New Zealand, etc. Check out my profile. |