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

              
                <div class="wrapper" id="app">
  <input type="radio" name="drawing" value="lines" id="lines"/>
	<label for="lines" class="label">Lines</label>
	
	<input type="radio" name="drawing" value="triangles" id="triangles"/>
	<label for="triangles" class="label">Triangles</label>

	<input type="radio" name="drawing" value="joyDivision"  id="joyDivision"/>
	<label for="joyDivision" class="label">JoyDivision</label>
	
	<input type="range" name="size" id="size" class="slider" min="26" max="200" value="50"/>
	
	<div class="card">
		<form class="form" onsubmit="event.preventDefault();">
      <input type="text" placeholder="username"/>
      <input type="password" placeholder="password"/>
      <button>login</button>
    </form>
	</div>
</div>

<span class="credit">Code for pattern generation from <a href="https://generativeartistry.com/">generativeartistry.com</a> </span>

<script>
  if (CSS.paintWorklet) {
    CSS.paintWorklet.addModule('/lisilinhart/pen/LYEJWQQ.js');
  } else {
    document.body.classList.add('warning');
  }
	
	document.addEventListener("DOMContentLoaded",function(){
		let el = document.querySelector('#size');
		el.addEventListener('change', function(e) {
			let card = document.querySelector('.card');
			let value = e.target.value   
			card.style.setProperty('--size', value)
		});
	});

	
</script> 
              
            
!

CSS

              
                :root {
	--c-primary: #E0AF53;
	--c-secondary: #d1274b;
	--c-light: #f8f8f8;
}

// CSS Houdini
.card {
	background: var(--c-light);
	background-image: paint(generative);
	// Types: lines,joyDivision,triangles
	--type: var(--drawType, lines); 
	--size: 120;
	--line-color: #E0AF53;
	--line-width: 2;
}



// Pure CSS Variable Toggling
input[name="drawing"] {
	visibility: hidden;
	display: none;

	&:checked + label {
		background: var(--c-primary);
		color: var(--c-light);
	}
}

input[value="lines"]:checked ~ .card {
		--drawType: lines;
}

input[value="joyDivision"]:checked ~ .card {
		--drawType: joyDivision;
}

input[value="triangles"]:checked ~ .card {
	--drawType: triangles;
}

input[name="size"]{
	justify-self: center;
	align-self: center;
	grid-area: number;
	width: 100px;
}


// CSS Styling
.card {
	justify-self: center;
	align-self: center;
	grid-area: card;
	
	position: relative;
	display: flex;
	margin: 2em;
	width: 100%;
	height: 100vh;
	max-width: 520px;
	max-height: 400px;
	padding: 2em;
	box-shadow: 0 30px 60px 0 rgba(0, 0, 0, 0.2);
	border-radius: 2em;
}

.label {
	justify-self: center;
	align-self: center;
	font-family: "Roboto", sans-serif;
	font-weight: 700;
	letter-spacing: 0.1em;
	color: var(--c-primary);
	border: 2px solid var(--c-primary);
	font-size: 1.4em;
	padding: 0.3em 0.7em;
	border-radius: 0.5em;
	cursor: pointer;
	transition: all 0.3s cubic-bezier(0.39, 0.575, 0.565, 1);
	transition-property: background, color;
}

.form {
	position: relative;
	z-index: 1;
	max-width: 360px;
	margin: auto;
	padding: 45px;
	text-align: center;
}

.form input, .form-input {
	margin: 0 0 15px;
	padding: 15px;
	width: 100%;

	box-sizing: border-box;
	border-radius: .4em;
	font-size: 14px;
	background: rgba(255, 255, 255, 0.8);
	border: 0;
}
.form button {
	padding: 0.5em 0.2em;
	outline: 0;
	width: 100%;
	border: 0;
	border-radius: .4em;

	color: #ffffff;
	font-size: 1em;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	cursor: pointer;

	background: var(--c-primary);
	transition: background-color 0.2s cubic-bezier(0.39, 0.575, 0.565, 1);
}

.form button:hover,
.form button:active,
.form button:focus {
	background: var(--c-secondary);
}

.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 5px;  
  background: var(--c-light);
  outline: none;
  opacity: 0.7;
  transition: opacity .2s;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  border-radius: 50%; 
  background: var(--c-primary);
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: var(--c-primary);
  cursor: pointer;
}

body {
	background: #2b2b28;
	font-family: "Lora", sans-serif;
	font-size: 16px;
}

* {
	box-sizing: border-box;
}

.wrapper {
	position: relative;
	min-height: 100vh;
	padding: 50px 15px;
	display: grid;
	grid-template-columns: 1fr 1fr 1fr;
	grid-template-rows: 60px 20px 1fr;
	grid-gap: 20px;
	grid-template-areas: 
		"btn-1 btn-2 btn-3"
		". number ."
		"card card card";
	justify-content: space-around;
	align-items: center;
}

.warning:after {
	content: "Sorry your browser doesn't support the CSS Paint API!";
	position: fixed;
	top: 0;
	left: 0;
	text-align: center;
	width: 100%;
	padding: 1em 0;
	background: var(--c-primary);
	color: var(--c-light);
}

.credit {
	display: block;
	position: absolute;
	bottom: 30px;
	right: 30px;
	color: var(--c-light);

	a {
		color: inherit;
	}
}

              
            
!

JS

              
                if (typeof registerPaint !== "undefined") {
  registerPaint("generative", class {

    static get inputProperties() {
      return ["--type", "--size", "--line-color", "--line-width"];
    }

    drawLines(ctx, width, height, size) {
      for (var y = 0; y <= height; y += size) {
        for (var x = 0; x <= width; x += size) {
          var leftToRight = Math.random() >= 0.5;

          if (leftToRight) {
            ctx.moveTo(x, y + size);
            ctx.lineTo(x + size, y);
          } else {
            ctx.moveTo(x, y);
            ctx.lineTo(x + size, y + size);
          }

          ctx.stroke();
        }
      }
    }
		
		drawTriangles(ctx, width, height, size) {
			let line, dot,
				odd = false,
				lines = [],
				gap = size;
			
			for (let y = -40; y <= width + 40; y += gap) {
				odd = !odd;
				line = [];
				for (let x = -40; x <= width + 40; x += gap) {
					dot = {
						x: x + (odd ? gap / 2 : 0),
						y: y
					};
					line.push({
						x: x + (Math.random() * .8 - .4) * gap + (odd ? gap / 2 : 0),
						y: y + (Math.random() * .8 - .4) * gap
					});
					ctx.fill();
				}
				lines.push(line);
			}

			function drawTriangle(pointA, pointB, pointC) {
				ctx.beginPath();
				ctx.moveTo(pointA.x, pointA.y);
				ctx.lineTo(pointB.x, pointB.y);
				ctx.lineTo(pointC.x, pointC.y);
				ctx.lineTo(pointA.x, pointA.y);
				ctx.closePath();
				ctx.stroke();
			}
			
			let dotLine;
			odd = true;
			for(let y = 0; y < lines.length - 1; y++) {
				odd = !odd;
				dotLine = [];
				for(let i = 0; i < lines[y].length; i++) {
					dotLine.push(odd ? lines[y][i]   : lines[y+1][i]);
					dotLine.push(odd ? lines[y+1][i] : lines[y][i]);
				}
				for(let i = 0; i < dotLine.length - 2; i++) {
					drawTriangle(dotLine[i], dotLine[i+1], dotLine[i+2]);
				}
			}

		}
		
		drawJoyDivision(ctx, width, height, size) {
			var lines = [];
			let step = size / 2;

			// Create the lines
			for (var i = -40; i <= width + 40; i += step) {
				var line = [];
				for (var j = -40; j <= width + 40; j += step) {
					var distanceToCenter = Math.abs(j - width / 2);
					var variance = Math.max(width / 2 - 50 - distanceToCenter, 0);
					var random = Math.random() * variance / 2 * -1;
					var point = {
						x: j,
						y: i + random
					};
					line.push(point);
				}
				lines.push(line);
			}

			// Do the drawing
			for (var i = 0; i < lines.length; i++) {
				ctx.beginPath();
				ctx.moveTo(lines[i][0].x, lines[i][0].y);

				for (var j = 0; j < lines[i].length - 2; j++) {
					var xc = (lines[i][j].x + lines[i][j + 1].x) / 2;
					var yc = (lines[i][j].y + lines[i][j + 1].y) / 2;
					ctx.quadraticCurveTo(lines[i][j].x, lines[i][j].y, xc, yc);
				}

				ctx.quadraticCurveTo(lines[i][j].x, lines[i][j].y, lines[i][j + 1].x, lines[i][j + 1].y);
				ctx.save();
				ctx.globalCompositeOperation = 'destination-out';
				ctx.fill();
				ctx.restore();
				ctx.stroke();
			}
		}

    paint(ctx, geom, properties) {
      let drawType = String(properties.get("--type")).replace(' ', '');
      let size = Number(properties.get("--size"));
      let lineWidth = Number(properties.get("--line-width"));
      let lineColor = String(properties.get("--line-color"));

      let {
        width,
        height
      } = geom;
      ctx.lineWidth = lineWidth;
      ctx.strokeStyle = lineColor;
			
			const drawFunctions = {
				"lines":  () => this.drawLines(ctx, width, height, size),
				"joyDivision": () => this.drawJoyDivision(ctx, width, height, size),
				"triangles": () => this.drawTriangles(ctx, width, height, size),
			};
			
			drawFunctions[drawType]();
    }
  });
}



              
            
!
999px

Console