File:Barnsley fern 1024x1024.png
Summary
Description |
English: Barnsley Fern colour-toned for natural leaf appearance |
Date | |
Source |
Own work |
Author | Farry |
Permission (Reusing this file) |
Public domain (CC0 1.0) |
Other versions |
![]() |
PNG development |
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
![]() ![]() |
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.
|
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()