From fd6fce75ee01b82361ca22b49f3881899cb65a20 Mon Sep 17 00:00:00 2001
From: himanshus0764 <himanshu.s6487@gmail.com>
Date: Sun, 3 Nov 2024 15:29:42 +0530
Subject: [PATCH 1/4] here i upload a fractal art code in python

---
 Fractal_art/Readme.md       | 47 ++++++++++++++++++
 Fractal_art/fractal_code.py | 95 +++++++++++++++++++++++++++++++++++++
 README.md                   |  2 +
 3 files changed, 144 insertions(+)
 create mode 100644 Fractal_art/Readme.md
 create mode 100644 Fractal_art/fractal_code.py

diff --git a/Fractal_art/Readme.md b/Fractal_art/Readme.md
new file mode 100644
index 00000000..81500abb
--- /dev/null
+++ b/Fractal_art/Readme.md
@@ -0,0 +1,47 @@
+Here’s a simple `README.md` file for your fractal drawing project. You can copy and paste this directly into a file named `README.md` in your project directory.
+
+```markdown
+# Fractal Drawing with Turtle Graphics
+
+This project generates fractals using Python's Turtle Graphics and an L-System (Lindenmayer System).
+
+## Features
+- Generates fractal patterns based on defined production rules.
+- Customizable parameters for axiom, iterations, and angles.
+
+## Installation
+
+1. install pygame library by "pip install pygame"
+
+## Usage
+
+1. Clone this repository or download the files.
+2. Open the `fractal_drawing.py` file in your preferred text editor or IDE.
+3. Run the script using Python:
+   ```bash
+   python fractal_drawing.py
+   ```
+
+## Code Overview
+
+- **Production Rules**: Defines how the initial axiom transforms over iterations.
+- **apply_rules()**: Applies the defined rules to generate the final string.
+- **draw_fractal()**: Interprets the final string and draws the fractal using turtle graphics.
+
+## Configuration
+
+Modify the following parameters in the `main()` function to change the fractal's appearance:
+- **Axiom**: Initial string (e.g., `'VZFFF'`).
+- **Iterations**: Number of times to apply the production rules (e.g., `12`).
+- **Angle**: Angle for turtle turns (e.g., `30` degrees).
+
+## Example Output
+
+Running the script generates a fractal pattern that visually represents branching structures.
+
+## License
+
+This project is open-source. Feel free to modify and use it as you wish!
+```
+
+Feel free to adjust any section to better fit your needs or to add more information as you see fit!
\ No newline at end of file
diff --git a/Fractal_art/fractal_code.py b/Fractal_art/fractal_code.py
new file mode 100644
index 00000000..eb303f63
--- /dev/null
+++ b/Fractal_art/fractal_code.py
@@ -0,0 +1,95 @@
+import pygame
+import math
+
+# Constants
+SCREEN_WIDTH = 1920
+SCREEN_HEIGHT = 1080
+MAX_DEPTH = 6  # Maximum iterations for the L-system
+MIN_DEPTH = 1   # Minimum iterations for the L-system
+TREE_SPACING = 100  # Spacing between trees
+TREE_COUNT = 1  # Number of trees
+ANGLE = math.pi / 2  # 90 degrees
+
+# Function to calculate the fractal dimension D2
+def calculate_fractal_dimension(gamma):
+    return 2.0 - gamma
+
+# Function to generate the L-system string
+def generate_l_system(axiom, rules, iterations):
+    current_string = axiom
+    for _ in range(iterations):
+        next_string = ""
+        for char in current_string:
+            next_string += rules.get(char, char)
+        current_string = next_string
+    return current_string
+
+# Function to draw the fractal based on the L-system string
+def draw_fractal_l_system(surface, l_system_string, start_x, start_y, length, angle):
+    stack = []
+    x, y = start_x, start_y
+    for command in l_system_string:
+        if command == 'F':
+            # Calculate new branch endpoint
+            x_new = x + length * math.cos(angle)
+            y_new = y + length * math.sin(angle)
+
+            # Draw the branch
+            pygame.draw.line(surface, (255, 255, 255), (x, y), (x_new, y_new), 1)
+            x, y = x_new, y_new
+        elif command == '+':
+            angle += ANGLE  # Turn right
+        elif command == '-':
+            angle -= ANGLE  # Turn left
+        elif command == '[':
+            stack.append((x, y, angle))  # Save current position and angle
+        elif command == ']':
+            x, y, angle = stack.pop()  # Restore last position and angle
+
+def main():
+    # Initialize Pygame
+    pygame.init()
+    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
+    pygame.display.set_caption("Fractal Trees with Pygame (L-System)")
+
+    clock = pygame.time.Clock()
+    axiom = "F+F+F+F"
+    rules = {'F': "F+F-F+F+F"}  # Production rule
+    iterations = 4  # Initial number of iterations for L-system
+    length = 7.0  # Length of each branch
+
+    running = True
+    while running:
+        for event in pygame.event.get():
+            if event.type == pygame.QUIT:
+                running = False
+
+            # Adjust depth with key events
+            if event.type == pygame.KEYDOWN:
+                if event.key == pygame.K_k and iterations < MAX_DEPTH:
+                    iterations += 1  # Increase iterations
+                if event.key == pygame.K_j and iterations > MIN_DEPTH:
+                    iterations -= 1  # Decrease iterations
+
+        # Generate the L-system string based on the current number of iterations
+        l_system_string = generate_l_system(axiom, rules, iterations)  # Generate L-system string
+
+        screen.fill((0, 0, 0))  # Set background color to black
+
+        # Draw the L-system fractal tree
+        start_x = SCREEN_WIDTH / 2
+        start_y = SCREEN_HEIGHT - 50  # Y position for tree base
+        draw_fractal_l_system(screen, l_system_string, start_x, start_y, length, -math.pi / 2)
+
+        # Display the current depth on screen
+        font = pygame.font.Font(None, 36)
+        text = font.render(f"Iterations (Press K/J to change): {iterations}", True, (255, 255, 255))
+        screen.blit(text, (10, 10))
+
+        pygame.display.flip()
+        clock.tick(120)
+
+    pygame.quit()
+
+if __name__ == "__main__":
+    main()
diff --git a/README.md b/README.md
index e86d05e7..8e63c06e 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,8 @@ This repository has the following Projects.
 - [pokemone_battle](https://github.com/Shahrayar123/Python-Projects/tree/master/pokemone_battle.py)
 - [Text-to-Speech](https://github.com/Shahrayar123/Python-Projects/tree/master/Text-to-Speech)
 
+### Other art code python 
+- [Fractal_art](https://github.com/Shahrayar123/Python-Projects/tree/master/Fractal_art)
 
 ## Contribution
 

From 8d6df5e2fd69853afc6725e838dbd8e791e3a01d Mon Sep 17 00:00:00 2001
From: himanshus0764 <himanshu.s6487@gmail.com>
Date: Sun, 3 Nov 2024 15:35:50 +0530
Subject: [PATCH 2/4] rewrite a readme.md

---
 README.md | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 8e63c06e..2eba1b3b 100644
--- a/README.md
+++ b/README.md
@@ -46,9 +46,7 @@ This repository has the following Projects.
 - [Youtube Searching Script](https://github.com/Shahrayar123/Python-Projects/tree/master/Youtube%20Searching%20Script)
 - [pokemone_battle](https://github.com/Shahrayar123/Python-Projects/tree/master/pokemone_battle.py)
 - [Text-to-Speech](https://github.com/Shahrayar123/Python-Projects/tree/master/Text-to-Speech)
-
-### Other art code python 
-- [Fractal_art](https://github.com/Shahrayar123/Python-Projects/tree/master/Fractal_art)
+- [Fractal_art](https://github.com/himanshus0764/Python-Projects/tree/master/Fractal_art)
 
 ## Contribution
 

From 9b4c2efa92fe1f8fd2f18ad53027080bd6c06a24 Mon Sep 17 00:00:00 2001
From: himanshus0764 <152205558+himanshus0764@users.noreply.github.com>
Date: Sat, 9 Nov 2024 16:31:18 +0530
Subject: [PATCH 3/4] Update Readme.md

---
 Fractal_art/Readme.md | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Fractal_art/Readme.md b/Fractal_art/Readme.md
index 81500abb..57a84a77 100644
--- a/Fractal_art/Readme.md
+++ b/Fractal_art/Readme.md
@@ -1,5 +1,3 @@
-Here’s a simple `README.md` file for your fractal drawing project. You can copy and paste this directly into a file named `README.md` in your project directory.
-
 ```markdown
 # Fractal Drawing with Turtle Graphics
 
@@ -44,4 +42,4 @@ Running the script generates a fractal pattern that visually represents branchin
 This project is open-source. Feel free to modify and use it as you wish!
 ```
 
-Feel free to adjust any section to better fit your needs or to add more information as you see fit!
\ No newline at end of file
+Feel free to adjust any section to better fit your needs or to add more information as you see fit!

From 264db650b7204e46330c87a80d676c7b7d1fc8e3 Mon Sep 17 00:00:00 2001
From: himanshus0764 <152205558+himanshus0764@users.noreply.github.com>
Date: Sat, 9 Nov 2024 16:32:13 +0530
Subject: [PATCH 4/4] Update Readme.md

---
 Fractal_art/Readme.md | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/Fractal_art/Readme.md b/Fractal_art/Readme.md
index 57a84a77..d75bab07 100644
--- a/Fractal_art/Readme.md
+++ b/Fractal_art/Readme.md
@@ -37,9 +37,3 @@ Modify the following parameters in the `main()` function to change the fractal's
 
 Running the script generates a fractal pattern that visually represents branching structures.
 
-## License
-
-This project is open-source. Feel free to modify and use it as you wish!
-```
-
-Feel free to adjust any section to better fit your needs or to add more information as you see fit!