package com.example.m_evolution.View;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View; import com.example.m_evolution.MyApp; import static com.example.m_evolution.MyApp.COORDINATE_LENGTH;
import static com.example.m_evolution.MyApp.COORDINATE_ORIGIN_X;
import static com.example.m_evolution.MyApp.COORDINATE_ORIGIN_Y;
import static com.example.m_evolution.MyApp.STR_MOOD; public class CoordinateView extends View {
private Paint mPaint; public CoordinateView(Context context) {
this(context, null);
} public CoordinateView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
} public CoordinateView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mPaint = new Paint();
mPaint.setColor(Color.BLACK);
mPaint.setAntiAlias(true);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(4);
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint_coordinate = new Paint();
paint_coordinate.setColor(Color.rgb(207,207,207));
paint_coordinate.setAntiAlias(true);
paint_coordinate.setStrokeCap(Paint.Cap.ROUND);
paint_coordinate.setStrokeWidth(8);
// 画出坐标轴
int widthScreen = MyApp.getScreenWidth(getContext());
int leftX = (int)((COORDINATE_ORIGIN_X-COORDINATE_LENGTH/2)*widthScreen); //x轴左边坐标
int rightX = (int)((COORDINATE_ORIGIN_X+COORDINATE_LENGTH/2)*widthScreen); //x轴右边坐标
int topY = (int)((COORDINATE_ORIGIN_Y-COORDINATE_LENGTH/2)*widthScreen); //y轴上边坐标
int bottomY = (int)((COORDINATE_ORIGIN_Y+COORDINATE_LENGTH/2)*widthScreen); //y轴下边坐标
int centerX = (leftX+rightX)/2; //原点的x坐标
int centerY = (topY+bottomY)/2; //原点的y坐标
int radiusCoordinate = (rightX-leftX)/2; //轴的长度
canvas.drawLine(leftX,centerY,rightX,centerY,paint_coordinate); //画出x轴
canvas.drawLine(centerX,topY,centerX, bottomY, paint_coordinate); //画出x轴 //画圆
Paint paint_circle = new Paint();
paint_circle.setColor(Color.rgb(207,207,207));
paint_circle.setAntiAlias(true);
paint_circle.setStyle(Paint.Style.STROKE); //设置为描边,即只画边缘,不然的话就画出实心的圆
paint_circle.setStrokeCap(Paint.Cap.ROUND);
paint_circle.setStrokeWidth(4);
canvas.drawCircle(centerX,centerY,((float)Math.sqrt((double)2)/3)*radiusCoordinate,paint_circle);
canvas.drawCircle(centerX,centerY,((float)Math.sqrt((double)8)/3)*radiusCoordinate,paint_circle); //画圆弧
// Paint paint_circle = new Paint();
// paint_circle.setColor(Color.rgb(207,207,207));
// paint_circle.setAntiAlias(true);
// paint_circle.setStyle(Paint.Style.STROKE); //设置为描边,即只画边缘,不然的话就画出实心的圆
// paint_circle.setStrokeCap(Paint.Cap.ROUND);
// paint_circle.setStrokeWidth(4);
// RectF oval = new RectF(centerX-((float)Math.sqrt((double)2)/3)*radiusCoordinate, centerY-((float)Math.sqrt((double)2)/3)*radiusCoordinate, centerX+((float)Math.sqrt((double)2)/3)*radiusCoordinate, centerY+((float)Math.sqrt((double)2)/3)*radiusCoordinate);
//第四个boolean参数表示要不要连接原点,具体效果与paint_circle.setStyle(Paint.Style.STROKE)相关联。
//第二个参数是从哪个角度开始画,第三个参数是顺时针扫多少角度
// canvas.drawArc(oval,0,360,false,paint_circle); //画出八个关键点
Paint paint_mood_point = new Paint();
paint_mood_point.setAntiAlias(true);
paint_mood_point.setStrokeCap(Paint.Cap.ROUND);
paint_mood_point.setStrokeWidth(10);
paint_mood_point.setColor(Color.BLUE);
//八个心情点的位置
float[][] arr_mood_point = new float[][]{{2f/3f,2f/3f}, {1f/3f, 1f/3f}, {1f/3f, -1f/3f}, {2f/3f, -2f/3f}, {-2f/3f, -2f/3f}, {-1f/3f, -1f/3f}, {-1f/3f, 1f/3f},{-2f/3f, 2f/3f}};
for(int i = 0;i<8; i++){
canvas.drawPoint((float)centerX+arr_mood_point[i][0]*(float)radiusCoordinate,(float)centerY-arr_mood_point[i][1]*(float)radiusCoordinate,paint_mood_point);
} //画出四个轴点
Paint paint_xy_point = new Paint();
paint_xy_point.setAntiAlias(true);
paint_xy_point.setStrokeCap(Paint.Cap.ROUND);
paint_xy_point.setStrokeWidth(20);
paint_xy_point.setColor(Color.rgb(207,207,207));
//四个轴点位置
float[][] arr_xy_point = new float[][]{{1,0}, {-1, 0}, {0, 1}, {0, -1}};
for(int i = 0;i<4; i++){
canvas.drawPoint((float)centerX+arr_xy_point[i][0]*(float)radiusCoordinate,(float)centerY-arr_xy_point[i][1]*(float)radiusCoordinate,paint_xy_point);
} //写出相应的字
Paint paint_text = new Paint();
// paint_text.setAntiAlias(true);
// paint_text.setStrokeCap(Paint.Cap.ROUND);
// paint_text.setStrokeWidth(10);
paint_text.setTextSize(30f);
paint_text.setColor(Color.BLACK);
paint_text.setTextAlign(Paint.Align.CENTER);
//八个心情的文字
for(int i = 0;i<8; i++){
canvas.drawText(STR_MOOD[i],(float)centerX+arr_mood_point[i][0]*(float)radiusCoordinate,(float)centerY-arr_mood_point[i][1]*(float)radiusCoordinate,paint_text);
}
//四个坐标下标的文字
String str_xy[] = {"正能量", "负能量", "高压", "低压"};
//横纵坐标的下标位置
float[][] arr_point2 = new float[][]{{1f+0.13f,0f}, {-1f-0.13f, 0f}, {0f, 1f+0.05f}, {0f, -1f-0.1f}};
for(int i = 0;i<4; i++){
canvas.drawText(str_xy[i],(float)centerX+arr_point2[i][0]*(float)radiusCoordinate,(float)centerY-arr_point2[i][1]*(float)radiusCoordinate,paint_text);
}
}
}

画布Canvas 画笔Paint的更多相关文章

  1. 【Android】自己定义View、画家(画布)Canvas与画笔Paint的应用——绘图、涂鸦板app的实现

    利用一个简单的绘图app来说明安卓的图形处理类与自己定义View的应用. 例如以下图,有一个供用户自己随意绘图.涂鸦的app. 这里不做那么花俏了,仅提供黑白两色.但能够改变笔尖的粗细. 实质上这里的 ...

  2. java 图形化小工具Abstract Window Toolit :画笔Graphics,画布Canvas(),弹球小游戏

    画笔Graphics Java中提供了Graphics类,他是一个抽象的画笔,可以在Canvas组件(画布)上绘制丰富多彩的几何图和位图. Graphics常用的画图方法如下: drawLine(): ...

  3. android Canvas 和 Paint用法

    自定义view里面的onDraw方法,在这里我们可以绘制各种图形,onDraw里面有两个API我们需要了解清楚他们的用法:Canvas 和 Paint. Canvas翻译成中文就是画布的意思,Canv ...

  4. 自定义View(4)Canvas和Paint常用绘制函数

    画布Canvas 在Android下进行2D绘图需要Canvas类的支持,它位于"android.graphics.Canvas"包下,直译过来为画布的意思,用于完成在View上的 ...

  5. 安卓自定义控件(一)Canvas、Paint、Shader、Xfermode

    关于自定义控件,之前就写过一篇自定义控件,上图下字的Button,图片任意指定大小,但是使用效果还是让人感觉不幸福,这次索性彻彻底底地对自定义控件做一次彻彻底底的总结. 我会花4篇博客来介绍自定义控件 ...

  6. Android查缺补漏(View篇)--自定义View利器Canvas和Paint详解

    上篇文章介绍了自定义View的创建流程,从宏观上给出了一个自定义View的创建步骤,本篇是上一篇文章的延续,介绍了自定义View中两个必不可少的工具Canvas和Paint,从细节上更进一步的讲解自定 ...

  7. Android为TV端助力 Canvas 和 Paint用法

    自定义view里面的onDraw方法,在这里我们可以绘制各种图形,onDraw里面有两个API我们需要了解清楚他们的用法:Canvas 和 Paint. Canvas翻译成中文就是画布的意思,Canv ...

  8. 【Android】21.2 2D图形图像处理(Canvas和Paint)

    分类:C#.Android.VS2015: 创建日期:2016-03-19 一.Canvas对象简介 画布(Canvas对象)是与System.Drawing或iOS核心图形等传统框架非常类似的另一种 ...

  9. Android Canvas和Paint基本使用

    这篇文章主要介绍下画笔Paint和画布Canvas的基本使用  1.Paint 创建对象Paint mPaint = new Paint(); 常用的基本方法有 :                mP ...

随机推荐

  1. 在linux中安装protobuf编译器和运行时环境

    为了使用源码编译protobuf,需要下面的工具: autoconf, automake, libtool, make, g++, unzip 如果你使用ubuntu/debian,你可以使用如下方式 ...

  2. Scrapy实战篇(六)之爬取360图片数据和图片

    本篇文章我们以360图片为例,介绍scrapy框架的使用以及图片数据的下载. 目标网站:http://images.so.com/z?ch=photography 思路:分析目标网站为ajax加载方式 ...

  3. 图解Tomcat

  4. note 9 列表、时间复杂度、排序

    列表 List +内建(built-in)数据结构(data structure),用来存储一系列元素(items) 如:lst = [5.4,'hello',2] 前向索引.后向索引.切片.拼接.成 ...

  5. vs编写x64内联汇编

    参考自: https://www.cnblogs.com/achillis/p/5369658.html 先转过来, 等实践过了再做相应的修改, hehe 编写涉及系统特性的一些底层程序,特别是She ...

  6. SQLite3问题

    使用包含SQL语句的txt文件建立数据表 使用sqlite自带官方工具,.read <sql语法文件> 导入csv中数据到sqlite数据库表 使用sqlite自带官方工具,.import ...

  7. JavaScript数组方法--reduce、reduceRIght、reverse

    今天写的reduce是比较复杂的一个数组方法,其实在这之前我也用过reduce,可是每次用起来总感觉不那么顺手,主要还是因为不熟,对reduce本身不熟.首先reduce这个单词翻译为中文,不那么直观 ...

  8. Ubuntu忘记超级用户root密码,重新设置密码

    Ubuntu版本:Ubuntu 16.04.3 LTS 1启动系统,在启动过程中,反复按Esc键或者shift键(本人亲测反复按或者长按都可以,没必要纠结),直到出现以下界面: 通过上下键移动,选择U ...

  9. SAP Solution Manager 能够连接到 SAP Service Marketplace

    使用 在该步骤中,您要确保 SAP Solution Manager 能够连接到 SAP Service Marketplace. 作业 SAP Support Portal(SAPOSS)的 RFC ...

  10. dubbo rest服务 No provider available for the service 错误问题

    1.版本 dubbo 2.6.2 2.描述 消费者调用dubbo rest服务报No provider available for the service错误 网络上有讲是实体类未实现Serializ ...