orz像素脸图。。。

随机对称生成的脸图【?】

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>orz</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link rel="stylesheet">
</head>
<body style="text-align:center;background-color:#1e576b">
	<div>
		<input type="text" id="dim" placeholder="dim"/>
		<input type="button" id="submit" value="submit"/>
	</div>
	<div style="margin:1em"><canvas id="logoCanvas"></canvas></div>
</body>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>

<script type="text/javascript">
	function draw(w, h) {
		
		var w = w || 8;
		var h = h || 8;
		var border = 12;
		var val = [];
		for (var i = 0; i < h; i += 1) {
			var str = [];
			for (var j = 0; j < w / 2; j += 1) {
				var rand = parseInt(Math.random() * 2);
				str[j] = rand;
				str[w - j] = rand;
			}
			val.push(str.join(""));
			console.log(str.join(""));
		}
		
		var canvas=document.getElementById('logoCanvas');
		var fillWidth = border * w;
		var fillHeight = border * h;
		$(canvas).attr("height", fillHeight + "px");
		$(canvas).attr("width", fillWidth + "px");
		var ctx=canvas.getContext('2d');
		ctx.clearRect(0, 0, fillWidth, fillHeight);
		for (var y = 0; y < h; y += 1) {
			for (var x = 0; x < w; x += 1) {
				ctx.fillStyle= val[y][x] == "1" ? '#000' : '#FFF';
				console.log("x y v, %d %d %s", x, y, val[y][x]);
				ctx.fillRect(x * border, y * border, border, border);
			}
		}
	}
	$(document).ready(function() {
		draw();
		$("#submit").click(function(){
			var d = $("#dim").val();
			draw(d, d);
		});
	});

</script>
</html>

唔……

 

 

脑壳logo

<html>
<body style="text-align:center;background-color:#1e576b">
	<canvas id="logoCanvas"></canvas>
</body>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>

<script type="text/javascript">
	function drawLogo() {
		var w = 11;
		var h = 17;
		var border = 24;
		var map = [
			[1,1,1,1,1,1,1,1,1,1,1],
			[1,0,0,0,0,0,0,0,0,0,1],
			[1,0,1,0,1,1,1,1,1,0,1],
			[1,0,1,0,0,0,0,0,1,0,1],
			[1,0,1,0,1,1,1,0,1,0,1],
			[1,0,1,0,1,0,1,0,1,0,1],
			[1,0,1,0,1,0,1,0,1,0,1],
			[1,0,1,0,0,0,0,0,1,0,1],
			[1,0,1,1,1,0,1,1,1,0,1],
			[1,0,1,0,0,0,0,0,1,0,1],
			[1,0,1,0,1,1,1,0,1,0,1],
			[1,0,1,0,1,0,0,0,1,0,1],
			[1,0,1,0,1,1,1,0,1,0,1],
			[1,0,1,0,0,0,0,0,1,0,1],
			[1,0,1,1,1,0,1,1,1,0,1],
			[1,0,0,0,0,0,0,0,0,0,1],
			[1,0,0,0,0,0,0,0,0,0,1]
		]
		var canvas=document.getElementById('logoCanvas');
		var fillWidth = border * w;
		var fillHeight = border * h;
		$(canvas).attr("height", fillHeight + "px");
		$(canvas).attr("width", fillWidth + "px");
		var ctx=canvas.getContext('2d');
		ctx.clearRect(0, 0, fillWidth, fillHeight);
		for (var y = 0; y < h; y += 1) {
			for (var x = 0; x < w; x += 1) {
				if (map[y][x] == 0) {continue;}
				ctx.fillStyle='#FFF';
				ctx.fillRect(x * border, y * border, border, border);
			}
		}
	}
	$(document).ready(function() {
		drawLogo();

	});

</script>
</html>
 

某烟火(canvas)

<html>
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8">
	</head>
	<body style="margin:0;" onload="start();">
		<canvas id="_canvas"></canvas>		
	</body>
	
		<script>
			// 烟火
			function Fire(x, y, life, directionX, directionY) {
				this.x = x;
				this.y = y;
				this.life = life;
				this.frames = 0;	// 帧数计时
				this.directionX = directionX;
				this.directionY = directionY;
				this.color = "rgb(" + Math.floor(Math.random() * 128 + 128) + "," + Math.floor(Math.random() * 128 + 128) + "," + Math.floor(Math.random() * 128 + 128) +")";
			}
			Fire.prototype = {
				// 行进
				move : function() {
					this.x += this.directionX;
					this.y += this.directionY;
					this.directionX *= 0.94;
					this.directionY *= 0.94;
					this.directionY += 0.3;
					this.frames += 1;
				},
				// 失效
				powerOut : function() {
					return this.frames == this.life;
				},
				x : function() {
					return this.x;
				},
				y : function() {
					return this.y;
				},
				color : function() {
					return this.color;
				}
			}
			// 烟花
			function FirePackage(x, y) {
				this.x = x;
				this.y = y;
				this.fires = new Array();
			}
			FirePackage.prototype = {
				createFires : function(num) {
					// 添加烟火
					if (!num) {
						num = Math.floor(Math.random() * 50) + 10;
					}
					for (var i = 0; i < num; i += 1) {
						var life = Math.floor(Math.random() * 80) + 40;
						this.fires[i] = new Fire(this.x, this.y, life, Math.random() * 20 * (Math.random() * 10 >=5 ? (-1) : 1), Math.random() * 20 * (Math.random() * 10 >= 5 ? (-1) : 1));
					}
				},
				boom : function(ctx) {
					var powerOutCount = 0;
					if (this.powerOut()) {
						return;
					}
					for (var i = 0; i < this.fires.length; i += 1) {
						var fire = this.fires[i];
						if (!fire.powerOut()) {
							fire.move();
							ctx.fillStyle= fire.color;
							ctx.beginPath();
							//console.clear();
							//console.log("fire.x :" + fire.x, "fire.y:" + fire.y);
							//console.log("fire.color :" + fire.color);
							ctx.arc(fire.x,fire.y,5,0,Math.PI*2,true);
							ctx.closePath();
							ctx.fill();
						} else {						
							powerOutCount += 1;
						}
					}
					if (powerOutCount == this.fires.length) {
						this.powerOutFlag = true;
					}
				},
				powerOut : function() {
					return this.powerOutFlag ? true : false;
				}
			}
		</script>
		<script>
		var canvas = document.getElementById('_canvas');
		canvas.width = window.innerWidth;
		canvas.height = window.innerHeight;
		
		var ctx=canvas.getContext('2d');
		var timeInterval;
		window.onresize = function() {
			canvas.width = window.innerWidth;
			canvas.height = window.innerHeight;
		}
		var firePackages = new Array();
		function createFirePackage(x, y) {
			var firePackage = new FirePackage(x, y);
			firePackage.createFires();
			firePackages.push(firePackage);
		}
		var pushInterval;
		var pushFire = function() {
			clearInterval(pushInterval);
			createFirePackage(Math.random() * canvas.width , Math.random() * canvas.height);
			pushInterval = setInterval(pushFire, Math.random() * 1000 + 100);
		}
		function start() {
			var loop = function() {
				if (firePackages.length == 0) {
					createFirePackage(Math.random() * canvas.width , Math.random() * canvas.height);
				}
				var powerOutCount = 0;
				var border = 320;
				for (var i = 0; i < firePackages.length; i += 1) {
					var firePackage = firePackages[i];
					ctx.fillStyle="rgba(0,0,0,0.1)";
					ctx.fillRect(0,0,canvas.width,canvas.height);
					if  (!firePackage.powerOut()) {
						firePackage.boom(ctx);
					} else {
						firePackages[i] = firePackages[firePackages.length - 1];
						firePackages.pop();
					}
				}
				var border = 360;
				ctx.fillStyle="rgba(255,0,0,1)";
				ctx.font = border + "px 黑体";
				ctx.fillText("囍",(canvas.width - border) / 2, border);
			}
			timeInterval = setInterval(loop, 10);
			pushFire();
			loop();
		}
		</script>
</html>

bat遍历文件夹...

@echo off 
set work_path=./res
cd %work_path% 
for /R %%s in (.,*) do ( 
echo %%s 
) 

JavaScript拖拽文件作为背景图

<!DOCTYPE HTML>
<html>
<head>

</head>
<body>
DROP!!!!!!!!!!
<script type="text/javascript">
function chgImg(evt) {	
    var reader = evt.target;  
	console.log(reader.result);
    var file = reader.file;      
    document.getElementsByTagName("body")[0].setAttribute("style","background-image:url(" + reader.result + ");"); 
}
document.ondragstart = function(e) {
    e.preventDefault();
}
document.ondragover = function(e) {
	e.dataTransfer.dragEffect = 'copy';
    e.preventDefault();
}
document.ondrop = function(e){
	var files = e.dataTransfer.files;
	for(var i = 0, len = files.length; i < len; i++)
	{
		var f = files[i];
		if (f.type.indexOf("image") == -1) {continue;}
        var reader = new FileReader();
        reader.onloadend = chgImg;
        reader.file = f;
        reader.readAsDataURL(f);
	}
    e.preventDefault();
}

</script>
</body>
</html>

ScrollView的scrollToPercentHorizontal滚动距离相关笔记

手册:

scrollToPercentHorizontal(float percent, float time, bool attenuated);//水平滚动容器内容到滚动视图宽度百分比位置上

然而这并没有什么卵用。

 

笔记:

第一个参数percent将使内部容器向左滚动(内部容器宽度 - 滚动层宽度) * percent 像素的距离

第二个参数time为滚动时间,单位为秒

第三个参数attenuated为true时使滚动过程拥有减速效果

 

所以想要使内部容器0.5s内减速向左滚动x像素可以调用

float percent = 100.0f * x / (scroll->getInnerContainerSize().width - scroll->getContentSize().width)

scroll->scrollToPercentHorizontal(percent, 0.5f, true);

 

从前的一个A*

以前的一个a*练习,搬过来凑个数……

A*算法描述见这篇博文

ruby代码:

#encoding=utf-8
MAP = [
		[0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 1, 0, 0, 0, 0],
		[0, 0, 0, 1, 0, 0, 0, 0],
		[0, 0, 0, 1, 1, 0, 1, 0],
		[0, 0, 0, 1, 0, 0, 0, 0],
		[0, 0, 0, 1, 0, 0, 0, 0],
		[0, 0, 0, 1, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0],		
	  ]		
class Point
	attr_accessor		:x
	attr_accessor		:y
	attr_accessor		:g
	attr_accessor		:h
	attr_accessor		:f
	attr_accessor		:parent
	def initialize(x, y, parent)
		self.x = x
		self.y = y
		self.parent = parent
	end
	def to_s
		"#{super.to_s}, #{[self.x, self.y, self.g, self.h, self.f]}"
	end
end

$open = {}
$close = {}

def find(sx, sy, ex, ey)
	startP = Point.new(sx, sy, nil)
	startP.g = 0
	pos = startP
	while (!$open[[ex, ey]]) do
		dealAround(pos, ex, ey)	# 检查周围元素,计算f
		pos = getMinFPos
	end
	pos = $open[[ex, ey]]
	path = []
	while (pos.parent) do
		path << [pos.x, pos.y]
		pos = pos.parent
	end
	path << [pos.x, pos.y]
	for y in 0...MAP.size
		for x in 0...MAP[0].size
			print (path.include?([x, y])) ? "☆" : (MAP[y][x] == 0 ? "□" : "■")
		end
		print "\r\n"
	end
	p path
end
def getMinFPos
	return nil if $open.size < 1
	minG = $open.values[0].g
	minGPos = $open.values[0]
	$open.values.each{|pos|
		if minG > pos.g
			minG = pos.g
			minGPos = pos
		end
	}
	return minGPos
end
def dealAround(pos, endx, endy)
	# 将pos加入close列表
	$close[[pos.x, pos.y]] = pos	
	# 将pos从open列表中移出
	$open.delete([pos.x, pos.y])
	# 检查周围元素
	[[-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1]].each{|posOffset|
		# 跳过边界
		next if pos.x + posOffset[0] < 0 or pos.y + posOffset[1] < 0 or pos.x + posOffset[0] > MAP[0].size - 1 or pos.y + posOffset[1] > MAP.size - 1
		# 跳过不可通行的方块
		next if MAP[pos.y + posOffset[1]][pos.x + posOffset[0]] != 0
		# 跳过close列表
		next if $close[[pos.x + posOffset[0], pos.y + posOffset[1]]]
		
		newPos = Point.new(pos.x + posOffset[0], pos.y + posOffset[1], pos)
		# 计算g
		if posOffset[0].abs + posOffset[1].abs == 2 # 斜向
			newPos.g = pos.g + 14
		else
			newPos.g = pos.g + 10
		end
		# 计算h
		newPos.h = (endx - newPos.x).abs * 10 + (endy - newPos.y).abs * 10
		# 计算f
		newPos.f = newPos.g + newPos.h
		# 添加到open列表
		if $open[[newPos.x, newPos.y]] # 已存在
			thePos = $open[[newPos.x, newPos.y]]	
			tempG = ((thePos.x - pos.x).abs + (thePos.y - pos.y).abs == 2) ? (pos.g + 14) : (pos.g + 10)
			if tempG < thePos.g	# 当前节点使g更小
				thePos.g = tempG
				thePos.f = tempG + thePos.h
				thePos.parent = pos	# 修改父节点为当前节点
			end
		else	# 不存在
			$open[[newPos.x, newPos.y]] = newPos
		end
	}
end

find(0, 0, 7, 7)

 

实、实验报告......

TAT以下是折腾docker折腾quick-server0.4.0的经历,而非过程
 
 
查看镜像:
docker@boot2docker:~$ docker images
 
运行镜像并进到bash模式,映射8080端口到宿主50002端口:
docker@boot2docker:~$ docker run -t -i -p 50002:8080 chukong/quick-server:0.4.0
 
关闭镜像并保存:
记下当前id: |root@ID| ←
|root@ID| exit
docker@boot2docker:~$ docker commit ID chukong/quick-server:0.4.0
 
开启ssh后台运行镜像:
docker@boot2docker:~$ docker run -d -p 50003:22 chukong/quick-server:0.4.0 /usr/sbin/sshd -D
 
创建用户sure52:
|root@ID| useradd sure52
|root@ID| passwd sure52
 
建立git仓库:
|root@ID| cd /home/sure52
|root@ID| mkdir qs_code
|root@ID| chmod o+w -R qs_code
|root@ID| cd qs_code
|root@ID| git init
|root@ID| vim README.md
|root@ID| git add "."
|root@ID| git commit -m "base version"

|root@ID| git remote add origin ssh://sure52@127.0.0.1/home/sure52/qs_code/.git
|root@ID| git push origin
|root@ID| git remote show origin
 
测试git仓库
E:\> git clone ssh://sure52@192.168.59.103:50003/home/sure52/qs_code/.git
 
push 无写权限remote: fatal: failed to write object解决:
|root@ID| chmod -R 777 .git
 
push master -> master (branch is currently checked out)出错解决:
|root@ID| cd .git
|root@ID| vi config
    添加:    
       [receive]
       denyCurrentBranch = ignore
 
Quick-Server取session_id:
curl "http://192.168.59.103:50002/_server/user/session/?id=sure52"
 
提交usercode:
    本地路径结构:
    module1/actions/SayHello.lua
    提交至
    /home/sure52/qs_code/module1/actions/Sayhello.lua
    实际运行时
    /opt/qs/openresty/server/user_codes/module1/actions/SayHello.lua
    config.lua配置:
userDefinedCodes = {
	luaRepoPrefix = "server.user_codes",
	localRepo  = "/home/sure52/qs_code/",
	localDest  = "/opt/qs/openresty/server/user_codes",
	--localRepo = "/home/cheeray/work/user_codes",
	--localDest = "/home/cheeray/work/quick-server/src/server/user_codes",
	uriPrefix  = {
		module1 = "http_test1",
		module2 = "http_test2",
	},
},
    运行命令:
curl "http://192.168.59.103:50002/_Server/user/uploadcodes?commit=f54ab5e0ddd0d93b55ae4f9169c25caf52a88392&session_id=f56b3cb7fc96dfb25e501c56e8f9b057"
 
sayHello:
curl "http://192.168.59.103:50002/http_test1/Say/SayHello?session_id=f56b3cb7fc96dfb25e501c56e8f9b057&name=a_name"
 
因为用的是坑爹windows……
让本机localhost:8088能直接连到容器内:(windows 127.0.0.1:8088->docker虚拟机192.168.59.103:50002->容器内x.x.x.x:8088)
    在virtual box中做本机端口映射
        VM -> 设置 -> 网络 -> 网卡1 -> 端口转发 添加
        名称任意 协议:TCP 主机IP:127.0.0.1 主机端口:8088 子系统IP不填 子系统端口:50002
 
参考:
    http://www.cnblogs.com/bjfuouyang/p/3798421.html
 
 

【未完成】Window_Message(雾。。。

= =唔

 

--[[
local labelEx = require("ui.ui_label_ex"):create(300) -- width
l:addChild(labelEx, 100)
labelEx:setPosition(100, self.visibleSize.height)
labelEx:setString("普通文字$C<3>颜色$C<1>普通颜色$S<36>大小$S<0>普通大小$I<101>←图片$B<button>按钮$E<99>表情\n换\n行")

]]--
local UILabelEx = class("UILabelEx", require("ui.ui_common"))

-- 控制字符
UILabelEx.C_CHR = "$"
-- 单字显示时间间隔
UILabelEx.WAIT_FOR_MESSAGE = 5 / 60
-- 默认字号
UILabelEx.DEFAULT_FONT_SIZE = 24	
-- 行间距
UILabelEx.DEFAULT_LINE_HEIGHT = 12	


function UILabelEx:ctor(width, show_fast)
    UILabelEx.super.ctor(self, "")

    self._defaultFontSize = UILabelEx.DEFAULT_FONT_SIZE
    self._lineHeight = UILabelEx.DEFAULT_LINE_HEIGHT
    self._width = width
    self._show_fast = not not show_fast
    self._height = self._defaultFontSize
	self._rootWgt = ccui.Layout:create()
	self:addChild(self._rootWgt, 100)
    self:clear()
end

function UILabelEx:clear()
    self._contentStr = ""

    self._texts = self._texts or {}	-- 文字
    self._images = self._images or {}	-- 图片
    self._widgets = self._widgets or {}	-- 按钮等
    self._armatures = self._armatures or {}	-- 动画
    self._contents = self._contents or {}	-- 包含文字图片等实际顺序的数组
    self._currentLine = self._currentLine or {}	-- 渲染中的本行元素
    self._strIndex = 1 -- 遍历的当前字符
    self._currentColor = 1 	-- 当前文字颜色
    self._currentFontSize = self._defaultFontSize 	-- 当前文字大小

    for k, v in pairs(self._texts) do
    	v:removeFromParent()
    	self._texts[k] = nil
    end
    for k, v in pairs(self._images) do
    	v:removeFromParent()
    	self._images[k] = nil
    end
    for k, v in pairs(self._widgets) do
    	v:removeFromParent()
    	self._widgets[k] = nil
    end
    for k, v in pairs(self._armatures) do
    	v:removeFromParent()
    	self._armatures[k] = nil
    end
    self._texts = {}
    self._images = {}
    self._widgets = {}
    self._armatures = {}
    self._contents = {}
    self._renderPos = {
    					x = 0, 
    					y = 0,
    					maxHeight = self._defaultFontSize 	-- 记录本行最大高度
    				}
    self._currentLine = {}

    if self._scheduleShow ~= nil then
		cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self._scheduleShow)
	end	
    self._scheduleShow = nil
    self._showSeq = 0
end


-- 判断utf8字符byte长度
-- 0xxxxxxx - 1 byte
-- 110yxxxx - 192, 2 byte
-- 1110yyyy - 225, 3 byte
-- 11110zzz - 240, 4 byte
local function chsize(char)
    if not char then
        print("not char")
        return 0
    elseif char > 240 then
        return 4
    elseif char > 225 then
        return 3
    elseif char > 192 then
        return 2
    else
        return 1
    end
end

-- 计算utf8字符串字符数, 各种字符都按一个字符计算
-- 例如utf8len("1你好") => 3
local function utf8len(str)
    local len = 0
    local currentIndex = 1
    while currentIndex <= #str do
        local char = string.byte(str, currentIndex)
        currentIndex = currentIndex + chsize(char)
        len = len +1
    end
    return len
end

-- 截取utf8 字符串
-- str:         要截取的字符串
-- startChar:   开始字符下标,从1开始
-- numChars:    要截取的字符长度
local function utf8sub(str, startChar, numChars)
    local startIndex = 1
    while startChar > 1 do
        local char = string.byte(str, startIndex)
        startIndex = startIndex + chsize(char)
        startChar = startChar - 1
    end

    local currentIndex = startIndex

    while numChars > 0 and currentIndex <= #str do
        local char = string.byte(str, currentIndex)
        currentIndex = currentIndex + chsize(char)
        numChars = numChars -1
    end
    return str:sub(startIndex, currentIndex - 1)
end


function UILabelEx:onEnter()
	self:ignoreAnchorPointForPosition(false)
	self:setAnchorPoint(0, 1)
end

function UILabelEx:onExit()
	self:clear()
end

-- 根据代码取文字颜色
function UILabelEx:getColor(code)
	code = code or 1
	local colors = {
					cc.c3b(255, 255, 255),	-- 白色
					cc.c3b(0, 0, 0),			-- 黑色
					cc.c3b(255, 0, 0),			-- 红色
					cc.c3b(0, 255, 0),			-- 绿色
					cc.c3b(0, 0, 255),			-- 蓝色
					cc.c3b(0, 255, 255)			-- 黄色
					}

	return colors[code] or colors[1]
end

function UILabelEx:setDefaultFontSize(size)
	size = size or self._defaultFontSize
	if size <= 0 then size = self._defaultFontSize end
	self._defaultFontSize = size
end

function UILabelEx:setString(str)
	self:clear()
	self._contentStr = str
	self:refresh()
	self._scheduleShow = cc.Director:getInstance()
								:getScheduler()
								:scheduleScriptFunc(handler(self, self.scheduleShow), 
														UILabelEx.WAIT_FOR_MESSAGE, 
														false)
end

--[[
"普通文字\eC[color]颜色\eC[1]普通\n颜色\eS[size]大小\eS[24]普通大小\eI[img]←图片\eB[button]按钮\eE[emj]表情"
]]--
function UILabelEx:refresh()
	print(utf8len(self._contentStr))	
	while self._strIndex <= utf8len(self._contentStr) do
		self:progressContentString()
	end
	if self._show_fast then self._seq = #self._contents end
	self:nextLine()
	self._height = self._renderPos.y
	self._rootWgt:ignoreAnchorPointForPosition(false)
	self._rootWgt:setAnchorPoint(cc.p(0, 1))
	self._rootWgt:setBackGroundColorType(ccui.LayoutBackGroundColorType.solid)
 	self._rootWgt:setBackGroundColor(cc.c3b(128, 128, 128))
	self._rootWgt:setContentSize(self._width, self._height)
end

-- 处理特殊字符
function UILabelEx:progressContentString()
	local str = utf8sub(self._contentStr, self._strIndex, 1)
	self._strIndex = self._strIndex + 1
	-- print("str:"..str)
	
	if str == "\r" then 			-- 回车
		return
	elseif str == "\n" then 		-- 换行
		self:progressNewLine()
	elseif str == UILabelEx.C_CHR then 		-- 控制符
		-- 处理中会影响self._strIndex
		self:progressControlChar()
	else 							-- 普通文字
		self:progressNormalText(str)
	end
	
end

-- 换行
function UILabelEx:progressNewLine()
	self:nextLine()
end

-- 控制符
function UILabelEx:progressControlChar()
	local chr = utf8sub(self._contentStr, self._strIndex, 1)
	self._strIndex = self._strIndex + 1
	chr = string.upper(chr)
	-- print("char:"..chr)
	local progressFlag = false 	-- 是否正常解析
	local s, e, val = string.find(self._contentStr, "<(.-)>", string.len(utf8sub(self._contentStr, 1, self._strIndex)))
	if val and s == string.len(utf8sub(self._contentStr, 1, self._strIndex)) then
		progressFlag = true
		print("val:"..(val ~= nil and val or "nil"))
		if chr == "C" then
			progressFlag = self:changeFontColor(tonumber(val))	-- 修改颜色
		elseif chr == "S" then
			progressFlag = self:changeFontSize(tonumber(val))	-- 修改字号
		elseif chr == "I" then
			progressFlag = self:progressImage(tonumber(val))	-- 插入图片
		elseif chr == "B" then
			progressFlag = self:progressBtn(val)		-- 插入按钮
		elseif chr == "E" then
			progressFlag = self:progressEmoji(tonumber(val))	-- 插入表情
		end
	end
	if progressFlag then
		self._strIndex = self._strIndex + utf8len(val) + 2
	else -- 处理失败,当做通常字符处理		
		self._strIndex = self._strIndex - 2
		local str = utf8sub(self._contentStr, self._strIndex, 1)
		self._strIndex = self._strIndex + 1		
		self:progressNormalText(str)
	end
end

-- 普通文字
function UILabelEx:progressNormalText(chr)
	print("progress normal:"..chr)
	local uiText = ccui.Text:create()	
    uiText:setString(chr)
    uiText:setVisible(self._show_fast)
    uiText:setFontSize(self._currentFontSize)
    uiText:setColor(self:getColor(self._currentColor))
    self:addChild(uiText, 100)

    if uiText:getContentSize().width > self._width then
    	print("too big width, scaled")
    	uiText:setScale(self._width / uiText:getContentSize().width)
    end
    if self._renderPos.x + uiText:getContentSize().width > self._width then
    	self:nextLine()
	end

    self:setElemPosition(uiText, self._renderPos.x, self._renderPos.y)
    self._renderPos.x = self._renderPos.x + uiText:getContentSize().width
    self._renderPos.maxHeight = (self._renderPos.maxHeight > uiText:getContentSize().height) and self._renderPos.maxHeight or uiText:getContentSize().height

    self._texts[#self._texts + 1] = uiText

    self._contents[#self._contents + 1] = uiText
    self._currentLine[#self._currentLine + 1] = uiText
    return true
end

function UILabelEx:changeFontColor(code)
	if not code then return false end
	self._currentColor = code
	return true
end

function UILabelEx:changeFontSize(code)
	if not code then return false end
	if code <= 0 then code = self._defaultFontSize end
	self._currentFontSize = code
	return true
end

function UILabelEx:progressImage(code)
	if not code then return end
	print("progress image:"..code)
	local image = t_image[code]
	if not image then return false end
	cc.SpriteFrameCache:getInstance():addSpriteFrames(image.plist)
	local uiImage = ccui.ImageView:create()	
    uiImage:loadTexture(image.name, ccui.TextureResType.plistType)
    uiImage:setVisible(self._show_fast)
    self:addChild(uiImage, 100)

    if uiImage:getContentSize().width > self._width then
    	print("too big width, scaled")
    	uiImage:setScale(self._width / uiImage:getContentSize().width)
    end
    if self._renderPos.x + uiImage:getContentSize().width > self._width then
    	self:nextLine()
	end

    self:setElemPosition(uiImage, self._renderPos.x, self._renderPos.y)
    self._renderPos.x = self._renderPos.x + uiImage:getContentSize().width
    self._renderPos.maxHeight = (self._renderPos.maxHeight > uiImage:getContentSize().height) and self._renderPos.maxHeight or uiImage:getContentSize().height

    self._images[#self._images + 1] = uiImage

    self._contents[#self._contents + 1] = uiImage
    self._currentLine[#self._currentLine + 1] = uiImage
    return true
end

function UILabelEx:progressBtn(str)
	return false
end

function UILabelEx:progressEmoji(code)	
	if not code then return false end
	print("progress emoji:"..code)
	local animation = t_animation[code]
	if not animation then return false end
	ccs.ArmatureDataManager:getInstance():addArmatureFileInfo(animation.json)
	local armature = ccs.Armature:create(animation.name)
	armature:getAnimation():play("effect")
	armature:setVisible(self._show_fast)
    self:addChild(armature, 100)

    if armature:getContentSize().width > self._width then
    	print("too big width, scaled")
    	armature:setScale(self._width / armature:getContentSize().width)
    end
    if self._renderPos.x + armature:getContentSize().width > self._width then
    	self:nextLine()
	end

    self:setElemPosition(armature, self._renderPos.x, self._renderPos.y)
    self._renderPos.x = self._renderPos.x + armature:getContentSize().width
    self._renderPos.maxHeight = (self._renderPos.maxHeight > armature:getContentSize().height) and self._renderPos.maxHeight or armature:getContentSize().height

    self._armatures[#self._armatures + 1] = armature

    self._contents[#self._contents + 1] = armature
    self._currentLine[#self._currentLine + 1] = armature
    return true
end

function UILabelEx:setElemPosition(elem, _x, _y)
	elem:ignoreAnchorPointForPosition(false)
	elem:setAnchorPoint(cc.p(0,0))
	if _x then
    	local x = _x + elem:getContentSize().width * elem:getAnchorPoint().x
    	elem:setPositionX(x)
    end
    if _y then
    	local y = _y + elem:getContentSize().height * elem:getAnchorPoint().y
    	elem:setPositionY(-y)
    end
end

function UILabelEx:nextLine()
	-- 调整当前行元素高度,适应maxHeight
	for k, v in pairs(self._currentLine) do
		self:setElemPosition(v, nil, self._renderPos.y + self._renderPos.maxHeight)
	end
	self._renderPos.x = 0
	self._renderPos.y = self._renderPos.y + self._renderPos.maxHeight + self._lineHeight / 2
	self._renderPos.maxHeight = self._defaultFontSize
	self._currentLine = {}
end

function UILabelEx:scheduleShow(dt)
	if self._showSeq < #self._contents then		
		self._showSeq = self._showSeq + 1
		self._contents[self._showSeq]:setVisible(true)
	end
end

return UILabelEx

 

还没完成就是了。。。

 

切切切...

require 'sdl'
require "rexml/document"  
include REXML  
SDL.init(SDL::INIT_VIDEO)

row = 4
col = 4

filename = "citizen-1.png"
image = SDL::Surface.load(filename)
w, h = image.w, image.h
if filename[/^(.*)?\.(png|jpg|bmp)?/i]
	p $1, $2
end

picname = $1
ext = $2


doc = Document.new("<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">")
doc << XMLDecl.new(1.0, "utf-8")
root_node = doc.add_element("plist")
root_node.attributes["version"] = "1.0"
root_dict = root_node.add_element("dict") 

# frames
frame_key = root_dict.add_element("key")
frame_key.text = "frames"
frame_dict =  root_dict.add_element("dict")

for i in 0...row
	for j in 0...col
		key = Element.new("key")
		key.text = "#{picname}_#{i * col + j}.#{ext}"
		dict = Element.new("dict")
		# dict
		ek = []
		ev = []
		
		ek[0] = Element.new("key")
		ek[0].text = "width"
		ev[0] = Element.new("integer")
		ev[0].text = (w / col).to_s
		
		ek[1] = Element.new("key")
		ek[1].text = "height"
		ev[1] = Element.new("integer")
		ev[1].text = (h / row).to_s
		
		ek[2] = Element.new("key")
		ek[2].text = "originalWidth"
		ev[2] = Element.new("integer")
		ev[2].text = (w / col).to_s
		
		ek[3] = Element.new("key")
		ek[3].text = "originalHeight"
		ev[3] = Element.new("integer")
		ev[3].text = (h / row).to_s
		
		ek[4] = Element.new("key")
		ek[4].text = "x"
		ev[4] = Element.new("integer")
		ev[4].text = (j * w / row).to_s
		
		ek[5] = Element.new("key")
		ek[5].text = "y"
		ev[5] = Element.new("integer")
		ev[5].text = (i * h / col).to_s
		
		ek[6] = Element.new("key")
		ek[6].text = "offsetX"
		ev[6] = Element.new("real")
		ev[6].text = "0"
		
		ek[7] = Element.new("key")
		ek[7].text = "offsetY"
		ev[7] = Element.new("real")
		ev[7].text = "0"
		
		for t in 0...ek.size
			dict.elements << ek[t]
			dict.elements << ev[t]
		end
		
		frame_dict.elements << key
		frame_dict.elements << dict
		
		# end dict
	end
end
# end frames
	
# metadata
metadata_key = root_dict.add_element("key")
metadata_key.text = "metadata"
metadatat_dict =  root_dict.add_element("dict")

ek = []
ev = []

ek[0] = Element.new("key")
ek[0].text = "format"
ev[0] = Element.new("integer")
ev[0].text = "2"	

ek[1] = Element.new("key")
ek[1].text = "textureFileName"
ev[1] = Element.new("string")
ev[1].text = filename

ek[2] = Element.new("key")
ek[2].text = "realTextureFileName"
ev[2] = Element.new("string")
ev[2].text = filename

ek[3] = Element.new("key")
ek[3].text = "size"
ev[3] = Element.new("string")
ev[3].text = "{#{w},#{h}}"

for t in 0...ek.size
	metadatat_dict.elements << ek[t]
	metadatat_dict.elements << ev[t]
end
#end metadata

# texture
texture_key = root_dict.add_element("key")
texture_key.text = "texture"
texture_dict =  root_dict.add_element("dict")

ek = []
ev = []

ek[0] = Element.new("key")
ek[0].text = "width"
ev[0] = Element.new("integer")
ev[0].text = "#{w}"	

ek[1] = Element.new("key")
ek[1].text = "height"
ev[1] = Element.new("integer")
ev[1].text = "#{h}"

for t in 0...ek.size
	texture_dict.elements << ek[t]
	texture_dict.elements << ev[t]
end
# end texture

file = File.open("#{picname}.plist", "w")
doc.write(file, 4, false, true)
file.close

p doc.xml_decl()

bug啥的慢慢修。