Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

Behavior

Auto Save

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

              
                <!-- - Create your own art! :) -->
<!-- - Move your cursor to create art. Click anywhere in the screen to reset canvas and start again.   -->

<!-- - For mobile: touch + drag screen to create art. Touch to reset and start again. -->
              
            
!

CSS

              
                body {
	background-color: rgb(129, 136, 146);
	margin: 0;
	padding: 0;
	overflow: hidden;
}
              
            
!

JS

              
                /* 
 * GENERATIVE MOUSE ART
 * Made with p5 - Enjoy!
 * https://p5js.org/
 *
 * #004 - #100DaysOfCode
 * By ilithya | 2019
 */

/* Create array of colors */
/* Resource: 
* - https://javascript.info/array
*/
const paint = [
	'#3800a0', // dark purple
	'#670456', // dark violet
	'#fb8d61', // coral
	'#784ffd', // light purple
	'#418dff', // dark blue
	'#99e4fd', // light blue
];
const bgColor = 'rgb(129, 136, 146)';

function setup() {
	createCanvas(windowWidth, windowHeight);
	background(bgColor);
	
	strokeWeight(5);
	noSmooth();
	fill(paint[0]);
}

/* Create a function to draw the art to call it in more than one function */
/* Resource: 
* - https://javascript.info/function-basics
*/
const createGenerativeArt = () => {
	const shapeX = (windowWidth / 6);
	const shapeY = (windowHeight / 4);
	ellipse(mouseX, mouseY, random(10, shapeX), random(10, shapeY));
};
function mouseMoved() {	
	createGenerativeArt();
}
function touchMoved() {
	createGenerativeArt();
}

function checkIfMouseMoved() {
  if (mouseMoved) {
	const randomColor = random(paint);
	fill(randomColor);
  }
}
/* Set an interval of time to change the random color filling the ellipses */
/* Resource: 
* - https://javascript.info/settimeout-setinterval
*/
setInterval(checkIfMouseMoved, 500);

/* Create a function to clear the canvas to call it in more than one function */
const clearCanvas = () => {	
	clear();
	background(bgColor);
};
function mousePressed() {
	clearCanvas();
}
function touchStarted() {
	clearCanvas();
}
              
            
!
999px

Console