Created
December 3, 2014 09:55
-
-
Save cuber5566/7ecfa51846b258a389b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.Path; | |
import android.graphics.Rect; | |
import android.util.AttributeSet; | |
import android.view.View; | |
public class FiveView extends View { | |
private double degree = Math.PI / 180; | |
private int ballSize = 5; | |
public FiveView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
// TODO Auto-generated constructor stub | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
Paint p_dark = new Paint(Paint.ANTI_ALIAS_FLAG) { | |
{ | |
this.setStyle(Paint.Style.FILL_AND_STROKE); | |
this.setARGB(255, 200, 200, 200); | |
this.setStrokeWidth(5); | |
} | |
}; | |
Rect rect = canvas.getClipBounds(); | |
int centerX = rect.centerX(); | |
int centerY = rect.centerY(); | |
int r = rect.width() / 2 - 20; | |
Path path = new Path(); | |
// path.moveTo(0, 0); | |
// path.lineTo((float)(r*Math.cos(45*Math.PI/180)), | |
// (float)(r*Math.sin(45*Math.PI/180))); | |
path.moveTo(centerX + (float) (r * Math.cos(18 * degree)), | |
centerY - (float) (r * Math.sin(18 * degree))); | |
canvas.drawCircle(centerX + (float) (r * Math.cos(18 * degree)), | |
centerY - (float) (r * Math.sin(18 * degree)), ballSize, p_dark); | |
path.lineTo(centerX + (float) (r * Math.cos(90 * degree)), | |
centerY - (float) (r * Math.sin(90 * degree))); | |
path.moveTo(centerX + (float) (r * Math.cos(90 * degree)), | |
centerY - (float) (r * Math.sin(90 * degree))); | |
canvas.drawCircle(centerX + (float) (r * Math.cos(90 * degree)), | |
centerY - (float) (r * Math.sin(90 * degree)), ballSize, p_dark); | |
path.lineTo(centerX + (float) (r * Math.cos(162 * degree)), | |
centerY - (float) (r * Math.sin(162 * degree))); | |
path.moveTo(centerX + (float) (r * Math.cos(162 * degree)), | |
centerY - (float) (r * Math.sin(162 * degree))); | |
canvas.drawCircle( | |
centerX + (float) (r * Math.cos(162 * degree)), centerY | |
- (float) (r * Math.sin(162 * degree)), ballSize, | |
p_dark); | |
path.lineTo(centerX + (float) (r * Math.cos(234 * degree)), | |
centerY - (float) (r * Math.sin(234 * degree))); | |
path.moveTo(centerX + (float) (r * Math.cos(234 * degree)), | |
centerY - (float) (r * Math.sin(234 * degree))); | |
canvas.drawCircle( | |
centerX + (float) (r * Math.cos(234 * degree)), centerY | |
- (float) (r * Math.sin(234 * degree)), ballSize, | |
p_dark); | |
path.lineTo(centerX + (float) (r * Math.cos(306 * degree)), | |
centerY - (float) (r * Math.sin(306 * degree))); | |
path.moveTo(centerX + (float) (r * Math.cos(306 * degree)), | |
centerY - (float) (r * Math.sin(306 * degree))); | |
canvas.drawCircle( | |
centerX + (float) (r * Math.cos(306 * degree)), centerY | |
- (float) (r * Math.sin(306 * degree)), ballSize, | |
p_dark); | |
path.lineTo(centerX + (float) (r * Math.cos(18 * degree)), | |
centerY - (float) (r * Math.sin(18 * degree))); | |
path.close(); | |
canvas.drawPath(path, p_dark); | |
super.onDraw(canvas); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment