HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
html, body {
margin: 0;
padding: 0;
}
body{
display: flex;
flex-wrap: wrap;
align-items: center;
flex-direction: row
}
.right {
}
/* 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();
}
Also see: Tab Triggers