Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411433 Posts in 69363 Topics- by 58418 Members - Latest Member: Pix_RolleR

April 20, 2024, 07:07:44 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)area dividing algorithm (Mondrian)
Pages: [1]
Print
Author Topic: area dividing algorithm (Mondrian)  (Read 8525 times)
nikki
Level 10
*****


View Profile
« on: August 27, 2010, 07:26:30 AM »




I am thinking of these Mondrian paintings (the early stuff)
and was wondering which algorithm one would use to try to generate these babies procedurally ?
any pointers ?
Logged
benbradley
Guest
« Reply #1 on: August 27, 2010, 08:37:43 AM »

It might not give a perfect result but you could generate something very similar by recursively dividing rectangles, like a binary tree.

Start with a whole square
Randomly pick a direction to divide, either X or Y
Pick a value from 0 up to the width or height of your square
Divide the square along this line (eg. X=10)
Maybe plot a black line at this point.

Then apply this to all the sub-rectangles. Repeat down to say 5 levels.
At the end of dividing all the rectangles, pick a random color and flood fill each part. Smiley
Logged
Solved
Level 0
***


View Profile
« Reply #2 on: August 27, 2010, 10:43:24 AM »

I just randomly tried the recursive subdivision way and made a python script for it http://pastebin.com/K3hCdTb4 . If you put sensible bounds on your algorithm it will probably work pretty well.

Some images:
https://dl.dropbox.com/u/10426165/Screenshot.png
https://dl.dropbox.com/u/10426165/Screenshot-1.png
https://dl.dropbox.com/u/10426165/Screenshot-2.png
Logged
Guillaume
Level 7
**



View Profile
« Reply #3 on: August 27, 2010, 11:12:55 AM »

That technique seems to work pretty well!

However, you'd need to limit the minimum width for a rectangle- this screenshot has rectangles that are way too thin.
Logged
slembcke
Level 3
***



View Profile WWW
« Reply #4 on: August 27, 2010, 12:55:31 PM »

Looks a lot like a k-d tree.
Logged

Scott - Howling Moon Software Chipmunk Physics Library - A fast and lightweight 2D physics engine.
Solved
Level 0
***


View Profile
« Reply #5 on: August 27, 2010, 02:50:17 PM »

by messing with the range the subdivide values can be in and stopping drawing when you are below a minimum width, you can get a better result. Obviously, like with a lot of algorithms, you can keep tweaking it to get better results for as long as you like.

http://pastebin.com/F6xuSLGC

https://dl.dropbox.com/u/10426165/new-screenshot.png
https://dl.dropbox.com/u/10426165/new-screenshot-2.png
https://dl.dropbox.com/u/10426165/new-screenshot-3.png
Logged
benbradley
Guest
« Reply #6 on: August 27, 2010, 06:01:29 PM »

Yeah, the second set look really cool. Smiley

Another way to tweak it might be to pick a rectangle to divide from all existing rectangles, using relative areas as the probability. But that's already pretty close.
Logged
nikki
Level 10
*****


View Profile
« Reply #7 on: August 27, 2010, 11:29:57 PM »

WOW, i had to be go out for a day, and found this post filled with goodness ! Wow thanks Solved for your code, mucho mucho appreciated.

Your already there for the 85% i guess, only thing i spot that's different is something that a post-processing loop could fix, to make the black lines 'even-out' in other words to adjust the shapes slightly after all the randomness to make it so that the black lines are as horizontal/vertical as possible (no small corners)
Logged
st33d
Guest
« Reply #8 on: August 29, 2010, 05:23:13 PM »

Reminds me of this by Jared Tarbell:

http://complexification.net/gallery/machines/substrate/index.php

There's source code to it when you launch an Applet.
Logged
Nix
Guest
« Reply #9 on: August 29, 2010, 07:22:30 PM »

Reminds me of this by Jared Tarbell:

http://complexification.net/gallery/machines/substrate/index.php

There's source code to it when you launch an Applet.

That's... really cool.
Logged
mcc
Level 10
*****


glitch


View Profile WWW
« Reply #10 on: August 29, 2010, 10:03:09 PM »

Pretty.

I wonder-- As I remember Mondrian was obsessed with the golden ratio and had the different areas in his paintings relate to each other via golden ratios as often as possible. If you had your program enforce golden ratios, would the images look more Mondriany?
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
nikki
Level 10
*****


View Profile
« Reply #11 on: August 29, 2010, 11:30:09 PM »

if i remember correctly Mondrian was against mathemathically constructing his works, it was much moire intuitive, alot of people claim there are golden ratio's in there, sometimes there are a few, but that's just a coincidence i think.
or have you found anything in particular to proof this claim?  Well, hello there!


offcourse a few golden ratio's here and there in a procedure like this , does make things nicer for the eye...


Logged
Solved
Level 0
***


View Profile
« Reply #12 on: August 30, 2010, 02:38:06 AM »

Reminds me of this by Jared Tarbell:

http://complexification.net/gallery/machines/substrate/index.php

There's source code to it when you launch an Applet.

Really awesome, the generated pictures look like cities from above.
Logged
Nix
Guest
« Reply #13 on: August 30, 2010, 05:29:49 AM »

So it looks like the general consensus here is to use a recursive BSP approach to generating those patterns, but I don't really think those results match Mondrian's paintings. To make it a bit clearer what I mean, here is a bare-bones Mondrian pattern that has all the essential bits and pieces of most other Mondrian paintings:



Here's my idea for a more "Mondrian-y" algorithm:

1) Create a bunch of vertical and horizontal lines that span the entire image, randomly spaced.
2) Create a bunch of vertical and horizontal lines that only stretch part of image such that their end-points are touching already-existing lines.
3) Flood fill random squares with random colors, leave some empty.

I suspect this may spit out images with a bit more similarity to actual Mondrian paintings.

 Coffee
Logged
Solved
Level 0
***


View Profile
« Reply #14 on: August 30, 2010, 06:47:51 AM »

Yeah, that could be a better method, I seem to have become very interested in this sort of stuff recently so I will probably implement a version of your method and see how it works.

Obviously the colours in my version of the subdividing one are completely off and those could be changed as well.

I had an idea for another method that creates slices, with knowledge of only the previous slice, so you could create an infinite mondrian painting one slice at a time.
« Last Edit: August 30, 2010, 09:17:55 AM by Solved » Logged
st33d
Guest
« Reply #15 on: August 30, 2010, 07:11:12 AM »

You should read about A. Michael Noll

http://www.citi.columbia.edu/amnoll/CompArtExamples.html

He's already tackled this problem before in the 1960s and it's an interesting read.
Logged
Nix
Guest
« Reply #16 on: August 30, 2010, 09:08:28 AM »

I seem to have become very interested in this sort of stuff recently...

Have you played with Processing? I hear it's very good for computer art.

Quote
I had an idea for another method that creates slices, with knowledge of only the previous slice, so you could create an infinite mondrian painting one slice at a time.

That could very cool. Then you could have a sort of fractal Mondrian painting that you can keep zooming into? The only thing is that Mondrian has lines that span multiple "slices", which is really the thing that the BSP method was missing. I think you should figure out how to have some consistency among adjacent slices like that.

You should read about A. Michael Noll

http://www.citi.columbia.edu/amnoll/CompArtExamples.html

He's already tackled this problem before in the 1960s and it's an interesting read.

Bookmarked
Logged
Solved
Level 0
***


View Profile
« Reply #17 on: August 30, 2010, 09:17:52 AM »

I have edited the subdivide method to create more mondrian like pictures, by making it more likely to choose white. I shouldn't need to post updated code for that.

Screenshot 1
Screenshot 2
Screenshot 3

Also I have coded up Nix's algorithm, it produces quite nice mondrian pictures. My code is really ugly and has magic numbers everywhere, because of rushing. Also doesn't prevent rectangles from being too small. Will fix these problems later.

Code
Screenshot 1
Screenshot 2
Screenshot 3

The lines that span multiple slices will work as the algorithm would know the previous slice, so it could carry on a line from the previous slice. This way the lines could span more than one slice. The main problem would be, the way I'm thinking of doing the slices, it could be infinite, but only in one direction, the other would have to be finite.
« Last Edit: August 30, 2010, 09:23:29 AM by Solved » Logged
nikki
Level 10
*****


View Profile
« Reply #18 on: August 31, 2010, 03:09:45 AM »

Quote
You should read about A. Michael Noll ..
great link! I've found this pdf by him too, wich is about generating Mondrians procedurally (in 1964)

thanks again

oh and i like your new screenshots very much Solved, i think they look more like the specific originals (the very early not so famous Mondrians) especcially when they all would be colored in that simple pallet that is  Well, hello there!

I'm trying some things myself too, but its not yet in a showable state
edit:

« Last Edit: August 31, 2010, 05:22:12 AM by nikki » Logged
Sigma
Level 1
*


View Profile WWW
« Reply #19 on: September 05, 2010, 09:13:25 PM »

try quadtree  Smiley
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic