-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathCatCircle.cpp
More file actions
95 lines (83 loc) · 2.86 KB
/
Copy pathCatCircle.cpp
File metadata and controls
95 lines (83 loc) · 2.86 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
#include <CatCircle.h>
#include <math.h>
CatCircle::CatCircle(int left, int bottom, int width, int height) : od::Graphic(left, bottom, width, height)
{
}
CatCircle::~CatCircle()
{
if (mpSequencer)
{
mpSequencer->release();
}
}
void CatCircle::draw(od::FrameBuffer &fb)
{
const int CURSOR = 3;
const int MARGIN = 2;
// The coordinate system.
// (mWorldLeft, mWorldBottom) are the screen coordinates of the (left, bottom) of this graphic.
// (mWidth, mHeight) are the width and height in pixels of this graphic.
// All FrameBuffer methods assume screen coordinates.
// Calculate the radius of a circle that will fit within this graphic's area including a margin and space for the cursor.
int radius = MIN(mWidth / 2, mHeight / 2) - MARGIN - CURSOR;
// Calculate the screen coordinates of the center of this graphic.
int centerX = mWorldLeft + mWidth / 2;
int centerY = mWorldBottom + mHeight / 2;
// Draw the outer circular.
// Colors available are: BLACK, GRAY1, ..., GRAY14, WHITE
fb.circle(GRAY5, centerX, centerY, radius);
// Do we have a sequencer object to render?
if (mpSequencer)
{
float theta, x, y;
// The number of steps (i.e. boxes in catspeak).
int n = mpSequencer->mCachedBoxes;
if(n < 1)
{
// There are no steps to render.
return;
}
// Render each step in gray as a spoke with a circle at the end.
for (int i=0;i<n;i++)
{
// Divide the circle into n wedges, 1 for each step.
theta = i * M_PI * 2 / n;
// Calculate the screen coordinates of the point on the circle that is theta radians along.
x = sinf(theta);
y = cosf(theta);
x = centerX + radius * x;
y = centerY + radius * y;
// Draw a gray line from the center of the circle to this point.
fb.line(GRAY7, centerX, centerY, x, y);
if(mpSequencer->mSpace[i] > 0.0f)
{
// Draw a filled circle to indicate this step has a cat in it.
fb.fillCircle(GRAY7, x, y, CURSOR);
}
}
// Render the current position in white.
int phase = mpSequencer->mPhase; // Phase is synonym for current position.
// Calculate the screen coordinates of the point on the circle that is theta radians along.
theta = phase * M_PI * 2 / n;
x = sinf(theta);
y = cosf(theta);
x = centerX + x * radius;
y = centerY + y * radius;
// Draw a white line from the center of the circle to this point.
fb.line(mForeground, centerX, centerY, x, y);
// Draw a white filled circle to indicate this step promimently.
fb.fillCircle(mForeground, x, y, CURSOR);
}
}
void CatCircle::follow(EuclideanSequencer *pSequencer)
{
if (mpSequencer)
{
mpSequencer->release();
}
mpSequencer = pSequencer;
if (mpSequencer)
{
mpSequencer->attach();
}
}