123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              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
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console