<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Video and Graphics 6: Jitter Matrix Exploration Part 2">

<previous name="jitterchapter00g_Jitter Matrix 1">Jitter Matrix Part 1</previous>
<next name="jitterchapter00i_Generating Geometry">Generating Geometry</next>
<parent name="jitindex">Jitter Tutorials</parent>

<openfile name="Jitter Matrix Exploration Part 2" patch="jitter_core_-_6_-_Jitter_Matrix_Exploration_2.maxpat"/>

<h1>Video and Graphics Tutorial 6: Jitter Matrix Exploration Part 2</h1>

<h2>Intro</h2>

<p>While being able to control individual cells in a matrix can be useful, there are a lot of other ways to fill a matrix with data. We’ll look at filling a matrix from a few other sources in this chapter. </p>

<h2>Setup</h2>

<ul><li>
	<openfilelink filename="jitter_core_-_6_-_Jitter_Matrix_Exploration_1.maxpat">Open the first patch</openfilelink>

</li></ul>

<h2>Filling a Matrix</h2>

<p>This example uses the <m>setcell</m> message in combination with an <o>uzi</o> object to rapidly fill a matrix.</p>

<p>Lock the patch and double-click the <b>patcher fillmatrix</b> object to open up the subpatcher.</p>


<p>When you click the button on the main patcher labeled <i>fill</i>, it sends a <m>bang</m> message to the <b>uzi 12</b> object, causing it to rapidly send values from 1 - 12 out the right outlet. These values correspond to the y (row) values. Each time a row is selected, another <o>uzi</o> object then sends a <m>bang</m> message to  <b>uzi 16</b> object which in turn sends out numbers for each x position or column. The x and y values are used both to determine which cell is being set and to calculate a value for each cell based on the mathematical equation in the <o>expr</o> object. The equation is relatively unimportant. It could be any formula that generates interesting data. In this case, we've chosen a formula that will produce a sinusoidal gradation of brightness in each column, and then cause the overall brightness of the columns to increase from left to right (i.e., as x increases). The important thing is that the method generates properly formatted <m>setcell</m> messages, with x and y coordinates and a valid value (0-255) for each cell. </p>

<illustration><img src="images/jitter_core - 6a.png"/></illustration>

<illustration><img src="images/jitter_core - 6b.png"/></illustration>


<p>The next method uses <o>jit.noise</o>, a great way to generate random values for every cell in a matrix. Each time it receives a <m>bang</m> message, the <o>jit.noise</o> object creates a random matrix of the specified dimensions and plane count. The result is a totally random arrangement of pixels.</p>

<illustration><img src="images/jitter_core - 6c.png"/></illustration>

<p>The third method uses a special object - <o>jit.expr</o>. The <o>jit.expr</o> object takes an input matrix and processes it based on the supplied expression. In the first example we are using <o>jit.noise</o> to supply the input matrix. Notice that the first set of expressions basically ignore the input values, only using the incoming matrix to determine the data type, plane count, and dimensions.</p>

<illustration><img src="images/jitter_core - 6d.png"/></illustration>

<p>The second set uses the colorbars image and the <i>in[0]</i> argument, which tells the object to use the value information for each cell of the incoming matrix (in this case, colorbars) as part of the calculation. For more on using <o>jit.expr</o>, check out the <a href="https://cycling74.com/2010/03/08/demystifying-expressions-in-jitter/"> Demystifying Expressions in Jitter</a> tutorial.</p>

<illustration><img src="images/jitter_core - 6e.png"/></illustration>



<h2>Copying Matrix Data - srcdim and destdim</h2>


<p>When we send a <m>jitter_matrix</m> message to another Jitter object, we tell the object to look up the matrix data somewhere in memory. By default, this usually means we are copying the entire matrix and then processing it with the same constraints. A 320x240 matrix going out is still a 320x240 matrix when it comes into the next destination. We’re going to look now at how to copy specific portions of a source matrix into a specific region of a destination matrix.</p>

<li>
	<openfilelink filename="jitter_core_-_6_-_Jitter_Matrix_Exploration_2.maxpat">Open the second example patcher</openfilelink>
</li>

<p>Here we use the <o>jit.matrix</o> attributes <i>usesrcdim</i> and <i>dstdim</i> to control how the matrix coming from <o>jit.movie</o> is copied into the <o>jit.matrix</o> object.</p>

<illustration><img src="images/jitter_core - 6f.png"/></illustration>

<p>As you explore the patch, switch between the colorbars and sunset images to get a better sense of how it works. Try enabling <i>usesrcdim</i> then manipulating the <i>srcdimstart</i> and <i>srcdimend</i> attribute values to select a portion of the color bars image to copy over. Next, try enabling <i>usedstdim</i> and adjusting the start and end points to determine where in the matrix the image will be displayed. As you adjust the values, you may notice portions of the previous image are left behind. You can remove them by using the <m>clear</m> message or by opening the <o>gate</o> next to the "auto clear" bubble.</p>

<p>Finally, when you are using a different number of pixels from one matrix to the next (either more or less), you will usually see some distortion or pixelation. Enabling the on <i>interp</i> attribute (i.e. <b>@interp 1</b>) will minimize this effect by interpolating or smoothing the data.</p>

<illustration><img src="images/jitter_core - 6g.png"/></illustration>


<div>
	<techdetail>

		<h2>Explore Further</h2>

		<p> <openfilelink filename="jitter_core_-_6_-_Jitter_Matrix_Exploration_3.maxpat">This patch</openfilelink> uses the <i>srcdim</i> and <i>dstdim</i> attributes to combine two images into a single <o>jit.matrix</o>. The secret here is that both <o>jit.matrix</o> objects share the same name and are triggered in sequence. The data from the righthand image is copied into the <o>jit.matrix</o> object before the data on the left, which then triggers the output and display. Notice how the lefthand image supersedes (covers) the one from the right when overlapping coordinates are given. This is one of many cases in Jitter where you’ll want to make sure one thing happens before another. For this reason, the <o>trigger</o> object is well-known among advanced Jitter users as an essential tool.</p>

		<p>For even more matrix filling options, take a look at <o>jit.gradient</o>, <o>jit.bfg</o>, <o>jit.gen</o> <o>jit.pix</o>.</p>


	</techdetail>
</div>
</chapter>
