File:Barnsley fern 1024x1024.png

Summary

Description
English: Barnsley Fern colour-toned for natural leaf appearance
Date
Source

Own work

I took the Turtle-Graphics based Python code from the Barnsley Fern's Wikipedia page and adapted it to use Python's "Tkinter" GUI library instead. (This has been included in Python's standard library since Python 3.7 so no external libraries are needed.) This gave a higher resolution image, allowed me to finesse the colour map, and save the image in PNG format. Python code is below, Python 3.7+ interpreter or Pypy 3.7+ JIT-compiler is required.
Author Farry
Permission
(Reusing this file)
Public domain (CC0 1.0)
Other versions High resolution Barnsley fern created in Processing
PNG development
InfoField

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Category:CC-Zero#Barnsley%20fern%201024x1024.png
Category:Self-published work

Source code (python)

import random
import tkinter as tk
width, height = 1024, 1024
pixels = [0] * (width * height)

x, y = 0, 1
for n in range(60 * width * height):

    r = random.random() * 100
    xn, yn = x, y
    if r < 1:
        x = 0
        y = 0.16 * yn
    elif r < 86:
        x = 0.85 * xn + 0.04 * yn
        y = -0.04 * xn + 0.85 * yn + 1.6
    elif r < 93:
        x = 0.20 * xn - 0.26 * yn
        y = 0.23 * xn + 0.22 * yn + 1.6
    else:
        x = -0.15 * xn + 0.28 * yn
        y = 0.26 * xn + 0.24 * yn + 0.44

    x_pix = int(width * (0.45 + 0.195 * x))
    y_pix = int(height * (1 - 0.099 * y ))
    pixels[x_pix + y_pix * width] += 1

greys = [ max(0, (256 - p) / 256) for p in pixels]
colors = [int(c * 255) for g in greys for c in [g ** 6, g, g ** 6]]
root = tk.Tk()
p6header = bytes("P6\n{} {}\n255\n".format(width, height), "ascii")
img = tk.PhotoImage(master=root, data=p6header + bytes(colors))
tk.Label(root, image=img).pack()
img.write("barnsley-fern.png", format='png')
tk.mainloop()
Category:Barnsley fern Category:Fractals Category:PNG created with Python Category:Images with Python source code
Category:Barnsley fern Category:CC-Zero Category:Fractals Category:Images with Python source code Category:PNG created with Python Category:Self-published work