Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+9 votes

Like a checkerboard?

asked in CSC 150 January201920 by (1 point)

1 Answer

+7 votes
 
Best answer

Indeed it is! The easiest way to do it is to check whether the x & y coordinates sum to an even or odd number. We can do that by checking whether the remainder is 0 or 1 when you divide that number by 2. In NetLogo, you can find the remainder after division using the MOD operation.

In NetLogo 2D, you would use:

ask patches [ 
   if (pxcor + pycor) mod 2 = 0 [
      set pcolor blue
   ]
   if (pxcor + pycor) mod 2 = 1 [
      set pcolor red
   ]
]

In NetLogo 3D, you would do the same thing, but you only want to ask ONE layer of patches to do it, so just change your initial ASK to only have one z-coordinate layer.

ask patches with [ pzcor = -16 ] [ 
   if (pxcor + pycor) mod 2 = 0 [
      set pcolor blue
   ]
   if (pxcor + pycor) mod 2 = 1 [
      set pcolor red
   ]
]
answered by (3.5k points)
selected by
+3

Thank you!

...