1.本控件绘图部分使用我的LogicCanvas绘图库:基础使用在此, 2.喜欢的话可以到github上看看,顺便给个star 3.发现向量还怪好用的,它不会出现在屏幕上,但却能支撑图形的形状 4.也许这是绘图篇的最后一篇了,还要总结其他方面的知识点,以后有机会一定再深入探究一下。 5.时间指针是通过角度确定的,所以让它们转起来很简单,就不演示了
效果图
device-2018-09-07-103155.png
protected Pos pos = new Pos(0, 0);//点
protected ShapeLine sl = new ShapeLine();//线
protected ShapeText st = new ShapeText();//文字
protected ShapeArc sa = new ShapeArc();//圆弧
private Pos coo = v2(500, 800);//坐标系原点
private int mDotWith = 3;
private int mDotColor = 3;
Painter painter = PainterEnum.INSTANCE.getInstance(canvas);
//绘制网格
//CanvasUtils.drawGrid(getContext(), 50, canvas);
//绘制坐标系
//CanvasUtils.drawCoord(getContext(), coo, 50, canvas);
//绘制60个小线
for (int i = 0; i < 60; i++) {
ShapeLine a = null;
if (i % 5 == 0) {
a = (ShapeLine) sl.deepClone().ang(i * 6f).c(260f).parse().coo(coo);
mDotWith = 5;
mDotColor = ColUtils.randomRGB();
} else {
a = (ShapeLine) sl.deepClone().ang(i * 6f).c(280f).parse().coo(coo);
mDotWith = 3;
mDotColor = Color.BLUE;
}
ShapeLine b = a.deepClone().c(300f).v(null).parse();
Shape c = sl.deepClone().ps(a.mv, b.mv).coo(coo).b(mDotWith).ss(mDotColor);
//绘制小圆点
painter.draw(c);
if (i % 5 == 0) {
painter.draw(sa.deepClone().r(4).ang(360).fs(Color.BLACK).p(a.mv).coo(coo));
}
//绘制四个圆弧
for (int i = 0; i < 4; i++) {
Shape circle = sa.deepClone().r(350).ang(70).coo(this.coo).b(3).ss(Color.parseColor("#D4DA")).rot(10 + 90 * i).b(6);
painter.draw(circle);
}
//绘制文字
painter.drawText(st.deepClone().size(70).str("Ⅲ").p(coo.add(350, 30)));
painter.drawText(st.deepClone().size(70).str("Ⅵ").p(coo.add(0, 350 + 30)));
painter.drawText(st.deepClone().size(70).str("Ⅸ").p(coo.add(-350, 30)));
painter.drawText(st.deepClone().size(70).str("Ⅻ").p(coo.add(0, -350 + 30)));
painter.drawText(st.deepClone().size(35).str("Toly").p(coo.add(0, -180)));
//绘制小圆
Shape center1 = sa.deepClone().ang(270f).r(25).coo(this.coo).b(5).ss(Color.parseColor("#6B6B6B);
Shape center2 = sa.deepClone().ang(360).r(15).coo(this.coo).b(5).fs(Color.GRAY);
Shape center3 = sa.deepClone().ang(360).r(5).coo(this.coo).fs(Color.BLACK);
//绘制指针
Shape secLine = sl.deepClone().ang(-90f).c(330f).coo(this.coo).b(2).ss(Color.parseColor("#6B6B6B"));
Shape hourLine = sl.deepClone().ang(45f).c(150f).coo(this.coo).b(8).ss(Color.parseColor("#8FC552"));
Shape minLine = sl.deepClone().ang(145f).c(250f).coo(this.coo).b(8).ss(Color.parseColor("#87B953"));
painter.draw(center1, secLine, hourLine, minLine, center2, center3);
OK,就这么简单。
1本文由张风捷特烈原创,转载请注明
2欢迎广大编程爱好者共同交流
3个人能力有限,如有不正之处欢迎大家批评指证,必定虚心改正
4你的喜欢与支持将是我最大的动力