Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active December 19, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/7c841da85ce423bb6e4d734f0fc28314 to your computer and use it in GitHub Desktop.
Save kenwebb/7c841da85ce423bb6e4d734f0fc28314 to your computer and use it in GitHub Desktop.
Cocktail Party
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Dec 19 2017 17:23:39 GMT-0500 (EST)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Cocktail Party
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 7c841da85ce423bb6e4d734f0fc28314
Keywords:
My Notes
--------
December 19, 2017
There should be 100 people at the cocktail party.
Each person should initially become part of a group of 2 to 3 people.
References
----------
(1) Barabasi (2003), Linked, p. 14+
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<CocktailParty/>
<PersonBuilder/>
<Person/>
<Group/>
</_-.XholonClass>
<xholonClassDetails>
<PersonBuilder implName="org.primordion.xholon.base.Behavior_gwtjs"/>
<Person implName="org.primordion.xholon.base.Behavior_gwtjs"><Color>red</Color></Person>
</xholonClassDetails>
<PhysicalSystem>
<CocktailParty>
<Person multiplicity="100"><![CDATA[
var beh = new $wnd.xh.Personbehavior();
]]></Person>
<!-- this needs to come after Person -->
<PersonBuilder><![CDATA[
$wnd.xh.Personbehavior = function Personbehavior() {}
$wnd.xh.Personbehavior.prototype.postConfigure = function() {
this.person = this.cnode;
if (this.person.parent().first() == this.person) {
this.person.color("green");
}
this.timer = $wnd.Math.floor($wnd.Math.random() * 100);
var group = this.person.parent().last();
if (group.xhc().name() != "Group") {
this.person.parent().append("<" + "Group/>");
group = this.person.parent().last();
}
var count = this.countChildren(group);
if (count > 2) {
this.person.parent().append("<" + "Group/>");
group = this.person.parent().last();
}
group.append(this.person.remove());
};
$wnd.xh.Personbehavior.prototype.act = function() {
this.timer--;
if (this.timer < 0) {
// change group
var nextGroup = this.person.parent().next();
if (nextGroup == null) {
nextGroup = this.person.parent().parent().first();
}
nextGroup.append(this.person.remove());
this.timer = $wnd.Math.floor($wnd.Math.random() * 50);
}
if (this.person.color() == "green") {
var node = this.person.parent().first();
while (node) {
node.color("green");
node = node.next();
}
}
};
$wnd.xh.Personbehavior.prototype.countChildren = function(p) {
var count = 0;
var child = p.first();
while (child) {
count++;
child = child.next();
}
return count;
};
//# sourceURL=Personbehavior.js
]]></PersonBuilder>
</CocktailParty>
</PhysicalSystem>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Cocktail Party</title>
<rect id="PhysicalSystem/CocktailParty" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Person</title>
<rect id="PhysicalSystem/CocktailParty/Group/Person" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment