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.
// ZIM is a JavaScript Canvas Framework for coding creativity!
// https://zimjs.com - please visit to start a wonderful coding journey.
// The main site has banner sections of TEN excellent uses of ZIM.
// NOTE - we often make colorful things with shapes - that is our style
// ZIM can be used very well with images, etc. if that is your style
// sound is also no problem - but sometimes slows down CodePen's preview...
// ZIM provides many conveniences, components and controls
// to help designers, developers and artists create interactive media
// https://zimjs.com/about.html - why ZIM, features, applications
// https://zimjs.com/docs.html - expand open any feature for info and examples
// Here are CodePen examples with comments for learning:
// https://codepen.io/zimjs/pens/public - ZIM CodePen
// https://codepen.io/danzen/pens/public - ZIM Founder's CodePen
// https://codepen.io/zimjs/post/welcome-to-zim-on-codepen
// There are also many tutorials, videos and references here:
// https://zimjs.com/learn.html - ZIM Skool, ZIM Kids, ZIM Badges, etc.
// https://zimjs.com/code.html - ZIM Template, tools and more
// https://zimjs.com/slack/ - join us on *** Slack *** for discussion and support
// -----------------
// ZIM is powered by CreateJS so we import CreateJS and ZIM in CodePen settings
// We make a Frame object which makes a stage on an HTML canvas
// We then add objects to the stage and update the stage to see them
const frame = new Frame("fit", 1024, 768, purple, purple);
frame.on("ready", ()=>{ // ES6 Arrow Function - similar to function(){}
zog("ready from ZIM Frame"); // logs in console (F12 - choose console)
// often need below - so consider it part of the template
const stage = frame.stage;
let stageW = frame.width;
let stageH = frame.height;
// CODE HERE
// ES6 Class that extends a ZIM Container
class Bee extends Container {
constructor() {
super(80,40); // must call superclass - CreateJS requirement
let body = new Circle(30).siz(60,40).center(this); // this is the container
new Tile(new Rectangle(5,60,yellow), 6, 1, 5, 0).center(body).setMask(body);
body.cache(); // helps performance by turning vectors into bitmap
}
}
// We have purple slants that need to match against the HTML outercolor
// Relying on stage color can leave thin line artifact at edges during browser scaling
// Try it if you want - comment this out and set color (first purple in Frame call) to pink
new Rectangle(stageW, stageH, pink).addTo();
// bees behind Grim
const beesBack = new Container(stageW, stageH).rot(-5).sca(.8).alp(.6).centerReg();
// points of Blob came from here https://zimjs.com/nio/paths.html
const reaper = new Blob({
color:black,
points:[[-20,-142.4,0,0,-35.6,9.6,35.6,-9.6,"mirror"],[44.8,-78.3,0,0,-4.8,-28.8,41.6,-32,"free"],[160.9,-102.3,0,0,-28,-20,-31.4,3.1,"free"],[88.3,-68.3,0,0,23,-26.3,-38.6,-32.3,"free"],[69.6,4,0,0,-34.9,-40.6,42,48.7],[67.5,127.3,0,0,0,0,0,0,"none"],[2.4,121.6,0,0,36.7,0,-36.7,0,"mirror"],[-69.6,131.2,0,0,0,0,0,0,"none"],[-25.6,-3.2,0,0,24,47.4,-24,-47.4,"mirror"]],
interactive:false
}).sca(2.5).center().mov(0,100)
// make Grim move around at SLOW speed
.wiggle("x", stageW/2, 50, 100, 20000, 30000) // prop, start, min, max, minTime, maxTime
.wiggle("y", stageH/2+100, 20, 50, 20000, 30000);
const mouth = new Circle(10, dark).sca(1,.7).rot(-10).loc(-8, -105, reaper);
reaper.shape.cur(); // interactive false seems to keep cursor away so add to shape
// bees in front of Grim
const beesFront = new Container(stageW, stageH).rot(-5).centerReg();
// move the bees along with the reaper
Ticker.add(()=>{
beesBack.loc(reaper).mov(0,-200);
beesFront.loc(reaper).mov(0,-200);
})
// the two purple slants - fun!
new Rectangle(stageW+500, 400, purple).reg(0,400).loc(0,0).rot(3);
new Rectangle(stageW+500, 400, purple).loc(0,stageH).rot(-10);
// make bees and wiggle them FAST!
// add some to front and some to back depending on ternary operation
// condition?if true:if false
// i%2==0?beesBack:beesFront
loop(30, i=>{
let x = rand(stageW*.4, stageW*.54); // tweaked until liked
let y = rand(stageH*.2,stageH*.35);
let bee = new Bee()
.sca(.7)
.centerReg(i%2==0?beesBack:beesFront) // centerReg so goes in mouth properly
.loc(x,y)
.wiggle("x", x, 20, 400, 300, 500) // prop, start, min, max, minTime, maxTime
.wiggle("y", y, 20, 150, 300, 500)
.wiggle("rotation", 0, 10, 20, 1000, 2000);
});
// when clicked, animate bees into mouth
reaper.on("click", ()=>{
removeBees(beesBack);
removeBees(beesFront);
reaper.shape.cur("default");
}, null, true); // just once
function removeBees(bees) {
bees.loop((bee, i)=>{
// could use a series but need different location as time goes on
timeout(i*100, ()=>{
let locMouth = mouth.localToLocal(0,0, bees); // gets 0,0 of mouth in bees
bee.animate({
props:{x:locMouth.x, y:locMouth.y},
ease:"linear",
time:300,
call:()=>{bee.removeFrom()} // remove bee when animation is done
});
});
}, true); // loop backwards anytime removing from container
// fill reaper with bee pattern ;-)
// this helps make a little story
new Tile(new Rectangle(5,500,yellow), 40, 1, 5, 0)
.centerReg(reaper)
.ord(-1) // move under mouth in Blob
.rot(45)
.setMask(reaper)
.alp(0)
.animate({
props:{alpha:.1},
time:2000,
wait:1200
});
}
new Label("GIVE GRIM A HEART!", 50, "impact", white).rot(-10).loc(425, 713).alp(.2);
// we are animating so no need to update the stage
// stage.update(); // this is needed to show any changes
// DOCS FOR ITEMS USED
// https://zimjs.com/docs.html?item=Frame
// https://zimjs.com/docs.html?item=Container
// https://zimjs.com/docs.html?item=Circle
// https://zimjs.com/docs.html?item=Rectangle
// https://zimjs.com/docs.html?item=Blob
// https://zimjs.com/docs.html?item=Label
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=wiggle
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=cur
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=mov
// https://zimjs.com/docs.html?item=ord
// https://zimjs.com/docs.html?item=alp
// https://zimjs.com/docs.html?item=rot
// https://zimjs.com/docs.html?item=siz
// https://zimjs.com/docs.html?item=reg
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=removeFrom
// https://zimjs.com/docs.html?item=centerReg
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=setMask
// https://zimjs.com/docs.html?item=rand
// https://zimjs.com/docs.html?item=timeout
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=Ticker
// FOOTER
// call remote script to make ZIM Foundation for Creative Coding icon
createIcon();
createGreet(null, 70);
createCode(null, 130);
}); // end of ready
Also see: Tab Triggers