Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Exploring the attribute matrix

From: Interactive Data Visualization with Processing

Video: Exploring the attribute matrix

Once you've gone through the effort of creating transformations in your drawing by translating the origin or changing the scale of the grid or rotating or you've gone through working on the attribute by changing the color or dimensions or methods of joining objects in your drawing, you want be able to save those things even if you want to temporarily suspend them and bring them back without having to code all over again. Fortunately, Processing gives you an easy way to do this with what's called the pushMatrix and popMatrix commands as well as the pushStyle and popStyle.

Exploring the attribute matrix

Once you've gone through the effort of creating transformations in your drawing by translating the origin or changing the scale of the grid or rotating or you've gone through working on the attribute by changing the color or dimensions or methods of joining objects in your drawing, you want be able to save those things even if you want to temporarily suspend them and bring them back without having to code all over again. Fortunately, Processing gives you an easy way to do this with what's called the pushMatrix and popMatrix commands as well as the pushStyle and popStyle.

And I'll show you how each of those things works in this particular drawing. We are going to start by putting a little comment with the name of the sketch and then I've previously entered a color array. I am just going to paste that in right here and then I'll create a new array of colors that I'll just called palette and copy the one called crowds. This lets me use palette as a generic reference in my drawing. I'm going to have one variable that I use as s for size. It specifies the dimensions of the squares that I'll be drawing in this.

Then I'm going to start going through some of my setup material. I'm going to do size for the window, 600x200. Then I'll be using anti-aliasing. I'm going to turn off the stroke, no border on it for right now and I'm going to put in the background that is the first color in the palette. Now from there I'm going to draw my first rectangle and going to fill palette, and then go in rectangle. I'm going to put it right up in the origin.

The top-left corner will be right at the corner and that's going to be my first rectangle. So it's drawn right up there in the corner. Its top left is 00 and then it is 80 pixels wide and 80 pixels tall. So that's fine. So that's my first one. Then what I'm going to do is I'm going to push the matrix and I'm going to push the style. What this is going to do is going to save the matrix that I have that has no transformations on it.

So the origin still at the top left and the scale is the same, there's no rotations. It's also going to take the fill and the stroke settings that I have so far and save those. It's just pushing them off to the side and then what I can do is that I can start making some transformations. So for instance I'll translate the origin 230 pixels over and 25 down and then I'll rescale things and make them all twice as big by doing scale 2 and then I'll rotate and then I'll do radians function because, I want to do just 45 degrees and this is an easy way to specify it.

Now I'm going to change this stroke to the third color on the palette and I'll change the strokeWeight as well and make it 15 pixels. Previously, I had this stroke turned off entirely. Then I'll change the fill to the second color on the palette and then I'll draw my rectangle and again it will be at 0, 0, S, S. It has the same arguments as one what I had earlier. I could have just copied it and pasted it down here.

I save that and now you see that I have a very different drawing. This rectangle is rotated, it's much larger, it's got a border. It's a different beast than what we had previously. Now here's an interesting thing that I can do is I can actually pop the matrix back to where it was before and what that does is the matrix has do with the translation moving the origin, the scale, changing the size of grid, and the rotation. So now I'm going back to what it was before and it was untransformed. So it's undoing all those things. So now I can do a rectangle.

I'll just copy that information. I'm going change the dimensions a little bit. I'm going to change location manually to 380 pixels over and 20 pixels down and when I run that you see what happens is I've gone back to the same orientation, but you see that the fill and the borders are still the same. Now the borders look smaller, but that's also because the scale is only half as big at this moment. Then I'm going to finish by changing back to what we had with the original styles by using popStyle.

In this case, I'm going to draw one more rectangle and I'm going to specify it a little differently. I want it to be down in the bottom corner so I'm going to do that its top corner is the width-s, that's the size and its height of that. It's going to be the height-s, and I believe that that should do it and get his back to the mirror image of the original rectangle. So what I've done is I created with one set of attributes and the grid in a particular way, I changed its grid, I changed the attributes, and then I was able to restore what I had previously by having used pushMatrix and then popping the matrix back and then pushStyles and popping the style back.

This is one way to save the work that you've done and go into it. Now you can also know that you can nest these. If you want to push the matrix more than once, you can. All you have to remember is it's the last in-first out method that when you reach back in into popMatrix it's going to bring back the matrix it was the last one used. So with these tools, the pushMatrix and popMatrix and the pushStyle and popStyle, you can save a lot of time in setting up your drawings and getting them to be exactly the way that you want them to.

Show transcript

This video is part of

Image for Interactive Data Visualization with Processing
Interactive Data Visualization with Processing

72 video lessons · 12238 viewers

Barton Poulson
Author

 
Expand all | Collapse all
  1. 3m 16s
    1. Welcome
      58s
    2. What you should know
      1m 22s
    3. Using the exercise files
      56s
  2. 11m 51s
    1. Overview of data visualization
      11m 51s
  3. 11m 53s
    1. Installing Processing
      3m 38s
    2. Overview of Processing
      4m 5s
    3. Exploring libraries
      4m 10s
  4. 1h 1m
    1. Basic setup
      7m 31s
    2. Drawing points
      4m 37s
    3. Drawing lines
      5m 6s
    4. Drawing ellipses and circles
      5m 24s
    5. Drawing arcs
      6m 54s
    6. Drawing rectangles and squares
      4m 58s
    7. Drawing quadrangles
      3m 25s
    8. Drawing triangles
      2m 55s
    9. Drawing polygons
      3m 37s
    10. Drawing simple curves
      4m 54s
    11. Drawing complex curves
      6m 46s
    12. Drawing Bézier curves
      5m 38s
  5. 54m 3s
    1. Introduction to variables
      10m 44s
    2. Understanding variable scope
      6m 53s
    3. Modifying variables
      9m 8s
    4. Creating arrays
      9m 53s
    5. Modifying arrays
      6m 37s
    6. Creating strings
      7m 3s
    7. Modifying strings
      3m 45s
  6. 1h 2m
    1. Incorporating randomness
      7m 59s
    2. Using Perlin noise
      4m 24s
    3. Shuffling with Java
      3m 30s
    4. Specifying line attributes
      8m 2s
    5. Changing placement modes
      5m 45s
    6. Understanding color attributes and functions
      4m 16s
    7. Exploring color spaces
      7m 44s
    8. Using color palettes
      7m 5s
    9. Transforming the grid
      8m 38s
    10. Exploring the attribute matrix
      5m 33s
  7. 52m 7s
    1. Building code blocks
      5m 57s
    2. Writing a while loop
      3m 52s
    3. Using for loops
      5m 35s
    4. Creating conditionals
      14m 50s
    5. Working with easing
      10m 51s
    6. Creating spirals
      11m 2s
  8. 18m 55s
    1. Mouse tracking
      3m 54s
    2. Hovering and clicking
      11m 16s
    3. Understanding keyboard interaction
      3m 45s
  9. 27m 32s
    1. Specifying fonts
      6m 43s
    2. Using images
      5m 51s
    3. Playing a video loop
      6m 20s
    4. Exporting video
      3m 47s
    5. Adding sound
      4m 51s
  10. 20m 49s
    1. Creating functions
      11m 48s
    2. Creating classes and objects
      9m 1s
  11. 31m 10s
    1. Using embedded data
      5m 26s
    2. Working with appended text data
      6m 4s
    3. Working with appended tabular data
      10m 26s
    4. Reading XML data
      9m 14s
  12. 48m 17s
    1. Generating dot plots
      11m 11s
    2. Building scatter plots
      10m 0s
    3. Making line plots
      9m 55s
    4. Creating bar charts
      9m 12s
    5. Checking out examples of maps, hierarchies, and networks
      7m 59s
  13. 20m 57s
    1. Introducing some principles of 2D design
      13m 44s
    2. Understanding color theory
      7m 13s
  14. 24m 46s
    1. Interacting with zooming, rotating, and sliding
      6m 26s
    2. Implementing slicing
      6m 47s
    3. Using rollovers
      5m 58s
    4. Introducing the GUI libraries
      5m 35s
  15. 10m 35s
    1. Sharing via OpenProcessing and other sites
      3m 19s
    2. Saving as a desktop application
      2m 42s
    3. Saving as JavaScript
      1m 47s
    4. Saving as an Android application
      2m 47s
  16. 2m 38s
    1. Where to go from here
      2m 38s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Interactive Data Visualization with Processing.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.