PowerCollectAnim.java
5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.lotus.town.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import java.util.Random;
public class PowerCollectAnim extends View{
public static class AnimaListener{
public void finish(){
}
}
private AnimaListener listener;
private Paint paint;
private Paint paintYellow;
private Paint paintGreen;
private float centerX = 0;
private float centerY = 0;
public void initPosition(float x,float y){
centerX = x;
centerY = y;
}
public PowerCollectAnim(Context context, AttributeSet attributes) {
super(context,attributes);
paint = new Paint();
paint.setAntiAlias(true);
paintYellow = new Paint();
paintYellow.setColor(getResources().getColor(android.R.color.holo_blue_light));
paintYellow.setAntiAlias(true);
paintGreen = new Paint();
paintGreen.setColor(getResources().getColor(android.R.color.holo_green_dark));
paintGreen.setAntiAlias(true);
}
public PowerCollectAnim(Context context) {
super(context);
paint = new Paint();
paint.setAntiAlias(true);
}
public void setListener(AnimaListener listener){
this.listener = listener;
}
public void reset(){
}
private int getRandom(){
return 100+new Random().nextInt(50);
}
float point1x = 0;
float point1y = 0;
float point2x = 0;
float point2y = 0;
float point3x = 0;
float point3y = 0;
float point4x = 0;
float point4y = 0;
float point5x = 0;
float point5y = 0;
float point6x = 0;
float point6y = 0;
double speed1 = 5;
double speed2 = 4;
double speed3 = 6;
private double getSpeed(){
int i = new Random().nextInt(3);
if(i == 0){
return speed1;
} else if(i==1){
return speed2;
} else if(i == 2){
return speed3;
}
return speed3;
}
@Override
public void draw(Canvas canvas) {
if(centerX == 0 && centerY ==0){
super.draw(canvas);
return;
}
if(point1x == 0) {
point1x = centerX + getRandom();
}
if(point1y == 0) {
point1y = centerY + getRandom();
}
if(point2x == 0) {
point2x = centerX - getRandom();
}
if(point2y == 0) {
point2y = centerY - getRandom();
}
if(point3x == 0) {
point3x = centerX + getRandom();
}
if(point3y == 0) {
point3y = centerY + getRandom();
}
if(point4x == 0) {
point4x = centerX + getRandom();
}
if(point4y == 0) {
point4y = centerY - getRandom();
}
if(point5x == 0) {
point5x = centerX - getRandom();
}
if(point5y == 0) {
point5y = centerY + getRandom();
}
if (point1x < centerX || point1y < centerY) {
int randomX = getRandom();
int randomY = getRandom();
point1x = centerX + randomX;
point1y = centerY + randomY;
}
point1x = (float) (point1x - getSpeed());
point1y = (float) (point1y - getSpeed());
if (point2x > centerX || point2y > centerY) {
int randomX = getRandom();
int randomY = getRandom();
point2x = centerX - randomX;
point2y = centerY - randomY;
}
point2x = (float) (point2x + getSpeed());
point2y = (float) (point2y + getSpeed());
if (point3y < centerY || point3x <centerX) {
int randomX = getRandom();
int randomY = getRandom();
point3y = centerY + randomY;
point3x = centerX + randomX;
}
point3y = (float) (point3y - getSpeed());
point3x = (float) (point3x - getSpeed());
if (point4x <= centerX || point4y >= centerY) {
int randomX = getRandom();
int randomY = getRandom();
point4x = centerX + randomX;
point4y = centerY - randomY;
}
point4x = (float) (point4x - getSpeed());
point4y = (float) (point4y + getSpeed());
if (point5x >= centerX || point5y <= centerY) {
int randomX = getRandom();
int randomY = getRandom();
point5x = centerX - randomX;
point5y = centerY + randomY;
}
point5x = (float) (point5x + getSpeed());
point5y = (float) (point5y - getSpeed());
// point4x = (float) (centerX + 100 - distance);
// point4y = (float) (centerY + 100 - distance);
//
// point5x = centerX + 100 - distance;
// point5y = centerY + 100 - distance;
//
// point6x = centerX + 100 - distance;
// point6y = centerY + 100 - distance;
//线宽
canvas.drawCircle(point1x, point1y, 6, paintGreen);
canvas.drawCircle(point2x, point2y, 5, paintYellow);
canvas.drawCircle(point4x, point4y, 5, paintGreen);
canvas.drawCircle(point5x, point5y, 6, paintYellow);
canvas.drawCircle(point3x, point5y, 7, paintGreen);
super.draw(canvas);
}
}