Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 08:21:05 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How to divide an image into random sized parts?  (Read 5637 times)

crono

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 179
    • View Profile
    • Donate to Member
How to divide an image into random sized parts?
« on: April 03, 2008, 06:29:55 PM »
Hi,

I want to divide an image into random sized parts. I need this for some kind of puzzle game I'm writing with a friend. Dividing an image into even sized parts like this:

[attach=#1][/attach]

is not a problem at all. But how could I divide in into randomsized parts like this:

[attach=#2][/attach]

The algorithm I'm searching must be capeable of slicing any image in a variable amount (which is set by the player) of parts. The resulting images (parts) should not be smaller than X pixels and not larger than Y Pixels. The parts may not overlap each other. I have no idea how to do this.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: How to divide an image into random sized parts?
« Reply #1 on: April 03, 2008, 06:39:03 PM »
a non-intuitive approach might work well ---
start by imagining a very large grid that divides the entire picture into a grid where each square is X by Y.
now simply REMOVE random edges until you have the desired # of pieces.

(note you'll have to do this a bit differently if you only want rectangular shapes pieces)

crono

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 179
    • View Profile
    • Donate to Member
Re: How to divide an image into random sized parts?
« Reply #2 on: April 03, 2008, 06:58:16 PM »
Good idea Mouser :) But I think keeping track of only producing rect-shapes will be very tricky. I have to use only rect-shapes, because the puzzle will be jpg + javascript based, so there is no way to overlay other shaped images (because of the missing transparency). I think I will try to prototype this Idea on the weekend - Thanks

Ampa

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 592
  • I am cute ;)
    • View Profile
    • MonkeyDash - 2 Player strategy boardgame
    • Donate to Member
Re: How to divide an image into random sized parts?
« Reply #3 on: April 04, 2008, 07:08:51 AM »
How about the alternative aproach...

Code: Text [Select]
  1. Begin with a single Slice (this will be the whole image)
  2. Repeat until you have enough slices {
  3.   Randomly choose a slice (check that it is not already too small to further divide)
  4.   Randomly choos an orientation (vertical or horizontal)
  5.   Divide the Slice it into two parts (this need not be two even parts)
  6. }

This will always ensure you have rectangles.

crono

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 179
    • View Profile
    • Donate to Member
Re: How to divide an image into random sized parts?
« Reply #4 on: April 10, 2008, 10:41:55 AM »
Thanks for your input Ampa. I came to the exact same methode while I was in the shower  ;D It works very well  :Thmbsup:

Silverchip

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 9
    • View Profile
    • Donate to Member
Re: How to divide an image into random sized parts?
« Reply #5 on: April 23, 2008, 07:48:25 PM »
It's probably not irrelevant but you could print, tear it to size desired then scan. I had to post it lol ;D :D :P

crono

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 179
    • View Profile
    • Donate to Member
Re: How to divide an image into random sized parts?
« Reply #6 on: May 08, 2008, 06:15:29 AM »
It's probably not irrelevant but you could print, tear it to size desired then scan. I had to post it lol ;D :D :P
I will remember this if there is a table-top version of the game :Thmbsup:  :P