![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 6
Rep Power: 0
![]() |
python link picture.
I am trying to code a jigsaw puzzle in python and c but i am unable to find a way to link the split images..... meaning that after the image is split i am unable to find a way that would link the image to the part of the image where it broke from the main and make it stick to the piece.
I am thinking of making a grid to place the piece in but then that would give the the place a way.... any help would be use full. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,784
Rep Power: 5
![]() |
Re: python link picture.
You make a "grid", but don't show it. There are many way of accomplishing this. I think the easiest way to do this is, every time someone places a piece, just snap it to the closest co-ordinates, that is a multiple of the size of each piece.
E.G. width = 20 # This is the width of each piece
height = 20 # This is the height of each piece
x = 44 # This is the x co-ordinate of where the piece was placed
y = 71 # This is the y co-ordinate of where the piece was placed
def new_round(value, multiple):
# Some dirty math to round "value" to the closest multiple of "multiple"
return int(round(value / float(multiple)) * multiple)
newx = new_round(x, width) # Round x to the closest width
newy = new_round(y, height) # Round y to the closest heightBy the way, just curious. How are you displaying the images? Pygame? WxPython? Last edited by Sane; Nov 2nd, 2007 at 10:37 AM. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2007
Posts: 6
Rep Power: 0
![]() |
Re: python link picture.
Thanks that makes sense.... But i have another issue that would there be any way to have the user chose the size and shape of the puzzle piece with that.....
i am new to python and this is a program for my son to learn shapes and things... so i would him to be able to chose the shape. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,784
Rep Power: 5
![]() |
Re: python link picture.
You're not giving me much to go on here, but the size is going to be defined as the (width, height) in the code. The user can choose what that is, and it should be the size of the piece, without the connecting part of the piece.
![]() |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: python link picture.
With ordinary puzzle pieces you're going to have to deal with rotation, also. Are you really looking for a puzzle, or are you looking more for a round-peg in round-hole or "where does the sheep go?" type of training device?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Nov 2007
Posts: 6
Rep Power: 0
![]() |
Re: python link picture.
Ok sorry about that it is a little hard to explain as i am a little new. I am in the concept stage of the program. I am trying to build something where we can take a picture of say the united states and be able to split the pieces as i or some one else choses i.e each states could be its own piece or divide the us by two main parts and so on..... does that make a little more sense.
i have most of the code already designed, alot of the user interface the ability to randomize the pieces but i am stuck on how to make it where a user can select size, and shape of the puzzle piece. hope that help a little more. |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,784
Rep Power: 5
![]() |
Re: python link picture.
So the pieces can vary in size? Ahh. That's a little tricky.
I think your best bet would be to join two pieces together if they are the right fit, and no more than (max_distance_x, max_distance_y) apart. Then once they are recognized by your program as one piece again, everything takes care of itself: If you click to move that piece, both pieces will move together. If you connect another piece to it, it's just as if you're connecting one with one again. Then I wouldn't even worry at all about snapping the pieces to any sort of grid. As long as they snap together, it should work out fine as a jigsaw. To let the user select the sizes and cut up the puzzle manually, you're on your own with this one. I'm thinking you could let the user select an area of the puzzle with an equivilent of a "rectangular marquee", and then cut out and shove the selected area into a different area beside the picture. Clicking the cut piece would move it back. Then it's finished when all of the pieces have been cut out. This definitely depends on the amount of power you want your program to give to the user... Code-wise, this is what immediately pops to my mind structurally for trying to put a puzzle (of varying size pieces) back together. I'll assume you're quite adept with Python, or else you wouldn't be tackling such a difficult project. Python Syntax (Toggle Plain Text)
Last edited by Sane; Nov 3rd, 2007 at 9:53 AM. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Nov 2007
Posts: 6
Rep Power: 0
![]() |
Re: python link picture.
thanks this helps a lot...... i am not technically adept but i know perl, php, and c so th language structure i know.
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Nov 2007
Posts: 6
Rep Power: 0
![]() |
Re: python link picture.
ok Hey guys i am back...... well i was trying to gather up some code mainly what you showed me earlier and thought of a better way to do it.... i am honestly just asking anyone if this makes sense and if so how plausible would it be to do.
her goes.... i thought that since i want them to chose the size and the general shape of the puzzle piece... i thought it would be nice to give them something like a cookie cutter to "cut" the image to the size (with some pre determined choices) that they want and then have it go through a module that would randomize the pieces depending on the level of difficulty they choose.... say easy would just separate the pieces and leave them in the general area then say have it increase by rotating the pieces and randomizing the pieces farther from the start point. does that make sense to any one else or do you think that would create to many problems. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| python for newbie | wizzkid | Python | 3 | Jun 7th, 2006 7:31 PM |
| [tutorial] Python for programming beginners | coldDeath | Python | 30 | Dec 14th, 2005 11:35 AM |
| Convert Python script to C++ code | clanotheduck | Python | 17 | Sep 25th, 2005 8:55 AM |
| Advanced Python Tricks | Arevos | Python | 19 | Sep 24th, 2005 7:39 AM |
| Python - A Programmers Introduction | coldDeath | Python | 17 | Aug 19th, 2005 12:41 PM |