--小黄人

if 文件是否存在(语录)==false then 写入文件(语录,"每教好一个孩子，就减少一个败类。——雨果") end

layout={
 LinearLayout,
 orientation="vertical",
 layout_width="fill",
 layout_height="fill",
 {
 TextView,
 textSize="18dp",
 id="tt",
 gravity="top|center";
 text=model_time,
 layout_marginTop="65dp";
 padding="30dp",
 layout_width="fill",
 layout_height="fill",
 },
}

require "import"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.*"
import "android.widget.LinearLayout"
import "android.widget.TextView"
import "android.graphics.SweepGradient"
import "com.androlua.LuaDrawable"
import "android.graphics.RectF"
import "android.graphics.DashPathEffect"
import "android.graphics.Color"
import "android.graphics.Path"
import "android.graphics.CornerPathEffect"

--activity.setTitle('AndroLua+')
--activity.setTheme(android.R.style.Theme_Holo_Light)
activity.setContentView(loadlayout(layout))

--[[
参见:
http://m.open-open.com/m/lib/view/1453336049620.html
]]


bg=LuaDrawable(function(c,p,d)
 bodyWidth = Math.min(activity.getWidth(), activity.getHeight() * 0.6) * 0.6;
 bodyHeigh = Math.min(activity.getWidth(), activity.getHeight() * 0.6) / 0.6 * 0.6;
 mStrokeWidth=4;
 mStrokeWidth = Math.max(bodyWidth / 50, mStrokeWidth);
 offset = mStrokeWidth / 2;
 colorStroke=Color.BLACK;
 colorClothes=Color.YELLOW
 colorBody=Color.rgb(249, 217, 70);
 b = RectF();
 b.left = (activity.getWidth() - bodyWidth) / 2;
 b.top = (activity.getHeight() - bodyHeigh) / 2;
 b.right = b.left + bodyWidth;
 b.bottom = b.top + bodyHeigh;

 radius = bodyWidth / 2;
 footHeigh = radius * 0.4333;

 handsHeight = (activity.getHeight() + bodyHeigh) / 2 + offset - radius * 1.65;


 -- Color.rgb(32, 116, 160)

 p.setColor(Color.YELLOW);
 p.setAntiAlias(true);
 p.setStyle(p.Style.FILL);
 p.setStrokeWidth(4);

 --画身体
 c.drawRoundRect(b, radius, radius, p);

 --身体后面的描边
 p.setColor(0xff000000);
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.STROKE);
 c.drawRoundRect(b, radius, radius, p);


 --穿上裤子
 rect = RectF();

 rect.left = (activity.getWidth() - bodyWidth) / 2 + offset;
 rect.top = (activity.getHeight() + bodyHeigh) / 2 - radius * 2 + offset;
 rect.right = rect.left + bodyWidth - offset * 2;
 rect.bottom = rect.top + radius * 2 - offset * 2;

 p.setColor(Color.rgb(32, 116, 160));
 p.setStyle(p.Style.FILL);
 p.setStrokeWidth(mStrokeWidth);
 c.drawArc(rect, 0, 180, true, p)

 --
 local h = radius * 0.5;
 local w = radius * 0.3;
 rect.left = rect.left + w;
 rect.top = rect.top + radius - h;
 rect.right = rect.right - w;
 rect.bottom = rect.top + h;
 c.drawRect(rect, p);


 -- //画横线

 p.setColor(Color.BLACK);
 p.setStyle(p.Style.FILL);
 p.setStrokeWidth(mStrokeWidth);
 pts = float[20];--5条线

 pts[0] = rect.left - w;
 pts[1] = rect.top + h;
 pts[2] = pts[0] + w;
 pts[3] = pts[1];

 pts[4] = pts[2];
 pts[5] = pts[3] + offset;
 pts[6] = pts[4];
 pts[7] = pts[3] - h;

 pts[8] = pts[6] - offset;
 pts[9] = pts[7];
 pts[10] = pts[8] + (radius - w) * 2;
 pts[11] = pts[9];

 pts[12] = pts[10];
 pts[13] = pts[11] - offset;
 pts[14] = pts[12];
 pts[15] = pts[13] + h;

 pts[16] = pts[14] - offset;
 pts[17] = pts[15];
 pts[18] = pts[16] + w;
 pts[19] = pts[17];
 c.drawLines(pts, p);

 --吊带
 --画左吊带

 p.setColor(Color.rgb(32, 116, 160));
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.FILL);
 path = Path();
 path.moveTo(rect.left - w - offset, handsHeight);
 path.lineTo(rect.left + h / 4, rect.top + h / 2);
 local smallW = w / 2 * Math.sin(Math.PI / 4);
 path.lineTo(rect.left + h / 4 + smallW, rect.top + h / 2 - smallW);
 local smallW2 = w / Math.sin(Math.PI / 4) / 2;
 path.lineTo(rect.left - w - offset, handsHeight - smallW2);

 c.drawPath(path, p);



 p.setColor(colorStroke);
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.STROKE);
 c.drawPath(path, p);

 p.setStyle(p.Style.FILL_AND_STROKE);
 c.drawCircle(rect.left + h / 4, rect.top + h / 4, mStrokeWidth, p);

 --画右吊带


 p.setColor(colorClothes);
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.FILL);
 path.reset();
 path.moveTo(rect.left - w + 2 * radius - offset, handsHeight);
 path.lineTo(rect.right - h / 4, rect.top + h / 2);
 path.lineTo(rect.right - h / 4 - smallW, rect.top + h / 2 - smallW);
 path.lineTo(rect.left - w + 2 * radius - offset, handsHeight- smallW2);

 c.drawPath(path, p);



 p.setColor(colorStroke);
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.STROKE);
 c.drawPath(path, p);



 p.setStyle(p.Style.FILL_AND_STROKE);
 c.drawCircle(rect.right - h / 4, rect.top + h / 4, mStrokeWidth, p);

 --//中间口袋

 p.setColor(colorStroke);
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.STROKE);

 path.reset();
 local radiusBigPokect = w / 2.0;
 path.moveTo(rect.left + 1.5 * w, rect.bottom - h / 4);
 path.lineTo(rect.right - 1.5 * w, rect.bottom - h / 4);
 path.lineTo(rect.right - 1.5 * w, rect.bottom + h / 4);
 path.addArc(rect.right - 1.5 * w - radiusBigPokect * 2, rect.bottom + h / 4 - radiusBigPokect,
 rect.right - 1.5 * w, rect.bottom + h / 4 + radiusBigPokect, 0, 90);
 path.lineTo(rect.left + 1.5 * w + radiusBigPokect, rect.bottom + h / 4 + radiusBigPokect);

 path.addArc(rect.left + 1.5 * w, rect.bottom + h / 4 - radiusBigPokect,
 rect.left + 1.5 * w + 2 * radiusBigPokect, rect.bottom + h / 4 + radiusBigPokect, 90, 90);
 path.lineTo(rect.left + 1.5 * w, rect.bottom - h / 4 - offset);
 c.drawPath(path, p);

 -- 下边一竖，分开裤子
 c.drawLine(b.left + bodyWidth / 2, b.bottom - h * 0.8, b.left + bodyWidth / 2, b.bottom, p);
 -- 左边的小口袋
 local radiusSamllPokect = w * 1.2;
 c.drawArc(b.left - radiusSamllPokect, b.bottom - radius - radiusSamllPokect,b.left + radiusSamllPokect, b.bottom - radius + radiusSamllPokect, 80, -60, false, p);
 -- 右边小口袋
 c.drawArc(b.right - radiusSamllPokect, b.bottom - radius - radiusSamllPokect,b.right + radiusSamllPokect, b.bottom - radius + radiusSamllPokect, 100, 60, false, p);

 --画脚
 p.setStrokeWidth(mStrokeWidth);
 p.setColor(colorStroke);
 p.setStyle(p.Style.FILL_AND_STROKE);

 local radiusFoot = radius / 3 * 0.4;
 local leftFootStartX = b.left + radius - offset * 2;
 local leftFootStartY = b.bottom - offset;
 local footWidthA = radius * 0.5;--脚宽度大-到半圆结束
 local footWidthB = footWidthA / 3;--脚宽度-比较细的部分

 -- 左脚
 path = Path();
 path.moveTo(leftFootStartX, leftFootStartY);
 path.lineTo(leftFootStartX, leftFootStartY + footHeigh);
 path.lineTo(leftFootStartX - footWidthA + radiusFoot, leftFootStartY + footHeigh);

 rectF = RectF();
 rectF.left = leftFootStartX - footWidthA;
 rectF.top = leftFootStartY + footHeigh - radiusFoot * 2;
 rectF.right = rectF.left + radiusFoot * 2;
 rectF.bottom = rectF.top + radiusFoot * 2;
 path.addArc(rectF, 90, 180);
 path.lineTo(rectF.left + radiusFoot + footWidthB, rectF.top);
 path.lineTo(rectF.left + radiusFoot + footWidthB, leftFootStartY);
 path.lineTo(leftFootStartX, leftFootStartY);
 c.drawPath(path, p);

 -- 右脚
 local rightFootStartX = b.left + radius + offset * 2;
 local rightFootStartY = leftFootStartY;
 path.reset();
 path.moveTo(rightFootStartX, rightFootStartY);
 path.lineTo(rightFootStartX, rightFootStartY + footHeigh);
 path.lineTo(rightFootStartX + footWidthA - radiusFoot, rightFootStartY + footHeigh);

 rectF.left = rightFootStartX + footWidthA - radiusFoot * 2;
 rectF.top = rightFootStartY + footHeigh - radiusFoot * 2;
 rectF.right = rectF.left + radiusFoot * 2;
 rectF.bottom = rectF.top + radiusFoot * 2;
 path.addArc(rectF, 90, -180);
 path.lineTo(rectF.right - radiusFoot - footWidthB, rectF.top);
 path.lineTo(rectF.right - radiusFoot - footWidthB, rightFootStartY);
 path.lineTo(rightFootStartX, rightFootStartY);
 c.drawPath(path, p);

 --画手
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.FILL);
 p.setColor(colorBody);

 -- 左手
 path = Path();
 local hypotenuse = b.bottom - radius - handsHeight;
 local radiusHand = hypotenuse / 6;
 p.setPathEffect(CornerPathEffect(radiusHand));

 path.moveTo(b.left, handsHeight);
 path.lineTo(b.left - hypotenuse / 2, handsHeight + hypotenuse / 2);
 path.lineTo(b.left, b.bottom - radius);
 c.drawPath(path, p);

 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.STROKE);
 p.setColor(colorStroke);
 c.drawPath(path, p);

 -- 右手
 path.reset();
 p.setStyle(p.Style.FILL);
 p.setColor(colorBody);

 path.moveTo(b.right, handsHeight);
 path.lineTo(b.right + hypotenuse / 2, handsHeight + hypotenuse / 2);
 path.lineTo(b.right, b.bottom - radius);
 c.drawPath(path, p);

 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.STROKE);
 p.setColor(colorStroke);
 c.drawPath(path, p);

 -- 一个慢动作 - -||| 拐点内侧
 path.reset();
 p.setStyle(p.Style.FILL);
 path.moveTo(b.left, handsHeight + hypotenuse / 2 - mStrokeWidth);
 path.lineTo(b.left - mStrokeWidth * 2, handsHeight + hypotenuse / 2 + mStrokeWidth * 2);
 path.lineTo(b.left, handsHeight + hypotenuse / 2 + mStrokeWidth);
 c.drawPath(path, p);
 path.reset();
 path.moveTo(b.right, handsHeight + hypotenuse / 2 - mStrokeWidth);
 path.lineTo(b.right + mStrokeWidth * 2, handsHeight + hypotenuse / 2 + mStrokeWidth * 2);
 path.lineTo(b.right, handsHeight + hypotenuse / 2 + mStrokeWidth);
 c.drawPath(path, p);
 --眼睛
 local eyesOffset = radius * 0.1;--眼睛中心处于上半圆直径 往上的高度偏移
 p.setStrokeWidth(mStrokeWidth * 5);
 -- 计算眼镜带弧行的半径 分两段，以便眼睛中间有隔开的效果
 local radiusGlassesRibbon = radius / Math.sin(Math.PI / 20);
 rect = RectF();
 rect.left = b.left + radius - radiusGlassesRibbon;
 rect.top = b.top + radius - (radius / Math.tan(Math.PI / 20)) - radiusGlassesRibbon - eyesOffset;
 rect.right = rect.left + radiusGlassesRibbon * 2;
 rect.bottom = rect.top + radiusGlassesRibbon * 2;
 c.drawArc(rect, 81, 3, false, p);
 c.drawArc(rect, 99, -3, false, p);
 --眼睛半径
 local radiusEyes = radius / 3;
 p.setColor(Color.WHITE);
 p.setStrokeWidth(mStrokeWidth);
 p.setStyle(p.Style.FILL);
 c.drawCircle(b.left + bodyWidth / 2 - radiusEyes - offset, b.top + radius - eyesOffset, radiusEyes, p);
 c.drawCircle(b.left + bodyWidth / 2 + radiusEyes + offset, b.top + radius - eyesOffset, radiusEyes, p);
 p.setColor(colorStroke);
 p.setStyle(p.Style.STROKE);
 c.drawCircle(b.left + bodyWidth / 2 - radiusEyes - offset, b.top + radius - eyesOffset, radiusEyes, p);
 c.drawCircle(b.left + bodyWidth / 2 + radiusEyes + offset, b.top + radius - eyesOffset, radiusEyes, p);

 local radiusEyeballBlack = radiusEyes / 3;
 p.setStyle(p.Style.FILL);
 c.drawCircle(b.left + bodyWidth / 2 - radiusEyes - offset, b.top + radius - eyesOffset, radiusEyeballBlack, p);
 c.drawCircle(b.left + bodyWidth / 2 + radiusEyes + offset, b.top + radius - eyesOffset, radiusEyeballBlack, p);

 p.setColor(Color.WHITE);
 local radiusEyeballWhite = radiusEyeballBlack / 2;
 c.drawCircle(b.left + bodyWidth / 2 - radiusEyes + radiusEyeballWhite - offset * 2,b.top + radius - radiusEyeballWhite + offset - eyesOffset,radiusEyeballWhite, p);
 c.drawCircle(b.left + bodyWidth / 2 + radiusEyes + radiusEyeballWhite,b.top + radius - radiusEyeballWhite + offset - eyesOffset,radiusEyeballWhite, p);

 --画嘴巴，因为位置和眼睛有相对关系，所以写在一块
 p.setColor(colorStroke);
 p.setStyle(p.Style.STROKE);
 p.setStrokeWidth(mStrokeWidth);
 local radiusMonth = radius;
 rect.left = b.left;
 rect.top = b.top - radiusMonth / 2.5;
 rect.right = rect.left + radiusMonth * 2;
 rect.bottom = rect.top + radiusMonth * 2;
 c.drawArc(rect, 95, -20, false, p);

 --脚下影子
 p.setColor(activity.getResources().getColor(android.R.color.darker_gray));
 c.drawOval(b.left + bodyWidth * 0.15, b.bottom - offset + footHeigh,b.right - bodyWidth * 0.15, b.bottom - offset + footHeigh + mStrokeWidth * 1.3, p);
end)
tt.background=bg

if 文件是否存在(启动图片)==true then 启动时间=读取文件(启动图片) else 启动时间="0" end
task (启动时间*1000,function() 退出页面() end)
