Raymond Camden's Blog Rss

Friday Challenge: Cut and Randomize a Picture

24

Posted in ColdFusion | Posted on 08-07-2009 | 3,701 views

Been a while since I posted a challenge, and today I had a good idea for a new one. Given a source image, divide the picture into 100 squares, and then paste these squares into a new picture in random order. This will create a mixed up version of the source image. You can assume a decent sized image (minimum of 200x200 pixels). Post your solution, and if you can, URLs to some sample output. As one hint, don't forget ColdFusion has the ability to paste images into canvases.

Comments

[Add Comment] [Subscribe to Comments]

I'll give 10000 bonus points to whoever uses an Ajax library to make each square draggable so you can 'solve' the puzzle after it's jumbled....
Here's my first attempt!

http://209.200.68.149/imagetest.cfm

Yes, I'm using the free CF9 hosting graciously provided by CrystalTech :)

Will link to the code from the same page, once I get it cleaned up a bit :)
Demo:
http://209.200.68.148/image.cfm

Code:
<cfimage name="imgGlobe" source="globe.jpg">

<cfimage source="#imgGlobe#" action="writeToBrowser" >
<!--- Destination Image --->
<cfset imgC = ImageNew("",400,400,"argb")>

<cfset imgA = imgGlobe>
<!--- Loops will create our 100 squares --->
<cfloop from="0" to="360" step="40" index="x">

   <cfloop from="0" to="360" step="40" index="y">
      <cfset imgA = imgGlobe>
      <!--- Get the Image Area square --->
      <cfset imgB = ImageCopy(imgA,x,y,40,40,x,y)>
      <!--- Paste the image to our destination --->
      <cfset ImagePaste(imgC,imgB,y,x)>
   </cfloop>

</cfloop>

<cfimage source="#imgC#" action="writeToBrowser">
Wow, both of you, cool!
I give Mike +200 points for creative use of 'Shuffle'. But seriously, nice work guys!
Agreed, Mike's solution is better.
Todd, can I get 1000 points for being a Google ninja? :p

http://www.bennadel.com/resources/demo/jquery_puzz...

I created one with my own image, just don't have public facing CF space.
@Steve - yep, i'll grant you the 1000 points for that - nice find. And 5000 to Nadel for putting that together.
Mike wins instantly for the use of a Hasselhoff cover! http://www.youtube.com/watch?v=x20v9F-sWHQ
I took Mike's code and attempted to add some jquery to sort the pics.
http://www.coldfusionjedi.com/demos/maimage/
Thanks Ray for graciously hosting this.
@Matthew - that's awesome!! Hard as heck too!
@Matthew - it would be *really* cool if i could ctrl+click several tiles and move them all at once... doable?

I'd also love to see a blog post written up on how you did it (I know I can view the source, but I'd still like to see a write up).
Wait a second...

$("#sortable").sortable();

That's it?!
re: todd and sortable:

yes, the jquery ui library kicks ass.
@todd Im probably the ONLY guy that doesnt have their own blog!
Is it required to use ColdFusion?

I tried it with HTML 5 and JavaScript/jQuery.
http://www.codymarquart.com/projects/image100/
Normally it is required, but you get a pass since it's jQuery. ;)
Would you believe that your HTML5/jQuery version works properly on FireFox 1.5 (don't ask...)?
I'm a first timer at the challenges...

http://code.project924.com/img-functions/cut-and-r...
@Todd,

You have got to be joking .. a one liner? Damn. That _is_ awesome. Hats off to @Mathew.

@Mike,

(Despite the Horrible Hasselhoff cover ;-) Great work!
Wow, you guys kicked butt on this one ...
Here's my attempt .. makes me feel old school !

http://www.drg1.com/challenge.cfm
I must say - I am incredibly impressed by the source pictures you guys used.
Why not use html5 canvas? ( ok I know it said 100 squares but I did not bother editing the image in paint)
http://bjarte.dev.inbusiness.no/canvas/index.html
Slick - of course, it's going to be a few years before we can use that. ;)

[Add Comment] [Subscribe to Comments]