/ p5.js / P_4_1_2_02

// P_4_2_2_01
//
// Generative Gestaltung, ISBN: 978-3-87439-759-9
// First Edition, Hermann Schmidt, Mainz, 2009
// Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
// Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni
//
// http://www.generative-gestaltung.de
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
 * simple overview of a video file.
 * 
 * KEYS
 * s : save png
 */

var movie;

// horizontal and vertical grid count
// take care of the aspect ratio ... here 4:3
var tileCountX = 3*5;
var tileCountY = 4*5;
var tileWidth, tileHeight;
var imageCount = tileCountX*tileCountY; 
var currentImage = 0;
var gridX = 0;
var gridY = 0;

function setup() {
  createCanvas(780, 585);
  smooth();
  background(0); 
  movie = createVideo("01.mp4")
  movie.hide();
  movie.play();
  tileWidth = width / tileCountX;
  tileHeight = height / tileCountY;
  frameRate(2);
}

function draw() {
  var posX = tileWidth*gridX;
  var posY = tileHeight*gridY;

  // calculate the current time in movieclip
  var moviePos = map(currentImage, 0,imageCount, 0,movie.duration());
  //movie.jump(moviePos);
  //movie.read();
  image(movie, posX, posY, tileWidth, tileHeight);

  // new grid position
  gridX++;
  if (gridX >= tileCountX) {
    gridX = 0;
    gridY++;
  }
  currentImage++;
  if (currentImage >= imageCount) noLoop();
}

function keyTyped() {
  if (key == 's' || key == 'S') save("P_4_2_2_01.png");
}