diff --git a/.DS_Store b/.DS_Store index 75e8e9ec..333537bc 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/B/.DS_Store b/B/.DS_Store new file mode 100644 index 00000000..db49523f Binary files /dev/null and b/B/.DS_Store differ diff --git a/B/Barnsley Fern/.DS_Store b/B/Barnsley Fern/.DS_Store new file mode 100644 index 00000000..42e07824 Binary files /dev/null and b/B/Barnsley Fern/.DS_Store differ diff --git a/B/Barnsley Fern/BarnsleyFernGenerator.py b/B/Barnsley Fern/BarnsleyFernGenerator.py new file mode 100644 index 00000000..e69de29b diff --git a/B/Barnsley Fern/Fern.png b/B/Barnsley Fern/Fern.png new file mode 100644 index 00000000..7ff0da08 Binary files /dev/null and b/B/Barnsley Fern/Fern.png differ diff --git a/B/Barnsley Fern/README.md b/B/Barnsley Fern/README.md new file mode 100644 index 00000000..78bdac5d --- /dev/null +++ b/B/Barnsley Fern/README.md @@ -0,0 +1,43 @@ +# Barnsley Fern using Turtle Graphics + +This Python script generates the Barnsley Fern fractal using the Turtle Graphics library. The Barnsley Fern is a famous fractal pattern created through mathematical transformations. + +![Barnsley Fern](Fern.png) + +## How to Run + +1. Ensure you have Python and the Turtle Graphics library installed in your environment. +2. Clone this repository or download the Python script to your computer. +3. Run the script using your preferred Python environment. + +## About the Fern + +The Barnsley Fern is created by applying four transformations with specific probabilities: + +1. Transformation 1: Probability 1% +2. Transformation 2: Probability 85% +3. Transformation 3: Probability 7% +4. Transformation 4: Probability 7% + +Each transformation corresponds to a specific set of equations that determine the position of the points. + +## Customize the Fern + +You can customize various aspects of the generated fern: + +- Screen size and background color +- Dot color and size +- Number of iterations + +## Example + +```python +# Customize the screen size and other parameters +screen.setup(width=800, height=800) +screen.bgcolor("black") + +# Customize the dot color and size +fern.dot(2, "green") + +# Set the number of iterations +iterations = 100000 diff --git a/S/.DS_Store b/S/.DS_Store new file mode 100644 index 00000000..688d0d3e Binary files /dev/null and b/S/.DS_Store differ diff --git a/S/sierpinski_triangle/.DS_Store b/S/sierpinski_triangle/.DS_Store new file mode 100644 index 00000000..39b3950e Binary files /dev/null and b/S/sierpinski_triangle/.DS_Store differ diff --git a/S/sierpinski_triangle/README.md b/S/sierpinski_triangle/README.md new file mode 100644 index 00000000..fde43293 --- /dev/null +++ b/S/sierpinski_triangle/README.md @@ -0,0 +1,33 @@ +# Sierpiński Triangle Generator using Turtle Graphics + +This Python script generates the Sierpiński Triangle fractal using the Turtle Graphics library. The Sierpiński Triangle is a classic example of a fractal pattern known for its self-replicating, intricate structure. + +![Sierpiński Triangle](sierpinski_triangle.png) + +## How to Run + +1. Ensure you have Python and the Turtle Graphics library installed in your environment. +2. Clone this repository or download the Python script to your computer. +3. Run the script using your preferred Python environment. + +## About the Sierpiński Triangle + +The Sierpiński Triangle is constructed by recursively removing smaller equilateral triangles from a larger equilateral triangle. This process is repeated infinitely, resulting in a self-replicating pattern. + +## Customize the Triangle + +You can customize various aspects of the generated Sierpiński Triangle: + +- Depth of recursion to control the complexity of the pattern. +- Initial size of the triangle. +- Choose whether to display a rainbow-colored triangle or a white one. + +## Example + +```python +# Customize the depth of recursion and other parameters +depth = 3 +initial_size = 400 +rainbow = False # Set to True for a rainbow-colored triangle + +# Run the script to generate the Sierpiński Triangle diff --git a/S/sierpinski_triangle/sierpinski_triangle.png b/S/sierpinski_triangle/sierpinski_triangle.png new file mode 100644 index 00000000..814b8f06 Binary files /dev/null and b/S/sierpinski_triangle/sierpinski_triangle.png differ diff --git a/S/sierpinski_triangle/sierpinski_triangle.py b/S/sierpinski_triangle/sierpinski_triangle.py new file mode 100644 index 00000000..f31dc8ab --- /dev/null +++ b/S/sierpinski_triangle/sierpinski_triangle.py @@ -0,0 +1,53 @@ +import turtle +import random + +p = [[0, 280], [-242, -140], [242, -140]] +colors = [ + ((255, 0, 0), (0, 69)), + ((255, 127, 0), (69, 69 * 2)), + ((255, 255, 0), (69 * 2, 69 * 3)), + ((0, 255, 0), (69 * 3, 69 * 4)), + ((0, 0, 255), (69 * 4, 69 * 5)), + ((75, 0, 130), (69 * 5, 69 * 6)), + ((148, 0, 211), (69 * 6, 69 * 7)) +] + +def changeColor(x): + colorx = (x + 242) + for i, (color, (start, end)) in enumerate(colors): + if start <= colorx < end: + t.pencolor(color) + break + +# Set True for rainbow-colored triangle +rainbow = False + +# Initialize turtle +t = turtle.Turtle() +t.hideturtle() +t.speed(0) +t.penup() +t.pencolor('white') + +# Initialize screen +s = turtle.getscreen() +s.setup(width=600, height=600) +s.bgcolor('black') + +# Draw first 3 points +for i in range(3): + t.goto(p[i][0], p[i][1]) + t.dot() + +# Draw 10000 points +for i in range(10000): + r = random.randint(0, 2) + pos = t.pos() + # Midway points + x, y = (pos[0] + p[r][0]) / 2, (pos[1] + p[r][1]) / 2 + t.goto(x, y) + if rainbow: + changeColor(x) + t.dot() + +turtle.exitonclick() diff --git a/animation.py b/animation.py new file mode 100644 index 00000000..2d90772f --- /dev/null +++ b/animation.py @@ -0,0 +1,30 @@ +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +# Create a figure and axis +fig, ax = plt.subplots() + +# Initialize an empty plot +line, = ax.plot([], [], lw=2) + +# Set the axis limits +ax.set_xlim(0, 2 * 3.14) +ax.set_ylim(-1, 1) + +# Function to initialize the plot +def init(): + line.set_data([], []) + return line, + +# Function to update the plot in each frame +def update(frame): + x = 2 * 3.14 * frame / 100 + y = 0.5 * (1 + frame / 100) + line.set_data(x, y) + return line, + +# Create an animation +ani = FuncAnimation(fig, update, frames=100, init_func=init, blit=True) + +# Display the animation (this may vary depending on your Python environment) +plt.show()