The Moving Stripe Puzzle solution REVEALED!!
(and scrolling pictures as well)
Remember that the
reason it doesn't work is the patches are executing their respective
commands in random order, and let''s say that we can't do anything about
that. And that, for any patch, the problem is that when the patch looks at its neighbor's pcolor, that neighbor may or may not have already changed its pcolor because it may have already execute its command. So.... Let's do this work in 2 steps: 0) create a new patch property called "future-pcolor" by putting at the top of your code tab: PATCHES-OWN [FUTURE-PCOLOR] 1) Now, let's ask each of the patches to get its neighbor's pcolor and store it in FUTURE-PCOLOR. 1.5) Notice that, so far, no patch has changed its pcolor, it has just stored away, inside FUTURE-PCOLOR, what its neighbor's pcolor is. 2) When every patch is finished doing that, THEN: 2.01) ask every patch to change its pcolor to FUTURE-PCOLOR. So... |
patches-own [future-pcolor] to move-left ; the first part.... ask patches [set future-pcolor [pcolor] of patch (pxcor + 1) pycor] ; and now, the second part... ask patches [set pcolor future-pcolor] end |
OK... If you've created a button to do this, then you can make it "forever" and watch your stripe move (but slow things down). |
Let's do this, not just to stripes, but to pictures... |
Download a picture from the internet. Make
sure you know where it's stored now (probably in your Downloads folder). Create a button called LoadPicture and attach to it the following code in your code tab: to LoadPicture ca let fred user-file if fred != false [import-pcolors fred] end TRY IT OUT! Yes, it's extremely pixelated. That's because you have relatively large patches and each patch can only hold and display one color. So... Use the settings button to make the patches smaller and create many more of them (but make sure that the entire world is visible inside your monitor). Now try it again. |