Skip to content

Instantly share code, notes, and snippets.

@jdryg
Created February 24, 2018 16:55
Show Gist options
  • Save jdryg/a0b6f6941daa050f2a25ae4bd51bca8b to your computer and use it in GitHub Desktop.
Save jdryg/a0b6f6941daa050f2a25ae4bd51bca8b to your computer and use it in GitHub Desktop.
Color circle
static float colorCirclePos[512];
static vg::Color colorCircleColor[256];
static uint16_t colorCircleIndices[765];
static bool colorCircleReady = false;
if (!colorCircleReady) {
// Center of the circle
colorCirclePos[0] = 0.0f;
colorCirclePos[1] = 0.0f;
colorCircleColor[0] = vg::ColorRGBA::White;
// the rest of the circle
float* pos = &colorCirclePos[2];
vg::Color* col = &colorCircleColor[1];
for (uint32_t i = 0; i < 255; ++i) {
const float ang = (i / 255.0f) * bx::kPi2;
pos[0] = 100.0f * bx::cos(ang);
pos[1] = 100.0f * bx::sin(ang);
col[0] = vg::ColorRGBA::fromHSB(i / 255.0f, 1.0f, 1.0f);
pos += 2;
col++;
}
uint16_t* id = colorCircleIndices;
for (uint32_t i = 1; i < 255; ++i) {
id[0] = 0;
id[1] = i;
id[2] = i + 1;
id += 3;
}
id[0] = 0;
id[1] = 254;
id[2] = 1;
colorCircleReady = true;
}
// vg::Context* vgr = ...;
vg::indexedTriList(vgr, colorCirclePos, nullptr, 256, colorCircleColor, 256, colorCircleIndices, 765, VG_INVALID_HANDLE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment