<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>
<chapter name="Tutorial 14: Matrix Positioning">
<setdocpatch name="14jMatrixPositioning" patch="14jMatrixPositioning.maxpat"/>

<previous name="jitterchapter13">Scissors and Glue</previous>
<next name="jitterchapter15">Image Rotation</next>
<parent name="jitindex">Jitter Tutorials</parent>



<h1>Tutorial 14: Matrix Positioning</h1>
<h2>Positioning Data in a Matrix</h2>
<p>In this tutorial we discuss some ways to take a portion of one matrix and place it in some different location in another matrix. There are various reasons you might want to reposition the location of data. We'll be focusing especially on visual effects, but the techniques we show here are useful for any sort of task that involves moving matrix data around.</p>

<p>We'll show how to isolate a region of a matrix, place it at a particular position in another matrix, resize it (which can be useful for visual effects such as stretching, <i>pixelation</i>, and blurring), and move it around dynamically.</p>

<h2>jit.window</h2>
<bullet>Open the <m>Window_options</m> subpatch</bullet>
<p>In the bottom-left corner of the patch there is a <o>jit.window</o> object. We introduced this object in <i>Tutorial 1</i>; it creates a separate window for displaying the contents of a matrix. In most of the other tutorial chapters we have used the <o>jit.pwindow</o> object instead.</p>

<p><o>jit.window</o> and <o>jit.pwindow</o> are pretty similar&#x2014;aside from the obvious difference that one opens a separate window while the other uses a rectangular region within the Patcher window&#x2014;and they share many of the same attributes and messages. There are a few differences, though, so we'll use <o>jit.window</o> this time in order to demonstrate a couple of its unique characteristics.</p>

<p>You probably can't see the <i>Display</i> window that has been opened by the <o>jit.window</o> object, because it's hidden behind the Patcher window. However, if we want to, we can make the <i>Display</i> window be a floating window&#x2014;one that always "floats" on top of every other window in Max while still letting us interact with the foreground Patcher window. To do this, we must turn on the <m>floating</m> attribute of <o>jit.window</o> with a <m>floating 1</m> message. (The <m>floating</m> attribute is <m>0</m> by default.)</p>

<bullet>Open the <m>Window_options</m> subpatch and click on the <o>toggle</o> box  labeled <i>Display as floating window</i> to send a <m>floating 1</m> message to <o>jit.window</o>.</bullet>

<illustration><img src="images/jitterchapter14a.png"/>Make the window "float" in front of all other windows</illustration>

<p>Note that the screen coordinates we've typed into the <o>jit.window</o> object for the display area&#x2014;<m>450 60 770 300</m>&#x2014;specify a display area 320 pixels wide by 240 pixels high. (For an explanation of how to specify screen coordinates for <o>jit.window</o>, see <i>Tutorial 1</i> and/or the Note later in this chapter.)</p>

<h2>From one jit.matrix to another</h2>
<p>Now we will load in a picture and try some modifications.</p>

<bullet>Click on the <o>message</o> box <m>importmovie sunset.jpg</m> to load a picture into the <o>jit.matrix</o> object at the top of the  patch. Turn on the <o>metro</o> labeled <i>Display On/Off</i> to begin sending  <m>bang</m> messages to <o>jit.matrix</o>.</bullet>

<p>The <m>bang</m> sends the matrix (through <o>jit.hue</o>) to a second <o>jit.matrix</o> object before displaying the image  with <o>jit.window</o>. In that second <o>jit.matrix</o> object we'll be able to modify attributes to change what part of the matrix we display. </p>

<illustration><img src="images/jitterchapter14b.png"/>The matrix goes (through <o>jit.hue</o>) to another <o>jit.matrix</o>, then to <o>jit.window</o></illustration>

<p>We've saved several preset configurations for the window's user interface objects in a <o>preset</o> object in the middle of the patch.</p>

<bullet>In the <o>preset</o> object, click on preset 1.</bullet>
<p>This changes the dimensions of the lower <o>jit.matrix</o> object to 16x12, by sending a <m>dim 16 12</m> message to it.</p>

<illustration><img src="images/jitterchapter14c.png"/>The <m>dim</m> message changes the dimensions of the matrix in <o>jit.matrix</o></illustration>

<p>The matrix coming in has the dimensions 320x240, but the receiving <o>jit.matrix</o> has dimensions of only 16x12, so it tries its best to display the entire matrix it receives, but it necessarily has to discard much of the information. This results in a very pixelated image. (The term <i>pixelation</i> refers to the mosaic effect that results from using an insufficient viewing resolution&#x2014;an insufficient number of pixels&#x2014;to represent an image faithfully.) Even though the <o>jit.window</o> object is capable of displaying the full-resolution 320x240 image (because of the window dimensions typed in as arguments), the matrix it is receiving is only 16x12 now. It "expands" the 16x12 matrix to 320x240 for display purposes, duplicating pixels as it needs to.</p>

<bullet>Try dragging on the two <o>number</o> boxes labeled <i>Change actual matrix dimensions</i> to see different pixelation effects.</bullet>

<h2>Interpolation</h2>

<bullet>Now set the <o>number</o> boxes back to <m>16</m> and <m>12</m>, and click on the  <o>toggle</o> labeled <i>Interpolate in window to smooth pixelation</i> to send an <m>interp 1</m> message to <o>jit.window</o>.</bullet>

<illustration><img src="images/jitterchapter14d.png"/>Turn on interpolation in <o>jit.window</o></illustration>

<p>Now the <o>jit.window</o> object&#x2014;instead of simply duplicating pixels of the 16x12 matrix to make a bunch of 20x20-pixel blocks&#x2014;interpolates between values in the incoming matrix as it expands it to 320x240. That is, as it expands the image , it creates a smooth gradation of colors between each cell value and and its neighboring values in the incoming matrix, so all of the transitions from cell to cell in the displayed 320x240 matrix are as gradual as possible. The interpolation causes extreme blurring because the size difference between the incoming matrix and the display is so great.</p>

<bullet>Click on the <o>toggle</o> again to turn off the interpolation. This sends an <m>interp 0</m> message to <o>jit.window</o>, setting its <m>interp</m> attribute to <m>0</m> (off). Enter some new matrix dimensions into the  <o>number</o> boxes labeled <i>Change actual matrix dimensions</i> so that the image is not quite so pixelated: say, <m>80</m> and <m>60</m>. (You should see that now the pixelated blocks are each only 4x4.) Click on the <o>toggle</o> to turn interpolation back on. Notice that in this case the blurring is not so extreme because interpolation occurs over only 4 pixels. Click on the <o>toggle</o> again to turn off the interpolation.</bullet>

<bullet>Now click on the <o>toggle</o> labeled <i>Interpolate in matrix to smooth pixelation</i> to turn on interpolation within <o>jit.matrix</o> (not <o>jit.window</o>).</bullet>

<illustration><img src="images/jitterchapter14e.png"/>Interpolation doesn't do much when you're reducing the size of the matrix</illustration>

<p>Notice that this doesn't have very much effect. That's because <o>jit.matrix</o> still only has a 80x60 matrix to send out. Interpolation in this case (when we're reducing the size of the matrix rather than enlarging it) is pretty ineffectual.</p>

<bullet>Click on that <o>toggle</o> again to turn off interpolation in <o>jit.matrix</o>.</bullet>

<h2>Isolate a Part of the Matrix</h2>
<p>Now we'll look at ways to focus on a particular portion of a matrix.</p>

<bullet>In the <o>preset</o> object, click on preset 2. Now you see only a small portion of the picture.</bullet>

<p>This preset restores the dimensions of our <o>jit.matrix</o> object back to 320x240. But we can still isolate a particular part of the matrix , without altering the actual dimensions of the full matrix, using some different attributes: <m>srcdimstart</m>, <m>srcdimend</m>, and <m>usesrcdim</m>. Notice that we have sent three new messages to <o>jit.matrix</o> to set those three attributes: <m>dimstart 40 150</m>, <m>dimend 119 209</m>, and <m>usesrcdim 1</m>. These messages let us specify a subset of the full matrix coming in the inlet, and send those values out as a full-sized (in this case 320x240) matrix. This smaller subset of the incoming matrix gets "expanded" (cells are duplicated as needed) within <o>jit.matrix</o> itself, to fill the size of the outgoing matrix. The <m>srcdimstart</m> and <m>srcdimend</m> attributes are ignored. In the messages for setting the <m>srcdimstart</m> and <m>srcdimend</m> attributes, the words <m>srcdimstart</m> and <m>srcdimend</m> are followed by cell indices describing the starting and ending points within each dimension. With our  <m>dimstart 40 150</m> and <m>dimend 119 209</m> messages, we have told <o>jit.matrix</o> to use a specific 80x60 region from cell 40 to 119 (inclusive) in the horizontal dimension and from cell 150 to 209 in the vertical dimension.</p>


<techdetail>Note: In this chapter we've discussed three different ways of specifying rectangular regions! It's important to be clear what we're specifying in each case.<br/>
<ul>
	

<li>In <o>jit.window</o> we typed in <i>screen coordinates</i> for the display area of the window. In the computer's operating system, screen coordinates are specified in terms of the point at the <i>upper-left corner of a pixel</i>. The upper-left corner of the entire screen is 0,0; the point two pixels to the right of that (the upper-left corner of the third pixel from the left) is 2,0; and the point 5 pixels down from that (the upper left corner of the sixth pixel down is 2,5. To describe a rectangular area of the screen, we type in arguments for the left, top, right, and bottom limits of the rectangle's coordinates.</li>

<li>In the <m>dim</m> attribute to <o>jit.matrix</o>, we provided <i>dimension sizes</i> for the object's matrix: the <i>number of cells</i> in each dimension.</li> 

<li>In the <m>srcdimstart</m> and <m>srcdimend</m> attributes, we're stating (inclusive) <i>cell indices</i> within the matrix. Remember that cells are given index numbers that go from 0 to one less than the number of cells in that dimension. (Planes are indexed similarly, by the way.) So for a 320x240 matrix, the indices for the cells in the first dimension go from 0 to 319, and the indices for the cells in the second dimension go from 0 to 239. To set the source dimensions for <o>jit.matrix</o>, we need to specify the range of cells we want to start at, using <m>srcdimstart</m> followed by a starting cell index for each of the matrix's dimensions, and using <m>srcdimend</m> followed by the cell indices for the end of the range in each dimension.</li>
</ul>
These different ways of describing regions can be confusing, but if you think carefully about exactly <i>what</i> it is that you're specifying, you'll be able to deduce the proper way to describe what you want.</techdetail>

<p>We're using only an 80x60 pixel range of the incoming matrix as the source, but the destination matrix is 320x240. Once again, this expansion of a smaller matrix into a larger one causes a pixelation effect. This time, though, the expansion occurs inside <o>jit.matrix</o> (i.e. between its "source" region and its "destination" size), rather than between <o>jit.matrix</o> and <o>jit.window</o> (as we did earlier when we reduced the actual dimensions of the <o>jit.matrix</o>). Therefore, if we want to smooth out the pixelation by interpolating, we must do it in <o>jit.matrix</o>. There's no point in turning on interpolation in <o>jit.window</o>, since it's already receiving a 320x240 matrix from <o>jit.matrix</o>.</p>

<bullet>If you want to verify this, turn on the <i>interpolate in window...</i> <o>toggle</o> to send an <m>interp 1</m> message into <o>jit.window</o>. It has absolutely no effect because we're trying to interpolate a 320x240 matrix into a 320x240 display area, so no change occurs. Turn off that same <o>toggle</o> to set the <m>interp</m> attribute of <o>jit.window</o> back to <m>0</m>. Now use the other <o>toggle</o> to send an <m>interp 1</m> message into <o>jit.matrix</o>. This time we get the smoothing effect we desire.</bullet><br/>

<bullet>Try entering new values into the <o>number</o> boxes to change the arguments of the <m>srcdimstart</m> and <m>srcdimend</m> attributes. This lets you isolate any particular region of the picture as your "source" area. Of course, the dimensions you choose for your source area will determine the distortion that the picture undergoes when it's expanded to fill a 320x240output matrix.</bullet>


<h2>Flip the Image</h2>

<p>You might assume that the arguments of the <m>srcdimend</m> attribute (the ending cell indices of the source region) should be greater than the index numbers for the <m>srcdimstart</m> attribute. But that need not necessarily be so.</p>

<bullet>In the <o>preset</o> object, click on preset 3. Now the picture is flipped vertically.</bullet>
<illustration><img src="images/jitterchapter14f.png"/>The top and bottom have been flipped in the second dimension.</illustration>
<p>This example shows that if you specify an ending cell index in the vertical dimension that is less than the starting index, <o>jit.matrix</o> will still relate those indices to the starting and ending points in the vertical dimension of the destination matrix , effectively reversing the up-down orientation of the values. (This statement assumes that you have not done the same sort of flip to the orientation of the destination matrix!)</p>

<p>You could do the same sort of flip in the horizontal (first) dimension to flip the image horizontally. If you flip the source region in <i>both</i> dimensions you get the same visual effect as if you had rotated the image 180&#xB0;.</p>

<bullet>In the <o>preset</o> object, click on preset 4.</bullet>
<p>In this example we've flipped the source region in both dimensions, reduced the size of the source area to 160x120, and smoothed out the pixelation by turning on the <m>interp</m> attribute.</p>

<h2>Resize the Output Matrix</h2>

<p>Just as we specified the source region of the matrix, we can also specify a destination for that source. This still does not change the size of the output matrix; that will still be 320x240, as determined by the <m>dim</m> attribute. However, this does change the region into which the specified source region will be placed. The source region of the input matrix will be placed in the destination region of the output matrix (with expansion/contraction as necessary). Cells of the output matrix that lie outside the destination region will remain unchanged.</p>

<bullet>In the <o>preset</o> object, click on preset 5. The entire input matrix has been squeezed into an 80x60 rectangle in the center of the output matrix.</bullet>
<p>The first thing to notice is that the <m>usesrcdim</m> attribute has been turned off, so that we're back to using the entire input matrix as the source. (The <m>srcdimstart</m> and <m>srcdimend</m> attributes are now being ignored.) The <m>usedstdim</m> attribute has been turned on, so the input will be placed in whatever part of the output matrix we specify. The <m>dstdimstart</m> and <m>dstdimend</m> attributes have been set to specify the cells in the center of the matrix as the destination: <m>dstdimstart 120 90</m> and <m>dstdimend 199 149</m>. We've turned the <m>interp</m> attribute off because we're contracting the image rather than expanding it.</p>

<p>Notice also that we've turned on the <o>toggle</o> labeled <i>Erase previous image</i>. This sends the number <m>1</m> into the <o>if</o> <m>$2 then clear</m> object. The <i>if</i> part of the statement is now true, so every time the object receives a message in its left inlet it will send out the message <m>clear</m>. This clears the contents of the <o>jit.matrix</o> object immediately after displaying the image, to prepare <o>jit.matrix</o> for the next matrix it will receive . That ensures that the values in all the cells outside the destination region will be 0, so the unused region of the output matrix will be displayed as black.</p>

<p>Change some of the values in the <o>number</o> boxes that provide the destination dimensions, to move (and resize) the picture within the Display window.</p>

<p>Now turn off the <o>toggle</o> labeled <i>Erase previous image</i>, to suppress the <m>clear</m> messages. Change the arguments of <m>dstdimstart</m> and <m>dstdimend</m> some more, and notice what's different this time. The previous destination regions are still being drawn in the Display window because those cells in the matrix have not been cleared, and they are left unchanged if they're outside the new destination region.  This gives the effect of leaving "trails" of the previous image behind. We can potentially use these artifacts for their particular visual effect.</p>

<illustration><img src="images/jitterchapter14g.png"/>If the matrix is not cleared, old destination areas will be left behind if they're outside the new destination region. For continuous changes, this leaves a trail of past images.</illustration>
<h2>Moving the Image Data Around in the Matrix</h2>
<p>By setting up an automated Max process that modifies the <m>dstdimstart</m> and <m>dstdimend</m> attributes, we can move the data around in the matrix, making the image seem to move around in the display.</p>

<bullet>In the <o>preset</o> object, click on preset 6.</bullet>
<p>This starts an automated process inside the <o>patcher</o> <m>move_around</m> subpatch that provides a continuous stream of new arguments for the <m>dstdimstart</m> and <m>dstdimend</m> attributes. (It is connected to the lower sections with hidden patchcords.) The <o>toggle</o> above the <o>patcher</o> turns on this process, and the <o>number</o> box gives a time, in milliseconds, for each move to a new destination.</p>

<bullet>Double-click on the <o>patcher</o> <m>move_around</m> object to see the contents of the subpatch. So far, we're only using the right half of the subpatch.</bullet>

<illustration><img src="images/jitterchapter14h.png"/>The destination-moving process in the subpatch [move_around]</illustration>

<p>The "rate" value coming in the right <o>inlet</o> is a time interval for the <o>metro</o> object. The <o>metro</o> periodically bangs four <o>random</o> objects which choose new left, top, right, and bottom cell indices at random. These destination points are sent, along with the time value, to <o>line</o> objects. The <o>line</o> objects send out new values every 50 ms (the rate at which we're displaying the image) to gradually move the destination region to these new random points. Outside the subpatch, those values are used as arguments for the <m>dstdimstart</m> and <m>dstdimend</m> attributes of <o>jit.matrix</o>.</p>

<p>This subpatch contains a couple of tricks worth noting. The first trick is that we've made it so the arguments for <m>dstdimend</m> can potentially exceed the 320x240 range of the matrix. For example, we use a <o>random</o> <m>640</m> object for the horizontal dimension, then subtract 160 from the result to give us an ending cell index from -160 to 479. We do this to  increase the likelihood of a larger destination area so that we can see a larger view of the image as it moves around, and it also means that the image will more frequently move all the way to the edge of the window. It's noteworthy that we can specify destination boundaries that are beyond the limits of the actual cells in the matrix, and <o>jit.matrix</o> will place the image in that area to the best of its ability (clipping it off when it exceeds the limits of the matrix dimensions). The second trick is a trivial but useful detail: we use a <link name="select" type="refpage">sel</link> <m>0</m> object to detect when the <o>metro</o> gets turned off, and we use that to trigger a <m>stop</m> message to each of the <o>line</o> objects so that they don't continue sending out values after the user has turned off the process.</p>

<bullet>Close the <i>[move_around]</i> subpatch window.</bullet>

<h2>Changing, Resizing, and Moving the Source Image</h2>

<p>Now we'll automate changes to the source image, as well.</p>

<bullet>In the <o>preset</o> object, click on preset 7.</bullet>
<p>In much the same manner as we did for the destination area, we're now continually changing the source area of the image. In effect, we're now seeing a constantly changing view of some retangular subset of the source matrix (using <m>srcdimstart</m> and <m>srcdimend</m>) while also constantly resizing that view and moving it around in the window (using <m>dstdimstart</m> and <m>dstdimend</m>). Because the source and destination rectangles are chosen randomly by the <i>[move_around]</i> subpatch, the image sometimes gets flipped, too. We have turned on the <m>interp</m> attribute in the <o>jit.matrix</o> object to smooth out the pixelation that would occur when the source image gets stretched.</p>

<bullet>To get a slightly clearer view of what's going on, try turning on the <o>toggle</o> marked <i>Erase previous image</i>.</bullet>

<h2>One More Word About Dimensions</h2>

<p>This tutorial has shown how to change the dimensions of a <o>jit.matrix</o> object, and how to specify source and destination regions within that object. For ease of discussion and visualization, we've used a two-dimensional matrix, and specified source and destination rectangles within the matrix. But we should point out that these ideas can also be employed with matrices that have any number of dimensions. (The number of arguments for <m>srcdimstart</m>, <m>srcdimend</m>, <m>dstdimstart</m>, and <m>dstdimend</m> should correspond to the number of dimensions in the <o>jit.matrix</o> object.) For example, if we have a three-dimensional matrix, these arguments can be used to specify a hexahedron in the virtual 3D space of the matrix.</p>

<div>
<techdetail>Note: In certain Jitter objects that deal exclusively with 2D matrices, such as <o>jit.movie</o>, source and destination regions will always be rectangular areas. So in those objects the source and destination areas are defined in single attributes called <m>srcrect</m> and <m>dstrect</m>, which take four arguments to specify the bounding (left-top and right-bottom corner) cells of the rectangles.</techdetail>
</div>

<h2>Hue Rotation</h2>

<p>Just to add a little additional color variety, we've placed a <o>jit.hue</o> object between  the two <o>jit.matrix</o> objects. (<o>jit.hue</o> is described in detail in <i><link type="tutorial" module="jit" name="jitterchapter07">Jitter Tutorial 7</link></i>.)</p>

<bullet>In the <o>preset</o> object, click on preset 8 to see <o>jit.hue</o> in action.</bullet>
<illustration><img src="images/jitterchapter14i.png"/>Modify the hue angle</illustration>
<p>This preset turns off <m>usedstdim</m>, but keeps <m>usesrcdim</m> on, and keeps interpolation on in <o>jit.matrix</o> to blur the expanded image. The automated process in the <o>patcher</o> <m>rotate</m> subpatch continually rotates the hue angle of <o>jit.hue</o>.</p>

<bullet>Double-click on the <o>patcher</o> <m>rotate</m> object to see the contents of the subpatch.</bullet>
<illustration><img src="images/jitterchapter14j.png"/>The contents of the [rotate] subpatch</illustration>
<p>The value coming in the right inlet provides a time, in milliseconds, to complete a 360&#xB0; hue rotation. When a <m>1</m> comes in the left inlet, the number <m>360</m> is combined with that time value to instruct the <o>line</o> object to go from 0 to 360 in that amount of time, sending out a new angle value once every 50 milliseconds. Note that the first typed-in argument of the <o>line</o> object contains a decimal point. This instructs <o>line</o> to send out <m>float</m> values rather than <m>int</m>s, for greater precision (and because the <m>hue_angle</m> message of <o>jit.hue</o> expects a <m>float</m> argument). When <o>line</o> reaches 360, its right outlet sends out a <m>bang</m>. We use that <m>bang</m> to set the internal value of <o>line</o> back to 0, then we re-bang the <o>pack</o> object to start the next rotation. When a <m>0</m> comes in the left inlet, the <link name="select" type="refpage">sel</link> <m>1</m> object passes it directly to <o>line</o> to stop <o>line</o> and reset the hue angle to 0.</p>

<bullet>Close the <i>[rotate]</i> subpatch window.</bullet>
<bullet>In the <o>preset</o> object, click on preset 9. This combines virtually all of the automation and image -manipulation techniques of the patch. The  changes of destination dimensions of <o>jit.matrix</o> are set to 200 ms this time, creating a more rapid rhythmic effect.</bullet>
<h2>Full Screen Display</h2>
<p>When you've got your Max patch creating just the images that you want, and you want to display your results in a somewhat more elegant way, you can instruct <o>jit.window</o> to fill your entire screen. <o>jit.window</o> has an attribute called <m>fullscreen</m>; when <m>fullscreen</m> is on, the <o>jit.window</o> uses the entire screen as its display area. If you uncheck the <m>fsmenubar</m> attribute in the <o>jit.window</o> inspector, the menu bar will be hidden.</p>

<p>There are a few things to remember about using the fullscreen capability of <o>jit.window</o>.</p>

<p>First of all, once you have filled your screen with an image (and especially if you have also hidden the menubar), you will no longer be able to use your mouse to turn <m>fullscreen</m> off. So you will need to program into your Max patch some method of returning the <m>fullscreen</m> attribute to 0.</p>

<p>Secondly, only one <o>jit.window</o> can fill any one screen at any one time. If you have more than one <o>jit.window</o> object vying for access to the full screen, the <o>jit.window</o> object that has most recently had its <m>fullscreen</m> attribute set to <m>1</m> will fill the screen.</p>

<p>Also, even when a <o>jit.window</o> is fullscreen, its resolution is determined by its actual dimensions (that is, by the arguments of its <m>rect</m> attribute). So if the <m>rect</m> attribute describes a 320x240 rectangle, that will be the resolution of your image, even though your screen dimensions are much greater than that.</p>

<p>In the <m>Window_options</m> subpatch, we've included the capability to turn the <m>fullscreen</m> attribute of <o>jit.window</o> on and off with the space bar of your keyboard. Note theat the <o>jit.window</o> object has an attribute named <m>fsmenubar</m> set to 0. This removes the top menu bar (in Macintosh) when the window is expanded.</p>

<illustration><img src="images/jitterchapter14a.png"/>Using the space bar to switch the window to full screen display</illustration>
<bullet>Try toggling <m>fullscreen</m> on and off with the space bar.</bullet><br/>
<bullet>For a more abstract visual effect, try importing the <i>colorswatch.pict</i> image into the <o>jit.matrix</o>  at the top of the patch, then try the different presets.</bullet><br/>
<p>In this tutorial, we've used a still image as our source material so that you could easily see the effects being demonstrated, but there's no reason that you couldn't use a video (from <o>jit.movie</o> or some other video source) as your basic material. (You might want to copy the contents of this patch to a new Patcher window and modify the top-left part of it to try that out.)</p>

<h2>Summary</h2>
<p>There are several ways to isolate and reposition certain data in a matrix. The <m>dim</m> attribute of <o>jit.matrix</o> sets the actual dimensions and size of the matrix. By turning on the <m>usesrcdim</m> and <m>usedstdim</m> attributes of <o>jit.matrix</o>, you can instruct it to use a particular portion of its input and output matrices, which are referred to as the <i>source</i> and <i>destination</i> regions of the matrix. You specify the cell boundaries of those regions with the <m>srcdimstart</m> and <m>srcdimend</m> attributes (to set starting and ending cells as the corners of the source region) and the <m>dstdimstart</m> and <m>dstdimend</m> attributes (for the destination region). These attributes do not change the actual size of the matrix, but they specify what part of the input matrix will be shown in what part of the output matrix when <m>usesrcdim</m> and <m>usedstdim</m> are on. If the source and destination regions are different in shape or size, <o>jit.matrix</o> will either expand or contract the source region to fit it in the destination region. This results in either duplication or loss of data, but can provide interesting stretching or <i>pixelation</i> effects. The source and destination regions can be altered dynamically with numbers provided by some other part of your Max patch for interactive or automated modification of the size, shape, and position of the image.</p>

<p>When the <m>interp</m> attribute is on, <o>jit.matrix</o>  interpolates (provides intermediate values) between values when a dimension of the destination region is greater than that of the source region. This smooths out pixelation effects, and blurs the changes between values in adjacent cells.</p>

<p>The <o>jit.window</o> object displays whatever size matrix it receives, using whatever display rectangle has been specified for it in its <m>rect</m> attribute. If the size of the incoming matrix differs from the size of the display area, the image will be expanded, or contracted, or distorted by <o>jit.window</o>. This, too, can be used for stretching and pixelation effects. <o>jit.window</o> also has an <m>interp</m> attribute which, when turned on, smooths out the pixelation caused by this expansion and stretching.</p>

<p>To fill the entire screen with an image, you can turn on <o>jit.window</o>'s <m>fullscreen</m> attribute, and you can hide the menu bar with an <m>fsmenubar 0</m> message. (Just remember to leave yourself some way to get your Patcher window back in the foreground.)</p>

<p>We've demonstrated the techniques of resizing, repositioning,  flipping, and interpolating matrix data to create visual effects such as stretching, distorting,blurring, and pixelation.</p>
	<seealsolist>
		<seealso display="Video and Graphics Tutorial 6: Jitter Matrix Exploration Part 2" module="Video and Graphics" name="jitterchapter00h_Jitter Matrix 2" type="tutorial" />
		<seealso name="jit.hue">Rotate hue</seealso>
		<seealso name="jit.matrix">The Jitter Matrix!</seealso>
		<seealso name="jit.movie">Play or edit a movie</seealso>
		<seealso name="jit.window">Display data in a Window</seealso>
		<seealso name="line">Output numbers in a ramp from one value to another</seealso>
		<seealso name="pack">Combine numbers and symbols into a list</seealso>
		<seealso name="pak">Format items into a list and automatically trigger output.</seealso>
		<seealso name="patcher">Create a subpatch within a patch</seealso>
		<seealso name="preset">Store and recall the settings of other objects</seealso>
		<seealso name="random">Generate a random number</seealso>
	</seealsolist>
</chapter>
