Skip to content

Commit b2fa345

Browse files
committed
console banner maker
1 parent c552d86 commit b2fa345

6 files changed

Lines changed: 191 additions & 45 deletions

File tree

955 Bytes
Loading
402 Bytes
Loading
940 Bytes
Loading

examples/bringToTop2.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
16+
17+
function preload() {
18+
game.load.image('card', 'assets/sprites/mana_card.png');
19+
}
20+
21+
function create() {
22+
23+
game.add.sprite(game.world.randomX, game.world.randomY, 'card');
24+
}
25+
26+
function runChange () {
27+
// changeOrder(a, h);
28+
}
29+
30+
function update() {
31+
}
32+
33+
function render() {
34+
}
35+
36+
})();
37+
38+
</script>
39+
40+
</body>
41+
</html>

examples/consoleBanner.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<textarea id="output" style="width: 800px; height: 400px">xxx</textarea>
12+
13+
<script type="text/javascript">
14+
15+
(function () {
16+
17+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
18+
19+
function preload() {
20+
// game.load.image('piccie', 'assets/sprites/phaser_tiny.png');
21+
// game.load.image('piccie', 'assets/sprites/carrot.png');
22+
// game.load.image('piccie', 'assets/sprites/phaser-dude.png');
23+
game.load.image('piccie', 'assets/pics/atari_fujilogo.png');
24+
}
25+
26+
var canvas;
27+
var context;
28+
29+
function create() {
30+
31+
var img = game.add.sprite(0, 0, 'piccie');
32+
33+
canvas = document.createElement('canvas');
34+
canvas.width = img.width;
35+
canvas.height = img.height;
36+
context = canvas.getContext('2d');
37+
38+
context.drawImage(game.cache.getImage('piccie'), 0, 0);
39+
40+
var result = '';
41+
42+
for (var y = 0; y < img.height; y++)
43+
{
44+
var line = '';
45+
var css = '';
46+
var previousColor = '';
47+
48+
for (var x = 0; x < img.width; x++)
49+
{
50+
var c = context.getImageData(x, y, 1, 1);
51+
var s = "#" + colorToHex(c.data[0]) + colorToHex(c.data[1]) + colorToHex(c.data[2]);
52+
53+
if (s == previousColor)
54+
{
55+
line = line + ' ';
56+
}
57+
else
58+
{
59+
line = line + '%c ';
60+
css = css + "'background: " + s + "', ";
61+
previousColor = s;
62+
}
63+
}
64+
65+
css = css.substr(0, css.length - 2);
66+
67+
result = result + "console.log('" + line + "', " + css + ");\n";
68+
}
69+
70+
document.getElementById('output').innerHTML = result;
71+
72+
}
73+
74+
/**
75+
* Return a string containing a hex representation of the given color
76+
*
77+
* @method colorToHexstring
78+
* @param {Number} color The color channel to get the hex value for, must be a value between 0 and 255)
79+
* @return {String} A string of length 2 characters, i.e. 255 = FF, 0 = 00
80+
*/
81+
function colorToHex(color) {
82+
83+
var digits = "0123456789ABCDEF";
84+
85+
var lsd = color % 16;
86+
var msd = (color - lsd) / 16;
87+
88+
var hexified = digits.charAt(msd) + digits.charAt(lsd);
89+
90+
return hexified;
91+
92+
}
93+
94+
function update() {
95+
}
96+
97+
function render() {
98+
}
99+
100+
})();
101+
102+
</script>
103+
104+
</body>
105+
</html>

src/core/World.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -105,84 +105,84 @@ Phaser.World.prototype = {
105105

106106
},
107107

108-
swapChildren: function (stage, node1, node2) {
108+
swapChildren: function (stage, child1, child2) {
109109

110-
if (node1 === node2 || !node1.parent || !node2.parent)
110+
if (child1 === child2 || !child1.parent || !child2.parent)
111111
{
112-
console.warn('You cannot swap a node with itself or swap un-parented nodes');
112+
console.warn('You cannot swap a child with itself or swap un-parented children');
113113
return;
114114
}
115115

116-
// Cache the node values
117-
var node1Prev = node1._iPrev;
118-
var node1Next = node1._iNext;
119-
var node2Prev = node2._iPrev;
120-
var node2Next = node2._iNext;
116+
// Cache the values
117+
var child1Prev = child1._iPrev;
118+
var child1Next = child1._iNext;
119+
var child2Prev = child2._iPrev;
120+
var child2Next = child2._iNext;
121121

122122
var endNode = stage.last._iNext;
123123
var currentNode = stage.first;
124124

125125
do
126126
{
127-
if (currentNode !== node1 && currentNode !== node2)
127+
if (currentNode !== child1 && currentNode !== child2)
128128
{
129-
if (currentNode.first === node1)
129+
if (currentNode.first === child1)
130130
{
131-
currentNode.first = node2;
131+
currentNode.first = child2;
132132
}
133-
else if (currentNode.first === node2)
133+
else if (currentNode.first === child2)
134134
{
135-
currentNode.first = node1;
135+
currentNode.first = child1;
136136
}
137137

138-
if (currentNode.last === node1)
138+
if (currentNode.last === child1)
139139
{
140-
currentNode.last = node2;
140+
currentNode.last = child2;
141141
}
142-
else if (currentNode.last === node2)
142+
else if (currentNode.last === child2)
143143
{
144-
currentNode.last = node1;
144+
currentNode.last = child1;
145145
}
146146
}
147147

148148
currentNode = currentNode._iNext;
149149
}
150150
while (currentNode != endNode)
151151

152-
if (node1._iNext == node2)
152+
if (child1._iNext == child2)
153153
{
154-
// This is an A-B neighbour swap
155-
node1._iNext = node2Next;
156-
node1._iPrev = node2;
157-
node2._iNext = node1;
158-
node2._iPrev = node1Prev;
159-
160-
if (node1Prev) { node1Prev._iNext = node2; }
161-
if (node2Next) { node2Next._iPrev = node1; }
154+
// This is a downward (A to B) neighbour swap
155+
child1._iNext = child2Next;
156+
child1._iPrev = child2;
157+
child2._iNext = child1;
158+
child2._iPrev = child1Prev;
159+
160+
if (child1Prev) { child1Prev._iNext = child2; }
161+
if (child2Next) { child2Next._iPrev = child1; }
162162
}
163-
else if (node2._iNext == node1)
163+
else if (child2._iNext == child1)
164164
{
165-
// This is a B-A neighbour swap
166-
node1._iNext = node2;
167-
node1._iPrev = node2Prev;
168-
node2._iNext = node1Next;
169-
node2._iPrev = node1;
170-
171-
if (node2Prev) { node2Prev._iNext = node1; }
172-
if (node1Next) { node2Next._iPrev = node2; }
165+
// This is am upward (B to A) neighbour swap
166+
child1._iNext = child2;
167+
child1._iPrev = child2Prev;
168+
child2._iNext = child1Next;
169+
child2._iPrev = child1;
170+
171+
if (child2Prev) { child2Prev._iNext = child1; }
172+
if (child1Next) { child2Next._iPrev = child2; }
173173
}
174174
else
175175
{
176-
// Nodes are far apart
177-
node1._iNext = node2Next;
178-
node1._iPrev = node2Prev;
179-
node2._iNext = node1Next;
180-
node2._iPrev = node1Prev;
181-
182-
if (node1Prev) { node1Prev._iNext = node2; }
183-
if (node1Next) { node1Next._iPrev = node2; }
184-
if (node2Prev) { node2Prev._iNext = node1; }
185-
if (node2Next) { node2Next._iPrev = node1; }
176+
// Children are far apart
177+
child1._iNext = child2Next;
178+
child1._iPrev = child2Prev;
179+
child2._iNext = child1Next;
180+
child2._iPrev = child1Prev;
181+
182+
if (child1Prev) { child1Prev._iNext = child2; }
183+
if (child1Next) { child1Next._iPrev = child2; }
184+
if (child2Prev) { child2Prev._iNext = child1; }
185+
if (child2Next) { child2Next._iPrev = child1; }
186186
}
187187
}
188188

0 commit comments

Comments
 (0)