android绘制实心。空心五角星
来源:互联网 发布:淘宝怎么清空购物车 编辑:程序博客网 时间:2024/05/16 00:43
package com.example.test;import android.annotation.SuppressLint;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Paint.Style;import android.graphics.Path;import android.util.AttributeSet;import android.view.View;/** * * 假设五角星外接圆半径为1,有一个角朝上,以五角星中心为原点:外点 x=Rcos(72°*k) y=Rsin(72°*k) k=0,1,2,3,4 内点 r=Rsin(18)/sin(180-36-18) x=rcos(72°*k+36°) y=rsin(72°*k+36°) k=0,1,2,3,4 * @author Young * */public class FiveView2 extends View {public FiveView2(Context context) {super(context);// TODO Auto-generated constructor stub}public FiveView2(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}public FiveView2(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);// TODO Auto-generated constructor stub}@SuppressLint("NewApi")public FiveView2(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr, defStyleRes);// TODO Auto-generated constructor stub} @Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);int width=getWidth();int r=width/2;float outR=getWidth()/2 /5;float inR=outR*sin(18)/sin(180-36-18);Paint paint=new Paint();paint.setAntiAlias(true);paint.setColor(Color.YELLOW);paint.setStrokeWidth(5);canvas.translate(r/5, r );canvas.rotate(-18);Path path = getCompletePath(outR, inR);paint.setStyle(Style.STROKE);canvas.drawPath(path, paint);path = getHalfPath(outR, inR);paint.setStyle(Style.FILL);canvas.drawPath(path, paint);canvas.rotate(18);canvas.translate(r/5*2+15,0 );canvas.rotate(-18);path = getCompletePath(outR, inR);paint.setStyle(Style.STROKE);canvas.drawPath(path, paint);paint.setStyle(Style.FILL);canvas.drawPath(path, paint); canvas.rotate(18);canvas.translate(r/5*2+15,0 );canvas.rotate(-18);path = getCompletePath(outR, inR);paint.setStyle(Style.STROKE);canvas.drawPath(path, paint);canvas.rotate(18);canvas.translate(r/5*2+15,0 );canvas.rotate(-18);path = getHalfPath(outR, inR);paint.setStyle(Style.STROKE);canvas.drawPath(path, paint);canvas.rotate(18);canvas.translate(r/5*2+15,0 );canvas.rotate(-18);path = getHalfPath(outR, inR);paint.setStyle(Style.STROKE);canvas.drawPath(path, paint);paint.setStyle(Style.FILL);canvas.drawPath(path, paint);}private Path getHalfPath(float outR, float inR) {Path path;path=new Path();path.moveTo(outR*cos(72*4), outR*sin(72*4));path.lineTo(inR*cos(72*1+36), inR*sin(72*1+36));path.lineTo(outR*cos(72*2), outR*sin(72*2));path.lineTo(inR*cos(72*2+36), inR*sin(72*2+36));path.lineTo(outR*cos(72*3), outR*sin(72*3));path.lineTo(inR*cos(72*3+36), inR*sin(72*3+36));path.close();return path;}private Path getCompletePath(float outR, float inR) {Path path=new Path();path.moveTo(outR*cos(72*0), outR*sin(72*0));path.moveTo(outR*cos(72*0), outR*sin(72*0));path.lineTo(inR*cos(72*0+36), inR*sin(72*0+36));path.lineTo(outR*cos(72*1), outR*sin(72*1));path.lineTo(inR*cos(72*1+36), inR*sin(72*1+36));path.lineTo(outR*cos(72*2), outR*sin(72*2));path.lineTo(inR*cos(72*2+36), inR*sin(72*2+36));path.lineTo(outR*cos(72*3), outR*sin(72*3));path.lineTo(inR*cos(72*3+36), inR*sin(72*3+36));path.lineTo(outR*cos(72*4), outR*sin(72*4));path.lineTo(inR*cos(72*4+36), inR*sin(72*4+36));path.close();return path;} float cos(int num){return (float) Math.cos(num*Math.PI/180);} float sin(int num){return (float) Math.sin(num*Math.PI/180);}}
1 0
- android绘制实心。空心五角星
- android绘制实心圆、空心圆
- js绘制菱形(空心和实心)
- Android canvas 绘制实心圆
- 打印三角形(空心,实心)
- Android xml shape=oval 实心圆不是空心圆
- Android绘制空心矩形示例
- 实心字转空心字
- 打印空心和实心菱形
- java代码--实心,空心图形
- 空心圆和实心圆
- 空心菱形与实心菱形
- java输出空心/实心菱形
- Android中用Shape绘制空心图形
- android 画实心矩形框和空心矩形框的设置
- android利用shap画小圆圈(空心圆、实心圆)
- 绘制实心圆
- opengl 绘制实心圆柱体
- HDU3068 最长回文(Manacher算法)
- C语言变参函数
- Java系列笔记(4) - JVM监控与调优 和相关博客
- shell笔记(4):正则表达式
- solrconfig.xml 应用解析调优
- android绘制实心。空心五角星
- iOS 页面之间的传值总结
- hihoCoder 1261 String Problem II
- HDU 1619:Unidirectional TSP【dfs & 回忆路径】
- HandlerThread类应用
- 手机助手(一)
- 用python从excel表格中读取数据生成可以放在科技论文中的图片
- 缩写含义
- ios之核心动画(二)