├── LICENSE
├── README.md
├── build
├── shimeji.css
└── shimeji.js
├── demo
├── index.htm
├── squalo
│ ├── mascot.json
│ ├── shime1.png
│ ├── shime10.png
│ ├── shime11.png
│ ├── shime12.png
│ ├── shime13.png
│ ├── shime14.png
│ ├── shime15.png
│ ├── shime16.png
│ ├── shime17.png
│ ├── shime18.png
│ ├── shime19.png
│ ├── shime2.png
│ ├── shime20.png
│ ├── shime21.png
│ ├── shime22.png
│ ├── shime23.png
│ ├── shime24.png
│ ├── shime25.png
│ ├── shime26.png
│ ├── shime27.png
│ ├── shime28.png
│ ├── shime29.png
│ ├── shime3.png
│ ├── shime30.png
│ ├── shime31.png
│ ├── shime32.png
│ ├── shime33.png
│ ├── shime34.png
│ ├── shime35.png
│ ├── shime36.png
│ ├── shime37.png
│ ├── shime38.png
│ ├── shime39.png
│ ├── shime4.png
│ ├── shime40.png
│ ├── shime41.png
│ ├── shime42.png
│ ├── shime43.png
│ ├── shime44.png
│ ├── shime45.png
│ ├── shime46.png
│ ├── shime5.png
│ ├── shime6.png
│ ├── shime7.png
│ ├── shime8.png
│ └── shime9.png
└── style.css
├── package.json
└── src
├── behaviors
├── boxNoEntry.js
├── boxNoExit.js
└── randomWalk.js
├── shimeji.css
└── shimeji.js
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Jim Chen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ShimejiHTML5
2 | ============
3 |
4 | The worlds most useless port of the desktop mascot. Acces the
5 | [demo](http://jabbany.github.com/ShimejiHTML5/demo) here.
6 |
7 |
8 |
--------------------------------------------------------------------------------
/build/shimeji.css:
--------------------------------------------------------------------------------
1 | .shimeji {
2 | position: fixed;
3 | z-index: 10;
4 | }
5 |
6 | .shimeji img {
7 | position: absolute;
8 | }
9 |
10 | .shimeji img.reverseH {
11 | transform: scaleX(-1);
12 | transform-origin: 50% 50%;
13 | }
14 |
15 | .shimeji img.reverseV {
16 | transform: scaleY(-1);
17 | transform-origin: 50% 50%;
18 | }
19 |
--------------------------------------------------------------------------------
/build/shimeji.js:
--------------------------------------------------------------------------------
1 | /** Library for loading shinmeji **/
2 | var Shimeji = (function(){
3 | var Shimeji = function(config){
4 | this.config = config;
5 | this.actionQueue = [];
6 | this.environment = [];
7 | this.behaviors = {};
8 | this.container = null;
9 | this.image = null;
10 | this._timeout = -1;
11 | this._x = null;
12 | this._y = null;
13 | };
14 | Shimeji.prototype.init = function(element, x, y){
15 | if(!element) { throw "Invalid bind element"; }
16 | var image = document.createElement("img");
17 | element.appendChild(image);
18 | this.container = element;
19 | this.image = image;
20 | this._x = (typeof x === "number") ? x : this.container.offsetLeft;
21 | this._y = (typeof y === "number") ? y :this.container.offsetTop;
22 |
23 | this.place(this._x, this._y);
24 | };
25 | Shimeji.prototype.makeEnvironment = function(elems){
26 | this.environment.push({
27 | "name":"page",
28 | "top":0,
29 | "left":0,
30 | "bottom":window.innerHeight,
31 | "right":window.innerWidth
32 | })
33 | if(typeof elems === "undefined"){ return; }
34 | for(var i = 0; i < elems.length; i++){
35 | var elem = elems[i];
36 | this.environment.push({
37 | "name": (elem.id !== "" ? elem.id : "elem_" + i),
38 | "top": elem.offsetTop,
39 | "bottom": elem.offsetTop + elem.offsetHeight,
40 | "left": elem.offsetLeft,
41 | "right": elem.offsetLeft + elem.offsetWidth
42 | });
43 | };
44 | };
45 | Shimeji.prototype._inEnv = function(env, x, y){
46 | return x < env.right && x > env.left && y > env.top && y < env.bottom;
47 | };
48 | Shimeji.prototype.place = function(x, y){
49 | this._x = x;
50 | this._y = y;
51 | this.container.style.left = this._x + "px";
52 | this.container.style.top = this._y + "px";
53 | };
54 | Shimeji.prototype.cancelAct = function(){
55 | this.actionQueue = [];
56 | };
57 | Shimeji.prototype.interact = function(oX, oY){
58 | // Interact with the environment
59 | for(var i = 0; i < this.environment.length; i++){
60 | var env = this.environment[i];
61 | if(this._inEnv(env, this._x, this._y) !== this._inEnv(env, oX, oY)){
62 | var interact = [];
63 | if(this._inEnv(env, oX, oY)){
64 | interact.push("exit");
65 | if(this._y >= env.bottom && oY < env.bottom){
66 | interact.push("bottom");
67 | }else if(this._y <= env.top && oY > env.top){
68 | interact.push("top");
69 | }
70 | if(this._x >= env.right && oX < env.right){
71 | interact.push("right");
72 | }else if(this._x <= env.left && oX > env.left){
73 | interact.push("left");
74 | }
75 | }else{
76 | interact.push("enter");
77 | if(this._y <= env.bottom && oY > env.bottom){
78 | interact.push("bottom");
79 | }else if(this._y >= env.top && oY < env.top){
80 | interact.push("top");
81 | }
82 | if(this._x <= env.right && oX > env.right){
83 | interact.push("right");
84 | }else if(this._x >= env.left && oX < env.left){
85 | interact.push("left");
86 | }
87 | }
88 | var ikey = interact.join("_");
89 | if(typeof this.behaviors[env.name] === "function"){
90 | this.behaviors[env.name](ikey, env);
91 | }else if(this.behaviors[env.name] && this.behaviors[env.name][ikey]){
92 | if(typeof this.behaviors[env.name][ikey] !== "function"){
93 | this.actionQueue = [];
94 | this.act(this.behaviors[env.name][ikey]);
95 | return;
96 | }else{
97 | this.behaviors[env.name][ikey](env);
98 | }
99 | }
100 | }
101 | }
102 | };
103 | Shimeji.prototype.pose = function(posture){
104 | this.image.src = (this.config.baseUrl ? this.config.baseUrl : "") + posture.src;
105 | this.image.style.left = -posture.anchor[0] + "px";
106 | this.image.style.top = -posture.anchor[1] + "px";
107 |
108 | this.image.className = (posture.reverseVert ? "reverseV" : "") + " " + (posture.reverseHori ? "reverseH" : "");
109 | var oX = this._x, oY = this._y;
110 | this._x += (posture.reverseHori ? -1: 1) * posture.move.x;
111 | this._y += (posture.reverseVert ? -1: 1) * posture.move.y;
112 | this.interact(oX, oY);
113 |
114 | this.container.style.transition = "top " + posture.duration + "ms, left " + posture.duration + "ms linear";
115 | this.place(this._x, this._y);
116 | };
117 | Shimeji.prototype.act = function(action, repeat, reverseH, reverseV, reverseM, onEnd){
118 | if(typeof repeat !== "number"){
119 | repeat = 1;
120 | }
121 | if(this.config.actions[action]){
122 | if(!reverseM){
123 | for(var r = 0; r < repeat; r++){
124 | for(var i = 0; i < this.config.actions[action].length; i++){
125 | var revact = {};
126 | for(var prop in this.config.actions[action][i]){
127 | if(this.config.actions[action][i].hasOwnProperty(prop)){
128 | revact[prop] = this.config.actions[action][i][prop];
129 | }
130 | }
131 | revact["reverseVert"] = reverseV;
132 | revact["reverseHori"] = reverseH;
133 | this.actionQueue.push(revact);
134 | };
135 | }
136 | }else{
137 | for(var r = 0; r < repeat; r++){
138 | for(var i = this.config.actions[action].length - 1; i >= 0; i--){
139 | var revact = JSON.parse(JSON.stringify(this.config.actions[action][i]));
140 | revact["reverseVert"] = reverseV;
141 | revact["reverseHori"] = reverseH;
142 | revact.move.x = -revact.move.x;
143 | revact.move.y = -revact.move.y;
144 | this.actionQueue.push(revact);
145 | };
146 | }
147 | }
148 | if(typeof onEnd === "function"){
149 | this.actionQueue.push(onEnd);
150 | }
151 | if(this._timeout < 0){
152 | var self = this;
153 | var _cb = function(){
154 | if(self.actionQueue.length > 0){
155 | var posture = self.actionQueue.shift();
156 | if(typeof posture === "function"){
157 | posture();
158 | _cb();
159 | return;
160 | }
161 | self.pose(posture);
162 | self._timeout = setTimeout(_cb, posture.duration );
163 | }else{
164 | self._timeout = -1;
165 | }
166 | };
167 | _cb();
168 | }
169 | }
170 | };
171 | Shimeji.prototype.behavior = function(trigger, action, hook){
172 | if(typeof hook === "undefined"){
173 | this.behaviors[trigger] = action;
174 | }else{
175 | if(!this.behaviors[trigger]){
176 | this.behaviors[trigger] = {};
177 | }
178 | this.behaviors[trigger][hook] = action;
179 | }
180 | };
181 | return Shimeji;
182 | })();
183 |
--------------------------------------------------------------------------------
/demo/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Shimeji HTML5 Demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
Shimeji Web Library Demonstration
17 |
18 |
Reverse Horizontal
19 |
Reverse Vertical
20 |
Reverse Motion
21 |
22 |
23 |
Walk
24 |
Climb
25 |
Stand
26 |
Drop
27 |
28 |
29 |
New
30 |
31 |
32 |
33 |
34 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/demo/squalo/mascot.json:
--------------------------------------------------------------------------------
1 | {
2 | "name":"Squalo",
3 | "license":"unknown",
4 | "baseUrl":"squalo/",
5 | "actions":{
6 | "sleep":[
7 | {
8 | "src":"shime21.png",
9 | "anchor":[64,128],
10 | "move":{"x":0, "y":0},
11 | "duration":2500
12 | }
13 | ],
14 | "stand":[
15 | {
16 | "src":"shime1.png",
17 | "anchor":[64,128],
18 | "move":{"x":0, "y":0},
19 | "duration":250
20 | }
21 | ],
22 | "walk":[
23 | {
24 | "src":"shime1.png",
25 | "anchor":[64,128],
26 | "move":{"x":-20, "y": 0},
27 | "duration":300
28 | },
29 | {
30 | "src":"shime2.png",
31 | "anchor":[64,128],
32 | "move":{"x":-20, "y": 0},
33 | "duration":300
34 | },
35 | {
36 | "src":"shime1.png",
37 | "anchor":[64,128],
38 | "move":{"x":-20, "y": 0},
39 | "duration":300
40 | },
41 | {
42 | "src":"shime3.png",
43 | "anchor":[64,128],
44 | "move":{"x":-20, "y": 0},
45 | "duration":300
46 | }
47 | ],
48 | "shift":[
49 | {"src":"shime25.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":800},
50 | {"src":"shime25.png","anchor":[64,128],"move":{"x":-10, "y":0}, "duration":200},
51 | {"src":"shime23.png","anchor":[64,128],"move":{"x":-10, "y":0}, "duration":200},
52 | {"src":"shime24.png","anchor":[64,128],"move":{"x":-10, "y":0}, "duration":200},
53 | {"src":"shime24.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":800},
54 | {"src":"shime24.png","anchor":[64,128],"move":{"x":-20, "y":0}, "duration":200},
55 | {"src":"shime23.png","anchor":[64,128],"move":{"x":-20, "y":0}, "duration":200},
56 | {"src":"shime25.png","anchor":[64,128],"move":{"x":-20, "y":0}, "duration":200}
57 | ],
58 | "sit_sing":[
59 | {"src":"shime31.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":250},
60 | {"src":"shime32.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":750},
61 | {"src":"shime31.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":250},
62 | {"src":"shime33.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":750}
63 | ],
64 | "jump":[
65 | {"src":"shime22.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":200}
66 | ],
67 | "fall":[
68 | {
69 | "src":"shime4.png",
70 | "anchor":[64,128],
71 | "move":{"x":0, "y":40},
72 | "duration":100
73 | }
74 | ],
75 | "land":[
76 | {
77 | "src":"shime18.png",
78 | "anchor":[64,128],
79 | "move":{"x":0, "y":0},
80 | "duration":200
81 | },
82 | {
83 | "src":"shime19.png",
84 | "anchor":[64,128],
85 | "move":{"x":0, "y":0},
86 | "duration":200
87 | }
88 | ],
89 | "climb":[
90 | {"src":"shime14.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":800},
91 | {"src":"shime14.png","anchor":[64,128],"move":{"x":0, "y":-10}, "duration":200},
92 | {"src":"shime12.png","anchor":[64,128],"move":{"x":0, "y":-10}, "duration":200},
93 | {"src":"shime13.png","anchor":[64,128],"move":{"x":0, "y":-10}, "duration":200},
94 | {"src":"shime13.png","anchor":[64,128],"move":{"x":0, "y":0}, "duration":800},
95 | {"src":"shime13.png","anchor":[64,128],"move":{"x":0, "y":-20}, "duration":200},
96 | {"src":"shime12.png","anchor":[64,128],"move":{"x":0, "y":-20}, "duration":200},
97 | {"src":"shime14.png","anchor":[64,128],"move":{"x":0, "y":-20}, "duration":200}
98 | ]
99 | },
100 | "behavior":{
101 |
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/demo/squalo/shime1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime1.png
--------------------------------------------------------------------------------
/demo/squalo/shime10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime10.png
--------------------------------------------------------------------------------
/demo/squalo/shime11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime11.png
--------------------------------------------------------------------------------
/demo/squalo/shime12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime12.png
--------------------------------------------------------------------------------
/demo/squalo/shime13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime13.png
--------------------------------------------------------------------------------
/demo/squalo/shime14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime14.png
--------------------------------------------------------------------------------
/demo/squalo/shime15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime15.png
--------------------------------------------------------------------------------
/demo/squalo/shime16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime16.png
--------------------------------------------------------------------------------
/demo/squalo/shime17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime17.png
--------------------------------------------------------------------------------
/demo/squalo/shime18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime18.png
--------------------------------------------------------------------------------
/demo/squalo/shime19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime19.png
--------------------------------------------------------------------------------
/demo/squalo/shime2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime2.png
--------------------------------------------------------------------------------
/demo/squalo/shime20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime20.png
--------------------------------------------------------------------------------
/demo/squalo/shime21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime21.png
--------------------------------------------------------------------------------
/demo/squalo/shime22.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime22.png
--------------------------------------------------------------------------------
/demo/squalo/shime23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime23.png
--------------------------------------------------------------------------------
/demo/squalo/shime24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime24.png
--------------------------------------------------------------------------------
/demo/squalo/shime25.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime25.png
--------------------------------------------------------------------------------
/demo/squalo/shime26.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime26.png
--------------------------------------------------------------------------------
/demo/squalo/shime27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime27.png
--------------------------------------------------------------------------------
/demo/squalo/shime28.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime28.png
--------------------------------------------------------------------------------
/demo/squalo/shime29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime29.png
--------------------------------------------------------------------------------
/demo/squalo/shime3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime3.png
--------------------------------------------------------------------------------
/demo/squalo/shime30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime30.png
--------------------------------------------------------------------------------
/demo/squalo/shime31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime31.png
--------------------------------------------------------------------------------
/demo/squalo/shime32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime32.png
--------------------------------------------------------------------------------
/demo/squalo/shime33.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime33.png
--------------------------------------------------------------------------------
/demo/squalo/shime34.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime34.png
--------------------------------------------------------------------------------
/demo/squalo/shime35.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime35.png
--------------------------------------------------------------------------------
/demo/squalo/shime36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime36.png
--------------------------------------------------------------------------------
/demo/squalo/shime37.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime37.png
--------------------------------------------------------------------------------
/demo/squalo/shime38.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime38.png
--------------------------------------------------------------------------------
/demo/squalo/shime39.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime39.png
--------------------------------------------------------------------------------
/demo/squalo/shime4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime4.png
--------------------------------------------------------------------------------
/demo/squalo/shime40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime40.png
--------------------------------------------------------------------------------
/demo/squalo/shime41.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime41.png
--------------------------------------------------------------------------------
/demo/squalo/shime42.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime42.png
--------------------------------------------------------------------------------
/demo/squalo/shime43.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime43.png
--------------------------------------------------------------------------------
/demo/squalo/shime44.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime44.png
--------------------------------------------------------------------------------
/demo/squalo/shime45.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime45.png
--------------------------------------------------------------------------------
/demo/squalo/shime46.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime46.png
--------------------------------------------------------------------------------
/demo/squalo/shime5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime5.png
--------------------------------------------------------------------------------
/demo/squalo/shime6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime6.png
--------------------------------------------------------------------------------
/demo/squalo/shime7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime7.png
--------------------------------------------------------------------------------
/demo/squalo/shime8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime8.png
--------------------------------------------------------------------------------
/demo/squalo/shime9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/demo/squalo/shime9.png
--------------------------------------------------------------------------------
/demo/style.css:
--------------------------------------------------------------------------------
1 | * {
2 | font-family: sans-serif;
3 | color: #fff;
4 | }
5 |
6 | body{
7 | background-color:#222;
8 | }
9 |
10 | div.btn{
11 | border: 1px solid #fff;
12 | padding: 5px;
13 | margin: 2px;
14 | cursor:pointer;
15 | float:left;
16 | background-color: #666;
17 | }
18 | div.btn.on{
19 | background-color: #88D;
20 | color:#000;
21 | }
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ShimejiHTML5",
3 | "version": "0.1.0",
4 | "description": "Shimeji Mascot for Web Pages",
5 | "directories": {
6 | "doc": "docs"
7 | },
8 | "repository": {
9 | "type": "git",
10 | "url": "https://github.com/jabbany/ShimejiHTML5.git"
11 | },
12 | "author": "Jim Chen ",
13 | "license": "MIT",
14 | "bugs": {
15 | "url": "https://github.com/jabbany/ShimejiHTML5/issues"
16 | },
17 | "homepage": "https://github.com/jabbany/ShimejiHTML5"
18 | }
19 |
--------------------------------------------------------------------------------
/src/behaviors/boxNoEntry.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Function to guarantee no exit of a boxed environment
3 | */
4 |
5 | function noExit(what, env){
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/behaviors/boxNoExit.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jabbany/ShimejiHTML5/f127c654bcd608105bd430ccaf34096ca110fca4/src/behaviors/boxNoExit.js
--------------------------------------------------------------------------------
/src/behaviors/randomWalk.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Randomly invoke some actions according to a CTMC
3 | */
4 |
5 | function randomWalk ( shimeji , markovProbs , exitFunc ) {
6 | var _rw = function(){
7 | // Pick random element
8 | var transition = Math.random();
9 | var _r = 0;
10 | for(var i = 0; i < markovProbs["_states"].length; i++){
11 | var state = markovProbs["_states"][i];
12 | if(_r <= transition && _r + markovProbs[state].prob >= transition){
13 | // Enter state
14 | console.log("Enter " + state + " N:" + markovProbs[state].name);
15 | if(!markovProbs[state].isExit){
16 | shimeji.act(markovProbs[state].name,
17 | (markovProbs[state].repeat ? markovProbs[state].repeat : 1),
18 | markovProbs[state].revH,
19 | markovProbs[state].revV,
20 | markovProbs[state].revM,
21 | _rw);
22 | return;
23 | }else{
24 | if(typeof exitFunc === "function"){
25 | exitFunc();
26 | }
27 | return;
28 | }
29 | };
30 | _r += markovProbs[state].prob;
31 | };
32 | if(typeof exitFunc === "function"){
33 | exitFunc();
34 | }
35 | return;
36 | }
37 | _rw();
38 | };
39 |
--------------------------------------------------------------------------------
/src/shimeji.css:
--------------------------------------------------------------------------------
1 | .shimeji {
2 | position: fixed;
3 | z-index: 10;
4 | }
5 |
6 | .shimeji img {
7 | position: absolute;
8 | }
9 |
10 | .shimeji img.reverseH {
11 | transform: scaleX(-1);
12 | transform-origin: 50% 50%;
13 | }
14 |
15 | .shimeji img.reverseV {
16 | transform: scaleY(-1);
17 | transform-origin: 50% 50%;
18 | }
19 |
--------------------------------------------------------------------------------
/src/shimeji.js:
--------------------------------------------------------------------------------
1 | /** Library for loading shinmeji **/
2 | var Shimeji = (function(){
3 | var Shimeji = function(config){
4 | this.config = config;
5 | this.actionQueue = [];
6 | this.environment = [];
7 | this.behaviors = {};
8 | this.container = null;
9 | this.image = null;
10 | this._timeout = -1;
11 | this._x = null;
12 | this._y = null;
13 | };
14 | Shimeji.prototype.init = function(element, x, y){
15 | if(!element) { throw "Invalid bind element"; }
16 | var image = document.createElement("img");
17 | element.appendChild(image);
18 | this.container = element;
19 | this.image = image;
20 | this._x = (typeof x === "number") ? x : this.container.offsetLeft;
21 | this._y = (typeof y === "number") ? y :this.container.offsetTop;
22 |
23 | this.place(this._x, this._y);
24 | };
25 | Shimeji.prototype.makeEnvironment = function(elems){
26 | this.environment.push({
27 | "name":"page",
28 | "top":0,
29 | "left":0,
30 | "bottom":window.innerHeight,
31 | "right":window.innerWidth
32 | })
33 | if(typeof elems === "undefined"){ return; }
34 | for(var i = 0; i < elems.length; i++){
35 | var elem = elems[i];
36 | this.environment.push({
37 | "name": (elem.id !== "" ? elem.id : "elem_" + i),
38 | "top": elem.offsetTop,
39 | "bottom": elem.offsetTop + elem.offsetHeight,
40 | "left": elem.offsetLeft,
41 | "right": elem.offsetLeft + elem.offsetWidth
42 | });
43 | };
44 | };
45 | Shimeji.prototype._inEnv = function(env, x, y){
46 | return x < env.right && x > env.left && y > env.top && y < env.bottom;
47 | };
48 | Shimeji.prototype.place = function(x, y){
49 | this._x = x;
50 | this._y = y;
51 | this.container.style.left = this._x + "px";
52 | this.container.style.top = this._y + "px";
53 | };
54 | Shimeji.prototype.cancelAct = function(){
55 | this.actionQueue = [];
56 | };
57 | Shimeji.prototype.interact = function(oX, oY){
58 | // Interact with the environment
59 | for(var i = 0; i < this.environment.length; i++){
60 | var env = this.environment[i];
61 | if(this._inEnv(env, this._x, this._y) !== this._inEnv(env, oX, oY)){
62 | var interact = [];
63 | if(this._inEnv(env, oX, oY)){
64 | interact.push("exit");
65 | if(this._y >= env.bottom && oY < env.bottom){
66 | interact.push("bottom");
67 | }else if(this._y <= env.top && oY > env.top){
68 | interact.push("top");
69 | }
70 | if(this._x >= env.right && oX < env.right){
71 | interact.push("right");
72 | }else if(this._x <= env.left && oX > env.left){
73 | interact.push("left");
74 | }
75 | }else{
76 | interact.push("enter");
77 | if(this._y <= env.bottom && oY > env.bottom){
78 | interact.push("bottom");
79 | }else if(this._y >= env.top && oY < env.top){
80 | interact.push("top");
81 | }
82 | if(this._x <= env.right && oX > env.right){
83 | interact.push("right");
84 | }else if(this._x >= env.left && oX < env.left){
85 | interact.push("left");
86 | }
87 | }
88 | var ikey = interact.join("_");
89 | if(typeof this.behaviors[env.name] === "function"){
90 | this.behaviors[env.name](ikey, env);
91 | }else if(this.behaviors[env.name] && this.behaviors[env.name][ikey]){
92 | if(typeof this.behaviors[env.name][ikey] !== "function"){
93 | this.actionQueue = [];
94 | this.act(this.behaviors[env.name][ikey]);
95 | return;
96 | }else{
97 | this.behaviors[env.name][ikey](env);
98 | }
99 | }
100 | }
101 | }
102 | };
103 | Shimeji.prototype.pose = function(posture){
104 | this.image.src = (this.config.baseUrl ? this.config.baseUrl : "") + posture.src;
105 | this.image.style.left = -posture.anchor[0] + "px";
106 | this.image.style.top = -posture.anchor[1] + "px";
107 |
108 | this.image.className = (posture.reverseVert ? "reverseV" : "") + " " + (posture.reverseHori ? "reverseH" : "");
109 | var oX = this._x, oY = this._y;
110 | this._x += (posture.reverseHori ? -1: 1) * posture.move.x;
111 | this._y += (posture.reverseVert ? -1: 1) * posture.move.y;
112 | this.interact(oX, oY);
113 |
114 | this.container.style.transition = "top " + posture.duration + "ms, left " + posture.duration + "ms linear";
115 | this.place(this._x, this._y);
116 | };
117 | Shimeji.prototype.act = function(action, repeat, reverseH, reverseV, onEnd){
118 | if(typeof repeat !== "number"){
119 | repeat = 1;
120 | }
121 | if(this.config.actions[action]){
122 | if(!reverseV && !reverseH){
123 | for(var r = 0; r < repeat; r++){
124 | for(var i = 0; i < this.config.actions[action].length; i++){
125 | this.actionQueue.push(this.config.actions[action][i]);
126 | };
127 | }
128 | }else{
129 | for(var r = 0; r < repeat; r++){
130 | for(var i = this.config.actions[action].length - 1; i >= 0; i--){
131 | var revact = {};
132 | for(var prop in this.config.actions[action][i]){
133 | if(this.config.actions[action][i].hasOwnProperty(prop)){
134 | revact[prop] = this.config.actions[action][i][prop];
135 | }
136 | }
137 | revact["reverseVert"] = reverseV;
138 | revact["reverseHori"] = reverseH;
139 | this.actionQueue.push(revact);
140 | };
141 | }
142 | }
143 | if(typeof onEnd === "function"){
144 | this.actionQueue.push(onEnd);
145 | }
146 | if(this._timeout < 0){
147 | var self = this;
148 | var _cb = function(){
149 | if(self.actionQueue.length > 0){
150 | var posture = self.actionQueue.shift();
151 | if(typeof posture === "function"){
152 | posture();
153 | _cb();
154 | return;
155 | }
156 | self.pose(posture);
157 | self._timeout = setTimeout(_cb, posture.duration );
158 | }else{
159 | self._timeout = -1;
160 | }
161 | };
162 | _cb();
163 | }
164 | }
165 | };
166 | Shimeji.prototype.behavior = function(trigger, action, hook){
167 | if(typeof hook === "undefined"){
168 | this.behaviors[trigger] = action;
169 | }else{
170 | if(!this.behaviors[trigger]){
171 | this.behaviors[trigger] = {};
172 | }
173 | this.behaviors[trigger][hook] = action;
174 | }
175 | };
176 | return Shimeji;
177 | })();
178 |
--------------------------------------------------------------------------------