Skip to content

Commit 35d90a7

Browse files
author
Felix Palmer
committed
Added color cycling to CircleRenderer
1 parent 8d84998 commit 35d90a7

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/com/pheelicks/visualizer/CircleRenderer.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.pheelicks.visualizer;
22

33
import android.graphics.Canvas;
4+
import android.graphics.Color;
45
import android.graphics.Paint;
56
import android.graphics.Rect;
67

78
public class CircleRenderer extends Renderer
89
{
910
private Paint mPaint;
11+
private boolean mCycleColor;
1012

1113
/**
1214
* Renders the audio data onto a pulsing circle
@@ -15,14 +17,35 @@ public class CircleRenderer extends Renderer
1517
*/
1618
public CircleRenderer(Canvas canvas,
1719
Paint paint)
20+
{
21+
this(canvas,
22+
paint,
23+
false);
24+
}
25+
26+
/**
27+
* Renders the audio data onto a pulsing circle
28+
* @param canvas
29+
* @param paint - Paint to draw lines with
30+
* @param cycleColor - If true the color will change on each frame
31+
*/
32+
public CircleRenderer(Canvas canvas,
33+
Paint paint,
34+
boolean cycleColor)
1835
{
1936
super(canvas);
2037
mPaint = paint;
38+
mCycleColor = cycleColor;
2139
}
2240

2341
@Override
2442
public void onRender(AudioData data, Rect rect)
2543
{
44+
if(mCycleColor)
45+
{
46+
cycleColor();
47+
}
48+
2649
for (int i = 0; i < data.bytes.length - 1; i++) {
2750
float[] cartPoint = {
2851
(float)i / (data.bytes.length - 1),
@@ -69,4 +92,14 @@ private float[] toPolar(float[] cartesian, Rect rect)
6992
};
7093
return out;
7194
}
95+
96+
private float colorCounter = 0;
97+
private void cycleColor()
98+
{
99+
int r = (int)Math.floor(128*(Math.sin(colorCounter) + 1));
100+
int g = (int)Math.floor(128*(Math.sin(colorCounter + 2) + 1));
101+
int b = (int)Math.floor(128*(Math.sin(colorCounter + 4) + 1));
102+
mPaint.setColor(Color.argb(128, r, g, b));
103+
colorCounter += 0.03;
104+
}
72105
}

src/com/pheelicks/visualizer/VisualizerView.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class VisualizerView extends View {
3232
private float[] mPoints;
3333
private Rect mRect = new Rect();
3434

35-
private Paint mCirclePaint = new Paint();
3635
private Paint mLinePaint = new Paint();
3736
private Paint mSpecialLinePaint = new Paint();
3837
private Paint mProgressLinePaint = new Paint();
@@ -59,10 +58,6 @@ public VisualizerView(Context context)
5958
private void init() {
6059
mBytes = null;
6160

62-
mCirclePaint.setStrokeWidth(3f);
63-
mCirclePaint.setAntiAlias(true);
64-
mCirclePaint.setColor(Color.argb(255, 222, 92, 143));
65-
6661
mLinePaint.setStrokeWidth(1f);
6762
mLinePaint.setAntiAlias(true);
6863
mLinePaint.setColor(Color.argb(88, 0, 128, 255));
@@ -113,7 +108,6 @@ private void rotateColours()
113108
int g = (int)Math.floor(128*(Math.sin(colorCounter + 2) + 1));
114109
int b = (int)Math.floor(128*(Math.sin(colorCounter + 4) + 1));
115110
mLinePaint.setColor(Color.argb(128, r, g, b));
116-
mCirclePaint.setColor(Color.argb(255, g, b, r));
117111
colorCounter += 0.03;
118112
}
119113

@@ -160,7 +154,12 @@ protected void onDraw(Canvas canvas) {
160154
paint2.setColor(Color.argb(200, 11, 111, 233));
161155
mBarGraphRendererTop = new BarGraphRenderer(mCanvas, 4, paint2, true);
162156

163-
mCircleRenderer = new CircleRenderer(mCanvas, paint2);
157+
Paint paint3 = new Paint();
158+
paint3.setStrokeWidth(3f);
159+
paint3.setAntiAlias(true);
160+
paint3.setColor(Color.argb(255, 222, 92, 143));
161+
162+
mCircleRenderer = new CircleRenderer(mCanvas, paint3, true);
164163
}
165164

166165
// Draw normal line - offset by amplitude

0 commit comments

Comments
 (0)