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.
<!-- Steven Universe: Ameythest https://zzz.dog/
https://steven-universe.fandom.com/wiki/Amethyst
-->
<canvas class="zdog-canvas" width="500px" height="600"></canvas>
.zdog-canvas {
cursor: move;
}
html { height: 100%; }
body {
min-height: 100%;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
background: #435;
color: white;
font-family: sans-serif;
text-align: center;
}
canvas {
display: block;
margin: 0 auto;
cursor: move;
}
const TAU = Zdog.TAU;
const offWhite='#FED';
const skin = '#B998CA';
const shirt='#19151D';
const pants='#656D8E';
const shoe='#FBE8FD';
const garnet='#19151D';
const eggplant='#636';
const hair="#DCD3EF";
const gemstone="#DB68FF";
var glow = 'hsla(286,100%,30%)';
var shadow = 'hsla(286,100%,.10%,20%)'
function setup() {
noCanvas();
}
let illo = new Zdog.Illustration({
element: '.zdog-canvas',
zoom: 10,
dragRotate: true,
// rotate for three-quarters view
// rotate: { y: -Zdog.TAU/8 },
});
// ---- model ---- //
let hipX = 3.4;
let hips = new Zdog.Shape({
addTo: illo,
path: [ { x: -hipX }, { x: hipX }
],
stroke: 5,
// move down a little
translate: { y: 2 },
// rotate: { x: TAU/8 },
color: shirt,
});
let leg = new Zdog.Shape({
addTo: hips,
path: [ { y: 4 }, { y: 10 } ],
translate: { x: -hipX },
// rotate leg
// rotate: { x: TAU/4 },
color: pants,
stroke: 5,
fill:true,
});
// foot
let foot = new Zdog.RoundedRect({
addTo: leg,
width: 2,
height: 4,
cornerRadius: 1,
// y: past leg end, z: scootch toward front
translate: { y: 14, z: 2 },
// rotate 90° along x-axis
rotate: { x: Zdog.TAU/4 },
color: shoe,
fill: true,
stroke: 4,
});
let standLeg =leg.copy({
// position on right
translate: { x: hipX },
// rotate leg
rotate: { x: -TAU/8 },
});
let shadowspot =
new Zdog.Cone({
addTo: hips,
diameter: 30,
length: 0,
stroke: 0,
color: shadow,
translate: {y:17.2},
backface: true,
rotate: {x: TAU/4.2},
});
// new Zdog.Ellipse({
// addTo: hips,
// diameter: 1,
// stroke: 20,
// color: shadow,
// translate: {y:20},
// rotate: {z: TAU/2},
// });
let star = new Zdog.Shape({
addTo: leg,
translate: { x: -hipX/2, y:4.5, z:2.4 },
path: [
{line: {x:1.00, y:.10}},
{line: {x:.40, y:1.98}},
{line: {x:1.90, y:.78}},
{line: {x:.10, y:.78}},
{line: {x:1.60, y:1.98}}
],
stroke: .8,
scale:1.6,
color: shirt,
fill: true
});
star.copy ({
addTo:standLeg,
});
// standfoot
foot.copy ({
addTo:standLeg,
rotate: { x: -TAU/8}
})
// separate anchor just for rotating upper body
let spine = new Zdog.Anchor({
addTo: hips,
// rotate: { x: TAU/8 },
});
let chest = new Zdog.Shape({
addTo: spine,
path: [ { x: -1.5 }, { x: 1.5 } ],
// position right above hips
// ( hips.stroke + chest.stroke ) / 2
translate: { y: -6.5 },
stroke: 10,
color: garnet,
});
let gem = new Zdog.Hemisphere({
addTo: illo,
diameter: 3,
translate: { y: -4.5,z: 4.2},
// fill enabled by default
// disable stroke for crisp edge
stroke: false,
color: gemstone,
backface: pants,
});
gem.copy ({
addTo:gem,
rotate: { x: -TAU/2},
translate: { y:0, z:-.21},
diameter: 3.6,
color:shirt,
backface: glow,
})
let waist = new Zdog.Shape({
addTo: spine,
path: [ { x: -hipX }, { x: hipX }
],
stroke: 2,
translate: { y: -2 },
color: shirt,
});
var armSize = 6;
// left arm
let upperArm = new Zdog.Shape({
addTo: chest,
path: [ { y: 0 }, { y: armSize } ],
translate: { x: -5 , y: -2},
rotate: { x: -TAU/4 },
color: skin,
stroke: 5,
});
let forearm = new Zdog.Shape({
addTo: upperArm,
path: [ { y: 0 }, { y: armSize } ],
translate: { y: armSize},
rotate: { x: TAU/8 },
color: skin,
stroke: 4,
});
// hand
let hand = new Zdog.Shape({
addTo: forearm,
// connect to end of forearm
// scootch toward front a bit
translate: { y: armSize, z: 1 },
stroke: 5,
color: skin,
});
// arm on right
upperArm.copyGraph({
translate: { x: 6, y: -1 },
// rotate forward 90°
rotate: { x: TAU/8, z: -TAU/15, y: TAU/20 },
});
let head = new Zdog.Shape({
addTo: chest,
stroke: 12,
color: skin,
translate: {y:-10.5},
});
let noseOutline = new Zdog.Ellipse({
addTo: head,
diameter: -2.0,
quarters: 2, // semi-circle
translate: { x: 0, y: .5, z: 4.5 },
// rotate semi-circle to down
rotate: { z: -TAU/4 },
color: shirt,
stroke: 0.8,
// hide when front-side is facing back
backface: false,
});
let nose = new Zdog.Hemisphere({
addTo: head,
diameter: 2.4,
translate: { y: .6,z: 5.5},
// fill enabled by default
// disable stroke for crisp edge
stroke: false,
color: skin,
backface: skin,
});
let neck = new Zdog.Ellipse({
addTo: chest,
diameter: 4,
// quarters: 2, // semi-circle
translate: { x: 0, y: -4, z: 1.4 },
rotate: { x: TAU/10},
color: skin,
fill: true,
});
let eye = new Zdog.Ellipse({
addTo: head,
diameter: 2.4,
translate: { x: -2.5, y: -1.2, z: 4.5 },
color: '#fff',
stroke: 0.5,
fill: true,
});
let pupil = new Zdog.Ellipse({
addTo: eye,
diameter: .4,
translate: { x: 0, y: .4, z: .2 },
color: '#000',
stroke: 0.5,
fill: true,
});
// eye on right
eye.copy({
translate: { x: 2.5, y: -1.2, z: 4.5 },
});
pupil.copy({
translate: { x: 5, y: .4, z: .2 },
});
// smile
new Zdog.Ellipse({
addTo: head,
diameter: 6,
quarters: 1,
translate: { x: -.2, y: .7, z: 4.5 },
rotate: { z: TAU/3 },
closed: true,
color: '#FFF',
stroke: 0.5,
fill: true,
backface: false,
});
// hair started from from example
// https://codepen.io/desandro/pen/RQeYYp?editors=0010 //
// hair ball
new Zdog.Shape({
path: [
{ x: -1 },
{ x: 1 },
{ z: -4 },
],
addTo: head,
translate: { y: -4, z: -1 },
stroke: 15,
color: hair,
});
var bang = new Zdog.Shape({
path: [
{},
{ arc: [
{ z: 5, y: 4 },
{ z: -2, y: 16 },
]},
],
addTo: head,
translate: { x: -1.4, y: -7.5, z: 2 },
rotate: { x: 0.8, z: -0.4 },
stroke: 3,
color: hair,
closed: false,
});
bang.copy({
translate: { x: 5, y: -6, z: 5 },
rotate: { x: -0.3, z: -0.5 },
color: hair,
stroke: 5,
});
bang.copy({
translate: { x: 5, y: -6, z: 3 },
rotate: { y: -0.7, z: -1 },
color: hair,
stroke: 5,
});
bang.copy({
translate: { x: -2, y: -6, z: 3 },
rotate: { y: 180, z: 1 },
color: hair,
stroke: 3,
});
// hair covers the entry point of strands
new Zdog.Shape({
path: [
{ x: -3 },
{ x: 3 },
],
addTo: head,
stroke: 7,
translate: { y: -8, z: 5 },
color: hair,
});
// trail locks
var trailLock = new Zdog.Shape({
path: [
{ y: -4, z: 0 ,x:3 }, //start
{ bezier: [
{ y: -10, z: -4}, //start control pt
{ y: 25, z: -6}, //end ctrl pt
{ y: 20, z: -14, x:-15} //end
]},
],
addTo: head,
translate: { z: -3, y: 0 },
stroke: 4,
color: hair,
closed: false,
});
trailLock.copy({
translate: { x: -3, z: -4 },
// rotate: { z: -TAU/8 },
// stroke: 8,
});
trailLock.copy({
translate: { x: 3, z: -4 },
// rotate: { z: TAU/8 },
// stroke: 8,
});
trailLock.copy({
translate: { y: 2 },
// rotate: { z: TAU/2 },
scale: { y: 0.5 },
stroke: 8,
});
// -- animate --- //
function animate() {
illo.updateRenderGraph();
requestAnimationFrame( animate );
}
animate();
Also see: Tab Triggers