Skip to content

Instantly share code, notes, and snippets.

@mazbox
Last active January 18, 2024 11:25
Show Gist options
  • Save mazbox/39390050ec56be8a33df81f3e0366b99 to your computer and use it in GitHub Desktop.
Save mazbox/39390050ec56be8a33df81f3e0366b99 to your computer and use it in GitHub Desktop.
//
// Created by Marek Bereza on 18/01/2024.
//
#pragma once
#include "Layer.h"
class Halo : public Layer {
public:
Halo(Graphics &g) : Layer(g) {}
VboRef vbo;
void draw() override {
ScopedAlphaBlend blend(g, true);
// pulse overall alpha
g.setColor(1.f, 1.f, 1.f, sin(g.currFrameTime * 4.f) * 0.5 + 0.5);
vbo->draw(g, Vbo::PrimitiveType::TriangleFan);
}
void doLayout() override {
// circle centre
vec2 c = centre();
// circle radius
float r = std::min(width, height) / 2.f;
vec3 col = {1.f, 1.f, 0.7f};
////////////////////////////////////
vbo = Vbo::create();
std::vector<vec2> verts;
std::vector<vec4> colors;
// centre of circle
verts.push_back(c);
// some kind of orange
colors.emplace_back(col, 1.f);
int numSteps = 64;
for (int i = 0; i <= numSteps; i++) {
double angle = (i / (double) numSteps) * M_PI * 2.0;
verts.emplace_back(c.x + std::cos(angle) * r, c.y + std::sin(angle) * r);
colors.emplace_back(col, 0.f);
}
vbo->setVertices(verts);
vbo->setColors(colors);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment