Tuesday, March 19, 2024

Blink Your Name in Different Colors - Python Program

 import turtle

import time


# Create a turtle object

t = turtle.Turtle()


# Set turtle speed

t.speed(0)


# Define colors

colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]


# Set starting position

x, y = -200, 0


# Function to toggle colors

def toggle_colors():

    for color in colors:

        t.clear()

        t.penup()

        t.goto(x, y)

        t.pendown()

        t.color(color)

        t.write("raja", font=("Arial", 100, "bold"))

        time.sleep(0.5)  # Delay for 0.5 seconds


# Blink the text in different colors

while True:

    toggle_colors()


Monday, March 18, 2024

Draw a Graphical Heart Program in Python

 Below is a Python code using the turtle module to draw a heart shape graphically:


import turtle


# Set up the screen

screen = turtle.Screen()

screen.setup(width=600, height=600)

screen.bgcolor("white")


# Create a turtle object

heart = turtle.Turtle()

heart.speed(0)

heart.color("red")

heart.fillcolor("red")

heart.begin_fill()


# Draw the heart shape

heart.left(140)

heart.forward(180)

for i in range(200):

    heart.right(1)

    heart.forward(2)

heart.left(120)

for i in range(200):

    heart.right(1)

    heart.forward(2)

heart.forward(180)


# Fill the heart with color

heart.end_fill()


# Hide the turtle

heart.hideturtle()


# Keep the window open

turtle.done()



===========
When you run this code, a window will appear displaying a graphical representation of a heart shape drawn using the turtle graphics library in Python. You can adjust the window size and heart shape by modifying the parameters in the screen.setup() function and the heart drawing commands.