Thursday 11 April 2024

Yellow Heart using Python ♥

 


Code : 

import turtle

t = turtle.Turtle()

t.shapesize(0.2, 0.2)

s = turtle.Screen()

s.bgcolor('black')


t.fillcolor("yellow")

t.begin_fill()


t.left(50)

t.forward(240)  

t.circle(90, 200)  

t.left(221)

t.circle(90, 200)  

t.forward(260)  


t.end_fill()


turtle.done()

#clcoding.com

Explanation: 

This code utilizes the Turtle module in Python to create a graphic using turtle graphics. Let's break down each part of the code:

import turtle: This line imports the Turtle module, which provides a drawing canvas and various methods for creating graphics using turtle graphics.

t = turtle.Turtle(): This creates a turtle object named t. The turtle object represents a turtle that can move around the screen and draw lines and shapes.

t.shapesize(0.2, 0.2): This line sets the size of the turtle shape. The parameters 0.2, 0.2 specify that the turtle's shape should be scaled to 20% of its default size in both the x and y directions.

s = turtle.Screen(): This creates a screen object named s. The screen object represents the window or canvas where the turtle will draw.

s.bgcolor('black'): This sets the background color of the screen to black.

t.fillcolor("yellow"): This sets the fill color of the turtle to yellow.

t.begin_fill(): This marks the beginning of a shape that will be filled with the fill color.

t.left(50): This turns the turtle left by 50 degrees.

t.forward(240): This moves the turtle forward by 240 units.

t.circle(90, 200): This draws a partial circle with a radius of 90 units and an extent of 200 degrees. This creates a curved shape.

t.left(221): This turns the turtle left by 221 degrees.

t.circle(90, 200): This draws another partial circle similar to the previous one.

t.forward(260): This moves the turtle forward by 260 units.

t.end_fill(): This marks the end of the shape to be filled and fills the shape with the specified fill color.

turtle.done(): This keeps the window open after the drawing is complete until the user closes it manually.

This code creates a graphic consisting of two curved shapes filled with yellow color on a black background.

0 Comments:

Post a Comment

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (115) C (77) C# (12) C++ (82) Course (62) Coursera (179) coursewra (1) Cybersecurity (22) data management (11) Data Science (91) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (747) Python Coding Challenge (208) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses