Thursday, 8 October 2026

๐Ÿ”ฅ Python Turtle The Slow Neon Fire Flower


 


Code:

import turtle import math import time screen = turtle.Screen() screen.setup(700, 700) screen.bgcolor("#050008") screen.tracer(0) t = turtle.Turtle() t.hideturtle() t.speed(0) t.width(3) colors = ["#ff1744", "#ff6d00", "#ffea00", "#ff00aa", "#d500f9"] for layer in range(16): t.color(colors[layer % len(colors)]) scale = 1 + layer * 0.055 for petal in range(10): angle = petal * 36 + layer * 1.5 t.penup() for i in range(81): a = math.radians(i * 4.5) r = 25 + 135 * math.sin(a) ** 2 r *= (1 + 0.35 * math.sin(a * 2)) x = r * math.cos(a) y = r * math.sin(a) rot = math.radians(angle) X = x * math.cos(rot) - y * math.sin(rot) Y = x * math.sin(rot) + y * math.cos(rot) X *= scale Y *= scale t.goto(X, Y) if i == 0: t.pendown() # ๐Ÿข Slow live drawing screen.update() time.sleep(0.015) time.sleep(0.15) # ✨ Slow glowing center for r in range(35, 2, -3): t.penup() t.goto(0, -r) t.dot(r, "#ffea00") screen.update() time.sleep(0.12) t.penup() t.goto(0, -7) t.dot(12, "white") turtle.done()import turtle import math import time screen = turtle.Screen() screen.setup(700, 700) screen.bgcolor("#050008") screen.tracer(0) t = turtle.Turtle() t.hideturtle() t.speed(0) t.width(3) colors = ["#ff1744", "#ff6d00", "#ffea00", "#ff00aa", "#d500f9"] for layer in range(16): t.color(colors[layer % len(colors)]) scale = 1 + layer * 0.055 for petal in range(10): angle = petal * 36 + layer * 1.5 t.penup() for i in range(81): a = math.radians(i * 4.5) r = 25 + 135 * math.sin(a) ** 2 r *= (1 + 0.35 * math.sin(a * 2)) x = r * math.cos(a) y = r * math.sin(a) rot = math.radians(angle) X = x * math.cos(rot) - y * math.sin(rot) Y = x * math.sin(rot) + y * math.cos(rot) X *= scale Y *= scale t.goto(X, Y) if i == 0: t.pendown() # ๐Ÿข Slow live drawing screen.update() time.sleep(0.015) time.sleep(0.15) # ✨ Slow glowing center for r in range(35, 2, -3): t.penup() t.goto(0, -r) t.dot(r, "#ffea00") screen.update() time.sleep(0.12) t.penup() t.goto(0, -7) t.dot(12, "white") turtle.done()















































Explanation:

1. Import Libraries
import turtleimport mathimport time


- turtle → draws the flower.
- math → performs trigonometric calculations.
- time → controls the slow animation.

2. Create the Screen
screen = turtle.Screen()screen.setup(700, 700)screen.bgcolor("#050008")screen.tracer(0)

- Creates a 700×700 window.
- Sets a dark purple-black background.
- tracer(0) gives manual control over screen updates.

3. Configure the Turtle
t = turtle.Turtle()t.hideturtle()t.speed(0)t.width(3)

- Creates the drawing turtle.
- Hides the turtle cursor.
- speed(0) gives maximum drawing speed.
- width(3) creates bold lines.

4. Define Neon Colors
colors = ["#ff1744", "#ff6d00", "#ffea00", "#ff00aa", "#d500f9"]

- Creates a palette of red, orange, yellow, pink, and purple.
- These colors are used for different layers.

5. Create Flower Layers
for layer in range(16):

- Creates 16 flower layers.
- Each layer makes the flower larger and slightly rotated.

6. Select Layer Color
t.color(colors[layer % len(colors)])

- Selects a color from the list.
- % makes the colors repeat automatically.

7. Increase Layer Size
scale = 1 + layer * 0.055

- Gradually increases the size of every layer.
- Creates the expanding flower effect.

8. Create 10 Petals
for petal in range(10):


- Creates 10 petals around each layer.

9. Calculate Petal Angle
angle = petal * 36 + layer * 1.5


- 36° separates the 10 petals evenly.
- layer * 1.5 slightly rotates each new layer.

10. Lift the Pen
t.penup()


- Prevents unwanted lines while moving to the starting point.

11. Generate Petal Points
for i in range(81):

- Generates 81 points for each petal.
- More points make the curves smoother.

12. Calculate the Curve Angle
a = math.radians(i * 4.5)

- Converts the current angle into radians.
- 4.5° × 80 = 360°, creating a complete curve.

13. Calculate the Petal Radius
r = 25 + 135 * math.sin(a) ** 2

- Calculates the distance from the center.
- The sine function creates the petal shape.

14. Add Extra Petal Distortion
r *= (1 + 0.35 * math.sin(a * 2))
- Adds another sine wave to the radius.
- Makes the petals more curved and organic.

15. Calculate X Coordinate
x = r * math.cos(a)
- Converts the radius and angle into the X position.

16. Calculate Y Coordinate
y = r * math.sin(a)
- Calculates the Y position.
- Together, x and y create the petal curve.

17. Convert Petal Angle
rot = math.radians(angle)
- Converts the petal rotation from degrees to radians.

18. Rotate X Coordinate
X = x * math.cos(rot) - y * math.sin(rot)
- Rotates the X position around the center.

19. Rotate Y Coordinate
Y = x * math.sin(rot) + y * math.cos(rot)
- Rotates the Y position.
- Together, these two formulas position each petal around the flower.

20. Apply Layer Scaling
X *= scaleY *= scale
- Enlarges the coordinates according to the current layer.
- Creates the layered bloom effect.

21. Move to the Point
t.goto(X, Y)
- Moves the turtle to the calculated position.

22. Start Drawing the Petal
if i == 0:    t.pendown()

- The first point starts the drawing.
- Subsequent points connect to create the petal curve.

23. Animate the Drawing
screen.update()time.sleep(0.015)

- Updates the screen after every point.
- 0.015 seconds creates a slow live-drawing effect.
24. Pause After Each Petal
time.sleep(0.15)


- Adds a noticeable pause after each petal.
- Makes the flower build up slowly.

25. Create the Glowing Center
for r in range(35, 2, -3):

- Creates multiple circles.
- The radius decreases from 35 to 3.
t.penup()t.goto(0, -r)t.dot(r, "#ffea00")

- Moves to the center.
- Draws yellow circles of decreasing size.
- Creates a glowing center.

26. Animate the Glow
screen.update()time.sleep(0.12)

- Updates each glow layer.
- Creates a slow glowing effect.

27. Add White Core
t.penup()t.goto(0, -7)t.dot(12, "white")

- Adds a bright white dot at the center.
- Creates a strong highlight.

28. Finish the Drawing
turtle.done()

- Keeps the Turtle window open.



Python Coding Challenge - Question with Answer (ID 081026)

 




Explanation:

๐ŸŸข Step 1: Understand the String
"12"


String ke indexes:
Index:   0   1
Value:  '1' '2'

So:
"12"[0]


means index 0 ka character:
"12"[0] → "1"

๐ŸŸก Step 2: Understand "12"[1]
"12"[1]


Index 1 par character hai:
"12"[1] → "2"

⚠️ Dhyaan rahe: ye "2" string hai, integer 2 nahi.

๐Ÿ”ต Step 3: Convert "2" to Integer
Code:
int("12"[1])


Pehle:
"12"[1] → "2"

Then:
int("2")


becomes:
2

So:
int("12"[1]) → 2

๐ŸŸฃ Step 4: String Multiplication
Ab original expression:
"12"[0] * int("12"[1])


Values substitute karo:
"1" * 2

Python mein string ko integer se multiply karne par string repeat hoti hai:
"1" * 2
→ "11"


๐ŸŽฏ Step 5: print()
Therefore:
print("11")


✅ Final Output
11

Wednesday, 7 October 2026

๐Ÿ Python Pattern Challenge — Day 21

 



๐Ÿ Python Pattern Challenge — Day 21

Pattern printing is a great way to strengthen your Python loops, repetition, and logical thinking. For Day 21, let's keep things simple with a Growing Star Triangle ⭐.

๐ŸŽฏ Today's Challenge

Write a Python program to print exactly this pattern:


Can you create it with the cleanest Python code? ๐Ÿ†


Solution 1 — Using a for Loop

for i in range(1, 11): print("* " * i)




How it works

The loop runs from 1 to 10.

On every iteration, i determines how many stars are printed:

"* " * i

So the number of stars increases row by row.


Solution 2 — Using a while Loop

i = 1 while i <= 10: print("* " * i) i += 1





Here, i starts at 1 and increases after every row until it reaches 10.


Solution 3 — Using a Function

def star_pattern(n): for i in range(1, n + 1): print("* " * i) star_pattern(10)





The function makes the pattern reusable.

For example:

star_pattern(5)

will create a smaller triangle.


⚡ Short & Clean Code

for i in range(1, 11): print("* " * i)





๐Ÿ”ฅ One line is enough to generate the complete pattern!


๐Ÿš€ Challenge Yourself

Can you modify this pattern:

  • Take the number of rows using input()?
  • Print the pattern in reverse?
  • Replace * with # or another character?
  • Create the same pattern using nested loops?
  • Make the triangle hollow?

Drop your solution below! ๐Ÿ‘‡

21 Days. 21 Patterns. Stronger Python Logic. ๐Ÿ๐Ÿ”ฅ

Learn • Practice • Grow with CLCODING ๐Ÿš€



107 Pattern Plots Using Python

✨ Python Turtle The 3D Ribbon Bloom

 

Code:

import turtle import math import time screen = turtle.Screen() screen.setup(700, 700) screen.bgcolor("#020208") t = turtle.Turtle() t.hideturtle() t.speed(0) t.width(3) colors = [ "#ff1744", "#ff2d75", "#d500f9", "#7c4dff", "#00e5ff", "#00ff9d" ] for layer in range(14): t.color(colors[layer % len(colors)]) for i in range(180): a = math.radians(i * 2) # Flower ribbon curve r = 90 + 85 * math.sin(5 * a + layer * 0.25) x = r * math.cos(a) y = r * math.sin(a) # Slight 3D rotation rot = math.radians(layer * 4) X = x * math.cos(rot) - y * math.sin(rot) Y = x * math.sin(rot) + y * math.cos(rot) if i == 0: t.penup() t.goto(X, Y) t.pendown() else: t.goto(X, Y) screen.update() time.sleep(0.002) time.sleep(0.08) # ✨ Bold glowing center for r in range(30, 2, -3): t.penup() t.goto(0, -r) t.dot(r, colors[r % len(colors)]) screen.update() time.sleep(0.06) t.penup() t.goto(0, -5) t.dot(9, "white") turtle.done()





















Explanation:

1. Import Libraries

import turtleimport mathimport time

- turtle → draws the flower.

- math → handles angles and trigonometry.

- time → adds animation delays.


2. Create the Screen

screen = turtle.Screen()screen.setup(700, 700)screen.bgcolor("#020208")

- Creates a 700×700 window.

- Sets a very dark background.


3. Configure the Turtle

t = turtle.Turtle()t.hideturtle()t.speed(0)t.width(3)

- Creates the drawing turtle.

- Hides the turtle cursor.

- speed(0) gives maximum drawing speed.

- width(3) makes the lines bold.


4. Define Neon Colors

colors = [    "#ff1744", "#ff2d75",    "#d500f9", "#7c4dff",    "#00e5ff", "#00ff9d"]

- Creates a palette of six neon colors.

- These colors are used for different flower layers.


5. Create Flower Layers

for layer in range(14):

- Creates 14 overlapping flower ribbons.

- Each layer has a slightly different rotation and phase.


6. Select Layer Color

t.color(colors[layer % len(colors)])

- Selects a color from the list.

- % makes the colors repeat after reaching the last color.


7. Generate Curve Points

for i in range(180):

- Creates 180 points for each flower ribbon.

- More points make the curve smoother.


8. Calculate the Angle

a = math.radians(i * 2)

- Converts the angle from degrees to radians.

- The angle increases as the loop progresses.


9. Create the Flower Ribbon Curve

r = 90 + 85 * math.sin(5 * a + layer * 0.25)

- Calculates the changing radius.

- sin() creates the petal-like wave.

- 5 * a produces five major flower lobes.

- layer * 0.25 shifts each layer slightly.


10. Calculate X Coordinate

x = r * math.cos(a)

- Converts the radius and angle into the X position.


11. Calculate Y Coordinate

y = r * math.sin(a)

- Calculates the Y position.

- Together, x and y create the flower curve.


12. Calculate 3D Rotation

rot = math.radians(layer * 4)

- Gives every layer a slightly different rotation.

- Creates a 3D/orbital appearance.


13. Rotate X and Y Coordinates

X = x * math.cos(rot) - y * math.sin(rot)Y = x * math.sin(rot) + y * math.cos(rot)

- Applies a mathematical rotation transformation.

- Produces the twisted ribbon effect.


14. Start Drawing the Layer

if i == 0:    t.penup()    t.goto(X, Y)    t.pendown()

- For the first point, the turtle moves without drawing.

- Then it puts the pen down to start the curve.


15. Connect the Points

else:

    t.goto(X, Y)

- Connects every calculated point.

- This forms the complete flower ribbon.


16. Animate the Drawing

screen.update()time.sleep(0.002)

- Updates the screen after each point.

- Adds a tiny delay for the drawing animation.


17. Pause Between Layers

time.sleep(0.08)

- Adds a short pause after completing each ribbon.

- Makes the layer-by-layer effect visible.


18. Create the Glowing Center

for r in range(30, 2, -3):

- Creates multiple circles.

- Radius decreases from 30 to 3.

t.penup()t.goto(0, -r)t.dot(r, colors[r % len(colors)])

- Moves to the center area.

- Draws colorful dots of different sizes.

- Together they create a glowing center.


19. Animate the Center Glow

screen.update()time.sleep(0.06)

- Updates the screen.

- Slows down the center-glow animation.


20. Add White Core

t.penup()t.goto(0, -5)t.dot(9, "white")

- Adds a small white dot.

- Creates a bright core/highlight in the center.


21. Finish the Drawing

turtle.done()

- Keeps the Turtle window open.



Popular Posts

Categories

100 Python Programs for Beginner (119) AI (363) Android (25) AngularJS (1) API (2) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (359) Bootcamp (20) C (78) C# (12) C++ (83) cloud (1) Course (97) Coursera (307) Cybersecurity (38) data (11) Data Analysis (48) Data Analytics (32) data management (17) Data Science (449) Data Strucures (22) Deep Learning (229) Django (17) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Gadgets (2) Generative AI (80) Git (14) Google (55) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (421) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (36) Python (1417) Python Bug (1) Python Coding Challenge (1321) Python Library (29) Python Mathematics (25) Python Mistakes (51) Python Pattern Challenge (51) Python Quiz (704) Python Tips (115) Python Turtle (3) Questions (3) R (72) React (7) Scripting (3) security (5) Selenium Webdriver (4) Software (21) SQL (57) Udemy (24) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)