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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
//thymic chemistry fear and sadness are the predators that have the tendency to decrease over time and delight and desire are the preys that have the tendency to increase over time, as well as fear reacts with desire and sadness reacts with delight. In the reaction of fear and desire, the prey converts to predator, desire converts to fear, and in the reaction of delight and sadness, delight converts to sadness. Also, there are four more reactions, which produce new emotions. One reaction is that of desire and delight, which is a catalytic reaction that produces two new preys, where desire converts to friendliness, and delight converts to excitement. Moreover, there is the reaction of sadness and fear, which produce two new predators, sadness converts to cowardice (δειλία) and fear converts to aggressiveness. Last, there is the reaction of desire and sadness, where desire converts to melancholy, and the reaction of delight and fear, where delight converts to ambivalence. /* ------------Elements::10------------- //increase over time RatePreys: 1.0f Preys: Desire, Delight, friendliness, excitement //decrease over time RatePredators: 0.5f Predators: Fear, Sadness, Cowardice, Aggressiveness, Melancholy, Ambivalence -----Reactions of the Elements:------- RatePredator:0.5; Reaction1:Desire+Fear= 2Fear RatePredator:0.5; Reaction2:Delight+Sadness= 2Sadness RatePrey:1.0; Reaction3:Desire+Delight= Friendliness + Excitement RatePredator:0.5; Reaction4:Sadness+Fear= Cowrdice + Aggressiveness RatePredator:0.5; Reaction5:Desire+Sadness= Melancholy+Sadness RatePredator:0.5; Reaction6:Delight+Fear= Ambivalence+Fear -----------Characters::5-------------- Ambivalent: Rate: 1.0; Reaction6:Delight+Fear= Ambivalence+Fear Melancholic: Rate:1.0; Reaction5:Desire+Sadness= Melancholy+Sadness Cowrdice: RatePredatorSadness: 1.0; Reaction4:Sadness+Fear= Cowrdice + Aggressiveness Aggressive: RatePredatorFear: 1.0; Reaction4:Sadness+Fear= Cowrdice + Aggressiveness Friendly: RatePreyDesire: 1.5; Reaction3:Desire+Delight= Friendliness + Excitement -----Reactions of Characters---------- ------Valence:------ |Desire+Friendliness|+Ambivalance-|Melancholy+Fear| ------Arousal:------ |Delight+Excitement+Aggressiveness|-|Sadness+Cowardice| Search(looking at) & Talk(looking at looked at) & Initiate Conversation(higher valence, higher arousal) & Response(lower valence, lower arousal) & End Conversation(30% when v<0, 70% when a<0) Melancholic + Cowardcice: ValenceM + ArousalC if (|VM|>|VC|) {Talk Mel talks first, MSynth trigger talks for 3 seconds then Cow responds to Mel, by leaving the conversation first} else {search} if (|AC|>|AM|) { Talk Cow talks first, for 3 seconds then Mel responds to Cow, for 3 seconds, Cow and Mel go into silence and after 5 seconds they both leave the conversation. } Else {search} Melancholic + Friendly: ValenceM +ValenceF if (|VF|>|VM|){ Fre talks first to Mel, FreSynth trigger for 10 seconds, then Mel talks for 3 seconds and leaves conversation first }else if (|VM|>|VF|){ stay and look at each other for 3 seconds or both keep the Search } Melancholic + Aggressive: ValenceM+ArousalAg if (|VAg|>|VM|){ Aggr talks to Mel first for 3 seconds, and Mel } Talk Melancholic + Ambivalent: ValenceM+ValenceAm if VM>VA, VA talks for 5 seconds with Va, VM talks first for 2 seconds, VA talks second for 3 seconds, Conversation ends after 10 seconds if VA>VM, VA talks first for 3 seconds with VM, VM doesn't talk just looks at Am for 2 seconds and they both end leave the conversation after 5 seconds Cowardice + Friendly: ValenceF+ArousalC Cowardice + Aggressive: ArousalC+ArousalAg Cowardice + Ambivalent: Valence + Arousal Friendly + Aggressive: ValenceF+ArousalAg Friendly + Ambivalent: ValenceF+ValenceAm */
let dim = 50;
let art_world = new field2D(dim);
let past = new field2D(dim);
let emotions = [];
// the names of these chemicals:
let names = "delightdesire, sadnessfearambivalence aggressivenessfriendlinessexcitementcowardicemelancholy".split
let mouseX=0.5, mouseY=0.5;
const lower_limit = 0.01;
const upper_limit = 50.0;
/*delight, sadness, fear, desire, thumos*/
// reaction constants:
let kdelight = 0.5;
let kdelightfear = 0.5;
let ksadness = 0.5;
let ksadelight = 0.5;
let ksadfear = 1.0;
let kfear = 1.0;
let kfeardesire = 1.0;
let kdesire = 0.5;
let ksaddesire = 0.5;
let kdesiredelight = 1.0;
let kambivalence=0.5, kaggressiveness=0.5, kfriendliness=1.0, kexcitement=1.0, kcowardice=0.5, kmelancholy=0.5;
function reset() {
// initial concentrations for the set of chemicals:
emotions = [0.5, 0.5, 0.5, 0.5,0.5, 0.5, 0.5, 0.5,0.5,0.5];
art_world.set(0);
past.set(0);
}
function react() {
//emotions[delight, desire, sadness, fear,ambivalence, aggressiveness, friendliness, excitement, cowardice, melancholy]
let [delight, desire, sadness, fear,ambivalence, aggressiveness, friendliness, excitement, cowardice, melancholy] = emotions;
// delta changes of each chemical:
let ddelight = 0,
dsadness = 0,
dfear = 0,
ddesire = 0,
dambivalence= 0,
daggressiveness= 0,
dfriendliness= 0,
dexcitement= 0,
dcowardice= 0,
dmelancholy= 0;
// dthumos = 0;
// timestep -- needs to be small, or else the dynamics can break:
let dt = 0.00001;
let x= mouseX;
let y =mouseY;
x = Math.min(Math.max(x, 0.5), 1.0);
y =Math.min(Math.max(y, 0.5), 1.0);
// apply reaction rules:
// sadness => 2sadness @rate ksadness (ksadness<kdelight)
//sadness+delight=>2Delight
dsadness += -ksadness * sadness;
dsadness += ksadelight * sadness * delight;
ddelight += -ksadelight * sadness * delight;
//delight=>2Delight
ddelight += kdelight * delight;
//Desire+Fear=>2Fear;
dfear += -kfear * fear;
dfear += kfeardesire * desire * fear;
ddesire += -kfeardesire * desire * fear;
//desire=>2Desire
ddesire += kdesire * desire;
//Sadness=>2Sadness && Delight=>2Delight
//Ambivalence=>.
dambivalence += (ksadelight* 1) *sadness *delight;
dambivalence+= -kambivalence* ambivalence;
//Fear=>2Fear && Desire=>2Desire
//Aggressiveness
daggressiveness += (kfeardesire*1*mouseX) *fear*desire;
daggressiveness += -kaggressiveness *aggressiveness;
//Fear=>2Fear
//Cowardice
dcowardice += (kfear * 1)*fear;
dcowardice += -kcowardice * cowardice/x;
//Sadness=>2Sadness && Excitement=>.
//Melancholy
dmelancholy += (ksadelight *1)*sadness;
dmelancholy += -kmelancholy* melancholy/x;
//Desire=>2Desire &&Aggressiveness=>.
//Friendliness
dfriendliness += (kfeardesire *1 )*desire/aggressiveness;
dfriendliness += -kfriendliness * friendliness/y;
//Delight=>2Delight && Aggressiveness=>2Aggressiveness
//Excitement
dexcitement += (kdelight*1) *delight*aggressiveness;
dexcitement += -kexcitement * excitement/y;
// apply changes:
delight += ddelight * dt;
sadness += dsadness * dt;
fear += dfear * dt;
desire += ddesire * dt;
ambivalence += dambivalence *dt;
melancholy += dmelancholy *dt;
excitement+= dexcitement * dt;
friendliness += dfriendliness *dt;
aggressiveness += daggressiveness *dt;
cowardice += dcowardice *dt;
ambivalence = Math.min(Math.max(ambivalence, lower_limit), upper_limit);
melancholy = Math.min(Math.max(melancholy, lower_limit), upper_limit);
excitement = Math.min(Math.max(excitement, lower_limit), upper_limit);
friendliness= Math.min(Math.max(friendliness, lower_limit), upper_limit);
aggressiveness = Math.min(Math.max(aggressiveness, lower_limit), upper_limit);
cowardice = Math.min(Math.max(cowardice, lower_limit), upper_limit);
//thumos += dthumos * dt;
emotions = [delight, desire, sadness, fear,ambivalence,melancholy,excitement,friendliness,aggressiveness,cowardice];
}
function update(dt) {
// run 100,000 reactions per second
for (let i = 0; i < dt * 500000; i++) {
react();
}
var tmp = art_world;
art_world = past;
past = tmp;
art_world.diffuse(past, 0.2);
art_world.set(function(x, y) {
if (
y < (random() * 0.2 + 0.4) * art_world.height &&
y > (random() * 0.2 + 0.4) * art_world.height
) {
if (
x < (random() * 0.2 + 0.05) * art_world.width &&
x > (random() * 0.2 + 0.05) * art_world.width
)
return 0;
// Middle Pole
if (
x < (random() * 0.2 + 0.4) * art_world.width &&
x > (random() * 0.2 + 0.4) * art_world.width
) {
return 0.2;
} else if (
x < (random() * 0.2 + 0.75) * art_world.width &&
x > (random() * 0.2 + 0.75) * art_world.width
) {
// Right Pole
return 0;
}
}
return art_world.get(x, y);
});
art_world.map(function(v) {
return clamp(v, 0, 1);
});
}
function key(kind, key) {
if (key == "r" && kind == "down") {
reset();
}
}
function mouse(e, pt) {
mouseX = pt[0] + 0.5;
mouseY = pt[1] + 0.5;
art_world.deposit(1, pt);
}
function draw(ctx) {
// display the current concentrations
// unpack chemical array into local variables:
let [delight, desire, sadness, fear,ambivalence, aggressiveness, friendliness, excitement, cowardice, melancholy] = emotions;
let emotionLabel = ["delight", "desire", "sadness", "fear","ambivalence", "aggressiveness", "friendliness", "excitement", "cowardice", "melancholy"];
// Let ["desire", "delight", "sadness", "fear"]
let numemotions = emotions.length;
// for each chemical:
for (let i = 0; i < emotions.length; i++) {
let c = emotions[i];
let t = i / numemotions;
let x = Math.sin(Math.PI * 2 * t);
let y = Math.cos(Math.PI * 2 * t);
// human-readable information:
let name = String.fromCharCode(65 + i);
let label = i;
// area = pi * radius*radius
// radius = sqrt(area/pi)
// clamp c between 0 and 10 to prevent blowups in renderer:
let radius = Math.sqrt(Math.min(5, Math.max(0, c/2)) / Math.PI);
//let area = Math.PI * radius * radius;
draw2D.push().translate(0.5, 0.5).scale(0.25).translate(x, y);
{
draw2D.color("lightgrey");
draw2D.hsl(t, 0.3);
ctx.font = "0.1px sans";
ctx.fillText(label, -0.175, 0.025);
draw2D.hsl(-t*mouseY/2*mouseX , 0.9);
draw2D.circle(radius);
//
}
draw2D.pop();
write(emotionLabel[i], c);
}
}
/*
*/
Also see: Tab Triggers