r/Python • • Jan 18 '20

Generating Geometric Birds

Post image
1.8k Upvotes

65 comments sorted by

80

u/thebuffed Jan 18 '20 edited Jan 18 '20

Trying to replicate the style of these designs, but in a generative way. Work in progress, but pretty happy so far

Source code: https://github.com/erdavids/Birds-of-a-Feather

More projects: https://github.com/erdavids/Generative-Art

22

u/who_body Jan 18 '20

So do you an entire family to species of birds? That would be interesting

12

u/thebuffed Jan 18 '20

Anything is possible!

23

u/SweetSoursop Jan 18 '20

Create an archipelago class, where each island will have it's own temperature, climate, food source, size and predators.

Have your code create a bird type (wing span, beak type, population) based on which island they live on.

You would have simulated the Origin of Species by Charles Darwin.

5

u/who_body Jan 18 '20

Very cool art project!

2

u/5erif φ=(1+ψ)/2 Jan 19 '20

at zombocom

3

u/Nickthedick66 Jan 18 '20

Love your work and channel, keep up the great content I am learning a lot from you and others like you.

2

u/thebuffed Jan 18 '20

Thanks for saying that! The goal is definitely so that people will learn, just hoping to pass forward what I have learned from others

1

u/agree-with-you Jan 18 '20

I love you both

2

u/I_Love_You-BOT Jan 18 '20

I love you too!

I am a bot trying to spread a little peace, love, and unity around Reddit. Please send me a message if you have any feedback.

0

u/I_Love_You-BOT Jan 18 '20

I love you too!

I am a bot trying to spread a little peace, love, and unity around Reddit. Please send me a message if you have any feedback.

1

u/tward14 Jan 19 '20

I like your style way better than the original, very cool

18

u/eldoea Jan 18 '20

Very cool. Thanks for sharing!

14

u/thebuffed Jan 18 '20

Oh wow, I remember this post of yours! That's crazy, and thanks!

15

u/Sirmikon Jan 18 '20

Cool. I love stuff like this! Nice job!

(Chernoff Faces immediately spring to mind as an orthinological application for this! Basically, instead of pure random generation, link different bird features with data from a real dataset.

You could model birds’ sizes based on weight, feather color based on habitat, eye size based on intelligence, talon type based on diet, etc...

It would be really cool to see how the algorithm would draw different birds.

9

u/thebuffed Jan 18 '20

I am extremely interested in this, I'll have to look into gathering some data or hitting an API for bird attributes. Thanks for pointing this out!

8

u/bens1989 Jan 18 '20

I did a bit of sleuthing for bird info. With a minor adjustment to the ebird API, I got it to send me back data on all of their birds (16.5k results). Some of the data might be helpful, but disappointingly it does not give things like weight, height, etc.

import requests

import json

import pandas as pd

df = pd.DataFrame(json.loads(requests.get(r'https://api.ebird.org/v2/ref/taxonomy/ebird?fmt=json&locale=en_US').content))

df.to_excel('bird_data.xlsx')

2

u/thebuffed Jan 18 '20

Very nice, I'll have to dig into this

1

u/ericonr Jan 19 '20

Does request cache stuff? It's probably faster to download that dataset just once, right?

1

u/bens1989 Jan 19 '20

No requests doesn’t cache. You can write the content to a file. I formatted the content as a dataframe and then wrote it to a spreadsheet. After the first call you can just read from the file.

2

u/Leon_Vance Jan 18 '20

Get the birds to mate and produce offsprings. :)

6

u/mountains-o-data Jan 18 '20

What a fun project! I love this

1

u/thebuffed Jan 18 '20

Thank you!

6

u/gibran800 Jan 18 '20

This is really, really amazing! Just one question, I was looking at the source code and I noticed that your file has a .pyde extension. What's the difference between that and the regular .py? Thanks!

11

u/thebuffed Jan 18 '20

Thank you so much! Yeah, .pyde is the the file that Processing runs through it's python module. I think it's built off of something called Jython, so you're writing Python code, but you have access to Java libraries. I guess it's not "pure" python, but working with graphic libraries like pycairo and pillow is significantly more complicated than using Processing.

4

u/gibran800 Jan 18 '20

Thanks for the info!

3

u/Verslizzle Jan 18 '20

Nice work. How did you come up with this idea and where do you plan on taking it?

4

u/thebuffed Jan 18 '20

Thanks! I randomly came across these designs and thought they seemed perfect for some generative work. I will probably keep messing around with some of the settings and colors, but mostly I just want some cool posters

39

u/Tweak_Imp Jan 18 '20

Now create pythons!

59

u/EquationTAKEN Jan 18 '20
print("_______/")

16

u/conventionistG Jan 18 '20

echo "ssssssssssssSSSSSSsssssss"

15

u/SrHombrerobalo Jan 18 '20

That sounds just like snake jazz!

3

u/afrolofi Jan 18 '20

That coul be:

while True: print('sss s ss s ss s ss s', end = ' ')

0

u/itsa_me_ Jan 18 '20

SssssS SssSssssssS SssSsssssss

5

u/[deleted] Jan 18 '20

At least 150 or more to see. To be a geometric bird master is my destiny!

1

u/Casseroli Jan 19 '20

Oh my god this is so awesome! Projects like this really motivate me a lot to learn more python!

2

u/thebuffed Jan 19 '20

Thank you! You can definitely do it!

1

u/brrrbrbr Jan 19 '20

Amazing work. I’m a beginner and was looking for projects and generative art seems really interesting!

1

u/thebuffed Jan 19 '20

Thanks! You should totally try it out, there's a lot of great beginner tutorials, and then you just let your imagination go wild

1

u/pattyhearst87 Jan 19 '20

Beautiful!

1

u/thebuffed Jan 19 '20

Thank you!

3

u/[deleted] Jan 18 '20

Procedurally generated memes are the future

3

u/conventionistG Jan 18 '20

I'm sure half the shit posts are already automated.

2

u/PharoahChromium Jan 18 '20

Wow! This is super cool! It is always great to see projects that merge the tech and art. Thank you for sharing.

2

u/LdySaphyre Jan 18 '20

Love this so much!

2

u/artjbroz Jan 18 '20

Code commenting goals

2

u/eli_mintz Jan 20 '20

Very nice!

Perhaps you could do this also using SVG (https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg) in addition to Processing and then generate images that can be viewed in a browser. Just something to think about.

1

u/[deleted] Jan 18 '20

Awesome project!

1

u/blamitter Jan 18 '20

Impressive!

BTW. The link to Processing in your readme is broken

1

u/JimBoonie69 Jan 19 '20

Put a bird on it

1

u/lifeisaburrito Jan 19 '20
  • king Tutankhamen would like to know your location *

1

u/[deleted] Jan 19 '20

Very cool! Here's a decorator for the sticky cycling if you want

def sticky(frequency):
    """ regenerate value frequency% of the time """
    def dec(func):
        stored = [func()]

        def inner():
            if random.random() < frequency:
                stored[0] = func()
            return stored[0]
        return inner
    return dec

@sticky(0.1)
def color():
    return random.choice(['red', 'black', 'green'])

1

u/kwelzel Jan 19 '20

Why should stored be a list if it only holds one value?

1

u/[deleted] Jan 19 '20

It's an old scope hack for python2. In python3,

def sticky(frequency):
    def dec(func):
        stored = func()

        def inner():
            nonlocal stored
            if random.random() < frequency:
                stored = func()
            return stored
        return inner
    return dec

will work instead

1

u/kwelzel Jan 19 '20

Ahh, good to know

1

u/[deleted] Jan 19 '20 edited Jan 19 '20

I've never used processing before this but after installing the processing.py extension and when executing the .pyde from the processing GUI, I see

import sys
sys.version
2.7.1 (v2.7.1:dd7e191d4c90+, Sep 24 2017, 10:11:23) 

which isn't even my system default (2.7.15) or the python that it should find if it's reading my $PATH correctly (3.8.0)

(apparently it's running jython and wont have access to any packages I install)

1

u/igottanutt Jan 19 '20

Birds arent real

1

u/monsto Jan 19 '20

The Partridge Fambly called.

On further reflection, how fucking old am I jesus H.

0

u/[deleted] Jan 18 '20

[deleted]

1

u/thebuffed Jan 18 '20

Thanks for the tip!

2

u/kwelzel Jan 19 '20

Your draw_lines method is also unnecessarily complicated:

https://github.com/erdavids/Birds-of-a-Feather/blob/103effe5185626a56039fe64c924506fe54eebf9/Generative_Birds.pyde#L57

The following lines are all the same if p1[0] != p3[0]

first_x_sep = sqrt(pow(p1[0] - p3[0], 2))/lines * first_x_adj
first_x_sep = abs(p1[0] - p3[0])/lines * first_x_adj
first_x_sep = abs(p1[0] - p3[0])/lines * (p3[0] - p1[0])/abs(p3[0] - p1[0])
first_x_sep = abs(p1[0] - p3[0]) * (p3[0] - p1[0])/abs(p3[0] - p1[0]) / lines

Now (p3[0] - p1[0])/abs(p3[0] - p1[0]) gives you the sign of p3[0] - p1[0] (+1 if positive and -1 if negative) and by multiplying it with abs(p1[0] - p3[0]) you get a number which has the absolute value of p1[0] - p3[0] with the sign of p3[0] - p1[0], but this number is just p3[0] - p1[0] itself.

So I propose you get rid of the _adj variables and just write

first_x_sep = (p3[0] - p1[0]) / lines

Fortunately, this also works for the p1[0] == p3[0] case, because you don't need to divide by zero

0

u/[deleted] Jan 18 '20

[deleted]

2

u/thebuffed Jan 18 '20

Yeah! It's essentially the same thing as the Java processing, but you get to write in Python! Also there is P5.js, which is processing for javascript!

0

u/[deleted] Jan 19 '20

[deleted]

1

u/thebuffed Jan 19 '20

I assure you citizen, birds are real. Now go back inside