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.
const frame = new Frame("fit", 1024, 768, green, dark);
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
let stage = frame.stage;
let stageW = frame.width;
let stageH = frame.height;
// REFERENCES for ZIM at http://zimjs.com
// see http://zimjs.com/learn.html for video and code tutorials
// see http://zimjs.com/docs.html for documentation
// see https://www.youtube.com/watch?v=pUjHFptXspM for INTRO to ZIM
// see https://www.youtube.com/watch?v=v7OT0YrDWiY for INTRO to CODE
// APP CREATED FOR PRAGMA for the language of Beryea
// CODE HERE
STYLE = {
type:{
Stepper:{
scale:.3,
shadowBlur:-1,
stepperType:"number",
min:0,
max:100,
continuous:true
},
TextArea:{
width:140, height:250, color:white
},
Tile:{
align:"center",
clone:false
}
}
}
// OVERVIEW
// The syllables are made of 6 parts
// The sliders give the odds out of 100 of the part being used
// The textAreas show the options for the parts
// These have a default weight of 10 but can be overridden with _num
// So "v_5" would mean v would be half as likely to be picked and "v_20" twice as likely
// The data from the sliders, textareas and answer field gets saved any time it is changed
// this is saved to the local computer not across computers although that could be set up
// Could have used arrays here - but these are the code letters the client uses
// so wanted her to be able to see what was going on in here and adjust if needed
const c = new Stepper().change(saveData);
const w = new Stepper().change(saveData);
const l = new Stepper().change(saveData);
const v = new Stepper().change(saveData);
const m = new Stepper().change(saveData); // w2
const o = new Stepper().change(saveData);
const C = new TextArea();
const W = new TextArea();
const L = new TextArea();
const V = new TextArea();
const M = new TextArea(); // W2
const O = new TextArea();
const parts = new Tile(series(c,w,l,v,m,o,C,W,L,V,M,O), 6, 2, 15, 15).center().pos(null,70,null,true)
// parts.loop(part=>{if (part.tag) part.tag.style.overflowY = "scroll";}); // if scroll is needed
parts.loop(part=>{if (part.type=="TextArea") part.on("input", saveData)});
new Rectangle(parts.width*1.05, parts.height*1.1, pink, null, null, 5).center(parts).addTo(stage).bot();
new Label("* Steppers set percent likelyhood of inclusion.").loc(parts).sca(.4).alp(.4).mov(0,-40);
new Label("* There are internal exlusion settings - see code.").loc(parts).sca(.4).alp(.4).mov(610,-40);
new Label("* Default weight is 10. Eg. use \"w_5\" for half weight on w, \"w_20\" for twice weight on w, etc. What you set and type is saved on this computer.").loc(parts).sca(.4).alp(.4).mov(0,parts.height+30);
// Slider values will be overridden if the user has changed the values
c.currentValue = 50;
w.currentValue = 20;
l.currentValue = 30;
v.currentValue = 100;
m.currentValue = 30;
o.currentValue = 50;
// TextArea values will be overridden if the user has changed the values
C.text = "p, b, t, d, k, g, m, n, f, v, th_2, dh_2, s, z, x, j, l, r, ps, ts, ks, ty, dy, xy, jy, ky, gy, w, y";
W.text = "w, y";
L.text = "l, r";
M.text = "w, y";
V.text = "a, e, i, o, u, á_4, é, í, ó_4, ú_4";
O.text = "p, b, t, d, k, g, m, n, f, v, th_2, dh_2, s, z, x, j, l, r, ps, ts, ks, bz, dz, gz, ty, dy, xy, jy, ky, gy, w, y";
// FILTERS
// these are filters so for instance, if part O has an l or an r then don't use an L part
const badOforL = ["l", "r"];
// if part O has any of these then don't have a part W or part L
const badOforWL = ["ty", "dy", "xy", "jy", "ky", "gy", "w", "y"];
// if part C has any of these then don't have a part M (W2)
const badCforM = ["w", "y"];
const button = new Button({
width:220,
label:"CREATE",
wait:"CONFIRM",
waitTime:4000,
waitBacking:pizzazz.makePattern({
type:"slants",
backgroundColor:purple,
colors:red,
size:30,
interval:1600
}),
waitModal:true,
corner:5,
backgroundColor:orange,
rollBackgroundColor:purple,
shadowBlur:-1,
gradient:.1
})
.sca(.7).center().mov(0,-50)
button.on("mousedown", function(){
if (button.waiting) makeSyllables();
});
function makeSyllables() {
// GET ARRAYS OF WEIGHTED OPTIONS FOR EACH PART
// getList() gets an array of all the items in the textArea
// and then adds each one ten times unless there is an _num suffix
// if there is an _num then it adds that many copies to the list
// for instance, if v_5 then all letters get added 10 times, v gets added 5 times
// if v_50 then all letters get added 10 times and v gets added 50 times
getList(C);
getList(W);
getList(L);
getList(V);
getList(M); // W2
getList(O);
const answers = []; // an array to hold all of the created syllables
// make 50 syllables
loop(50, function () {
// these will temporarily store the values (if there are) of the parts for each syllable
var oo = ""; var cc = ""; var ll = ""; var ww = ""; var vv = ""; var mm = "";
// if a random number out of 100 is less than the slider value then add the part choice to the syllable
// the part choice is from the getList() arrays for each part which is shuffled and the first one is chosen
// if there is a list.indexOf(value) then it will return -1 if the value is not in the list
// So for below, if the rand 100 is less than the slider value
// and the chosen part is not in the bad list then include the part in the syllable
if (rand(100) <= o.currentValue) oo = shuffle(O.list)[0];
if (rand(100) <= c.currentValue) cc = shuffle(C.list)[0];
if (rand(100) <= l.currentValue && badOforL.indexOf(oo)<0 && badOforWL.indexOf(oo)<0) ll = shuffle(L.list)[0];
if (rand(100) <= w.currentValue && badOforWL.indexOf(oo)<0) ww = shuffle(W.list)[0];
if (rand(100) <= v.currentValue) vv = shuffle(V.list)[0];
if (rand(100) <= m.currentValue && badCforM.indexOf(cc)<0) mm = shuffle(M.list)[0];
// add the parts to the syllable
answers.push(oo + ll + ww + vv + mm + cc);
})
answer.text = answers.join(", "); // join the array into a big long string
saveData();
button.clearWait();
}
function getList(field) {
field.temp = field.text.split(/,\s*/);
field.list = [];
loop(field.temp, options=>{ // loop through all the options
var opt = options.split("_");
// if _num then copy num times otherwise copy 10 times
loop(opt.length>1?Number(opt[1]):10, ()=>{field.list.push(opt[0]);});
});
}
const answer = new TextArea({width:800, height:150, size:26}).center().mov(0,-180);
answer.on("input", saveData);
if (localStorage) {
data = {};
if (localStorage.syllableData) {
data = JSON.parse(localStorage.syllableData);
c.currentValue = data.c;
w.currentValue = data.w;
l.currentValue = data.l;
v.currentValue = data.v;
m.currentValue = data.m;
o.currentValue = data.o;
C.text = data.C;
W.text = data.W;
L.text = data.L;
M.text = data.M;
V.text = data.V;
O.text = data.O;
answer.text = data.answer;
}
}
function saveData() {
if (localStorage) {
data = {};
data.w = w.currentValue;
data.c = c.currentValue;
data.m = m.currentValue;
data.l = l.currentValue;
data.v = v.currentValue;
data.o = o.currentValue;
data.C = C.text;
data.W = W.text;
data.L = L.text;
data.M = M.text;
data.V = V.text;
data.O = O.text;
data.answer = answer.text;
localStorage.syllableData = JSON.stringify(data);
}
}
new Label({text:"Beryea Syllable Creator", corner:5, color:white, backgroundColor:blue, padding:20}).sca(.7).pos(30,30);
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=Rectangle
// https://zimjs.com/docs.html?item=Label
// https://zimjs.com/docs.html?item=Button
// https://zimjs.com/docs.html?item=Stepper
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=TextArea
// https://zimjs.com/docs.html?item=change
// https://zimjs.com/docs.html?item=loop
// https://zimjs.com/docs.html?item=pos
// https://zimjs.com/docs.html?item=loc
// https://zimjs.com/docs.html?item=mov
// https://zimjs.com/docs.html?item=bot
// https://zimjs.com/docs.html?item=alp
// https://zimjs.com/docs.html?item=sca
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=shuffle
// https://zimjs.com/docs.html?item=zog
// https://zimjs.com/docs.html?item=STYLE
// FOOTER
// call remote script to make ZIM Foundation for Creative Coding icon
createIcon(-10,647, icon=>icon.sca(.7));
}); // end of ready
Also see: Tab Triggers