Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <section class="left"><script src="sketch.js"></script></section>
    <section class="right"><p>for some reason, the numeric pad doesn't work. Use SHIFT and the key number... </p>
<h2>Test d'Interactions</h2>
<h3>MOUSE</h3>
<ul>
 	<li>Mouse X and Mouse Y = position of the shape</li>
 	<li>left click = new random saturation level</li>
</ul>
<h3>KEYS¶</h3>
<ul>
 	<li>z : erase</li>
 	<li>g : displays a 'générique" for some time and returns to screen</li>
 	<li>w : save png of the whole screen</li>
 	<li>b : save very large tif of the whole screen</li>
 	<li>r : start pdf recording</li>
 	<li>e : start pdf recording</li>
 	<li>p : save one frame only to pdf file</li>
 	<li>1 : hue 0 to 120</li>
 	<li>2 : hue 120 to 240</li>
 	<li>3 : hue 240 to 360</li>
</ul>
    </section>
    
  </body>
</html>

              
            
!

CSS

              
                html, body {
  margin: 0;
  padding: 0;
}

body{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  flex-direction: row
}

.right {
  
}



              
            
!

JS

              
                /* A faire 
* Teste les vareractions entre le sketch et le clavier ou la souris
* teste des méthodes de sauvegarde de l'écran ou d'une ou plusieurs frame
* en pdf ou en image png, tif, ...
* 
* Peut produire des images plus grandes que l'écran 

* Les sources principales 
* Sur les intereractions, et principes généraux de sauvegarde
    * P_2_0_03.pde ( livre Generative Design) 
    * https://github.com/generative-design/Code-Package-Processing-3.x/blob/master/01_P/P_2_0_03/P_2_0_03.pde
    * https://github.com/jeffThompson/ProcessingTeachingSketches/blob/master/Basics/PDF_Export/PDF_Export.pde
    * https://github.com/jeffThompson/ProcessingTeachingSketches/blob/master/Basics/SaveStillImage/SaveStillImage.pde 

* sur la façon de créer une image beaucoup plus grande que le canevas / écran
    * en img png, tif ou autre
    * en pdf (mais seulement pour une frame)
    * https://stackoverflow.com/questions/33816798/can-i-save-a-sketch-in-a-different-resolution-than-the-createCanvas-in-processing
    * et aussi idée 16 https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/

* sur la façon de créer un générique varéressant, idées 14 & 15 de 
* https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/

* Constrain an object within a circle ! 
* idea 23 https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/

* voir https://processing.org/tutorials/prvar/ pour comprendre
    - diff image vectorielle ou raster
    - record pdf sauve tout ce qui est dessiné sur l'écran à partir du moment où on commence l'enregistrement
    - explique aussi comment faire des dessins avec une beaucoup plus grande taille que l'écran

* pour la création de pdf en javascript
* on peut voir avec http://zenozeng.github.io/p5.js-pdf/examples/#basic
*/

/* Interactions
* MOUSE
* Mouse X and Mouse Y = position of the shape
* left click          : new random saturation level

 /* KEYS
 * z                   : erase
 * g                   : displays a 'générique" for some time and returns to screen  
 * w                   : save png of the whole screen
 * b                   : save very large tif of the whole screen 
 * r                   : start pdf recording
 * e                   : start pdf recording
 * p                  : save one frame only to pdf file
 * 1                   : hue 0 to 120
 * 2                   : hue 120 to 240
 * 3                   : hue 240 to 360
 */
 
'use strict';
 
var recordPDF = false;
var saveOneFrame = false;

// pour l'écran de "générique"
var blinker;
var timer = -3000;
var gener = false ; // true (si appui sur g) => afficher le générique 

var r ;            // radius
var hue ;        // HUE of shape
var compHue;      // complementary hue
var sat ;        // saturation of shape's color

function setup() {

  createCanvas(600, 400) ;
  colorMode(HSB, 360, 100, 100, 100); 
  

  r = 40 ;
  hue = 0 ;
  compHue = 0 ;
  sat = 50 ;
  background(0,0,99,100) ;  // white

}

function draw() {
  if(saveOneFrame == true) {
        beginRecord(PDF, "framePDF/" + timestamp() + ".pdf"); 
  }
  
  if (gener) {
    
    drawGener() ;
    
  } else {
  
    smooth();
    strokeWeight(6);
    compHue = compl( hue) ;
    stroke( compHue, sat, 100, 70 );
    fill( hue, sat, 100, 70 );
    ellipse( mouseX, mouseY, r, r );
  }
  if(saveOneFrame == true) {
      endRecord();
      saveOneFrame = false;
    }
}

function compl( hue) {

  var ch = (hue + 180) % 360  ; // modulo 360 to make it a wheel !
  return ch ;
z
}


/* Affiche un écran de générique 
* jusqu'à ce que gener redevienne false
*/
function drawGener() {
  
  // idées 14 & 15 de 
  //  https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/

  background(255);
  fill(0);
  text("you are in frame: " + frameCount,50,50);
  text(millis()/1000 + " seconds have passed since the start", 50,100);
  text("this text will be here forever",50,150);
  if (frameCount < 500) {
    text("this text will be here for 500 frames",50,200);
  }
  if (frameCount > 800) {
    text("this text will be here from 800 frames onwards",50,200);
  }
  if (millis() < 8000) {
    text("this text will be here the first 8 seconds",50,250);
  }
  if (millis() > 12000) {
    text("this text will be here from 12 seconds onwards",50,250);
  }
  if (frameCount % 12 == 0) { blinker = !blinker; }
  if (blinker) {
    text("this text will blink",50,300);
  }
  if (millis() - timer < 3000) {
    text("this text will be here 3 secs after pressing a key",50,350);
  }
}


function mouseReleased() {
  sat = random(50, 100) ;
  print ("sat", sat) ;
}
233
function keyReleased() {
	
	/* KEYS
	 * del, backspace or z	: erase
	 * g                   	: displays a 'générique" for some time and returns to screen  
	 * w                   	: save png of the whole screen
	 * r                   	: start pdf recording
	 * e                   	: start pdf recording
	 * p                  	: save one frame only to pdf file
	 * 1                   	: hue 0 to 120
	 * 2                   	: hue 120 to 240
	 * 3                   	: hue 240 to 360
	 */
  if (keyCode == DELETE || keyCode == BACKSPACE || ( key == 'z' || key == 'Z' ) ) {
	
	background(0,0,99,100) ; // RAZ écran  
	  
  } 
  if (key == 'g' || key == 'G') {
	  
	gener = !gener ; // toggle gener
    timer = millis();
    background(0,0,99,100) ; // RAZ écran
  }
  if (key == 'p' || key == 'P') saveOneFrame = true ;
  if (key == 's' || key == 'S') saveCanvas(gd.timestamp(), 'png');

  if (key == '1') hue = random(0, 120) ;
  if (key == '2') hue = random(120, 240) ;
  if (key == '3') hue = random(240, 360);

  if (key == 'r' || key == 'R') {

  // ------ pdf record and export ------
    if (recordPDF == false) {
      beginRecord(PDF, "PDFrec/" + timestamp()+".pdf");
      println("recording started");
      recordPDF = true;
      colorMode(HSB, 360, 100, 100, 100);
      smooth();
      noFill();
      background(360);
    } else if (recordPDF) {
      println("recording stopped");
      endRecord();
      recordPDF = false;
      background(360); 
    }	  

  }
  if (key == 'w' || key == 'W') saveCanvas("Wsaved/" + timestamp() + "_##.png");

}

// see translation in https://gist.github.com/espinielli/f0366ad2c356b8ac3cfd
function timestamp() {
   var now = new Date();
   return  now.toISOString();
}

              
            
!
999px

Console