-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImDrawList coding party - deadline Nov 30, 2020! #3606
Comments
Here are some examples I made to get you started: Circles #define V2 ImVec2
void FX(ImDrawList* d, V2 a, V2 b, V2 sz, ImVec4 mouse, float t)
{
for (int n = 0; n < (1.0f + sinf(t * 5.7f)) * 40.0f; n++)
d->AddCircle(V2(a.x + sz.x * 0.5f, a.y + sz.y * 0.5f), sz.y * (0.01f + n * 0.03f),
IM_COL32(255, 140 - n * 4, n * 3, 255));
} Squares #define V2 ImVec2
void FX(ImDrawList* d, V2 a, V2 b, V2 sz, ImVec4, float t)
{
float sx = 1.f / 16.f;
float sy = 1.f / 9.f;
for (float ty = 0.0f; ty < 1.0f; ty += sy)
for (float tx = 0.0f; tx < 1.0f; tx += sx)
{
V2 c((tx + 0.5f * sx), (ty + 0.5f * sy));
float k = 0.45f;
d->AddRectFilled(
V2(a.x + (c.x - k * sx) * sz.x, a.y + (c.y - k * sy) * sz.y),
V2(a.x + (c.x + k * sx) * sz.x, a.y + (c.y + k * sy) * sz.y),
IM_COL32(ty * 200, tx * 255, 100, 255));
}
} Curves #define V2 ImVec2
void FX(ImDrawList* d, V2 a, V2 b, V2 sz, ImVec4, float t0)
{
for (float t = t0; t < t0 + 1.0f; t += 1.0f / 100.0f)
{
V2 cp0(a.x, b.y);
V2 cp1(b);
float ts = t - t0;
cp0.x += (0.4f + sin(t) * 0.3f) * sz.x;
cp0.y -= (0.5f + cos(ts * ts) * 0.4f) * sz.y;
cp1.x -= (0.4f + cos(t) * 0.4f) * sz.x;
cp1.y -= (0.5f + sin(ts * t) * 0.3f) * sz.y;
d->AddBezierCurve(V2(a.x, b.y), cp0, cp1, b, IM_COL32(100 + ts*150, 255 - ts*150, 60, ts * 200), 5.0f);
}
} Waves #define V2 ImVec2
#define ARFM d->AddRectFilledMultiColor
#define ACF d->AddCircleFilled
#define CH s.SetCurrentChannel
void FX(ImDrawList* d, V2 a, V2 b, V2 sz, ImVec4, float t)
{
ARFM(a, b, 0xFF1E1E1E, 0xFF1E281E, 0xFF1E1E5A, 0xFF321E78);
ARFM(a, V2(b.x, a.y + sz.y*0.4f), 0x1EFFDCFF, 0x14FFFFDC, 0x001E1E5A, 0x00321E78);
auto s = d->_Splitter;
s.Split(d, 2);
for (int n = 0; n < 256; n++)
{
V2 c(a.x + n / 256.f * sz.x, b.y + 20 - cos(t - 0.1f * n / 2) * 10 + cos(t) * 5);
float r(40 + sin(t + n / 2) * 40);
CH(d, 0);
ACF(c, r + 1, 0x80FFFFFF);
CH(d, 1);
ACF(c, r, IM_COL32(255, n / 2, n / 8, 255));
}
s.Merge(d);
d->AddRect(a, b, IM_COL32(128, 128, 128, 100));
} |
Thunder Storm #define min(x,y) ((x)<(y)?x:y)
#define wh(a) ImColor(1.f,1.f,1.f,a)
void FX(ImDrawList* d, ImVec2 a, ImVec2 b, ImVec2 sz, ImVec2, float t)
{
static float fl;
if ((rand() % 500) == 0) fl = t;
if ((t-fl) > 0)
{
auto ft = 0.25f;
d->AddRectFilled(a, b, wh((ft - (t - fl)) / ft));
}
for (int i = 0; i < 2000; ++i) {
unsigned h = ImGui::GetID(d+i + int(t/4));
auto f = fmodf(t + fmodf(h / 777.f, 99), 99);
auto tx = h % (int)sz.x;
auto ty = h % (int)sz.y;
if (f < 1) {
auto py = ty - 1000 * (1 - f);
d->AddLine({ a.x + tx, a.y + py }, { a.x + tx, a.y + min(py + 10,ty) }, (ImU32)-1);
}
else if (f < 1.2f)
d->AddCircle({ a.x + tx, a.y + ty }, (f - 1) * 10 + h % 5, wh(1-(f-1)*5.f));
}
} |
The Matrix effect, slowly been shaving off spaces and making the code uglier and uglier //v1.1
#define V2 ImVec2
void FX(ImDrawList*d,V2 a,V2,V2 sz,ImVec4,float t)
{
static struct{int y,h,c; float t,s;} m[40]={0};
static int S=0x1234;
static float t0=t;
float ZI=t*.07f,Z=ZI+1.f;
for(int x=0;x<40;x++)
{
auto& M=m[x];
int i=x>=15&&x<25;
if(M.s==0.f||M.y>16)
{
M.h = (t<7.f||i)*((int)(2+t*.5f) + S%(int)(6+(t*0.3f)));
M.y = (M.s==0.f)*-(S%15)-M.h;
M.c += S;
M.s = (5+(S%14))*(.01f-t*.001f);
if(t>5.f&&i)
{
M.c = (340003872375972UL>>(x*5-75))&31;
M.h = i?(x!=19):0;
}
}
if((M.t-=t-t0)<0.f)
{
if(t<6.f||!i||M.y!=6)
M.y++;
M.t += M.s;
}
char c=64|M.c%42;
for(int j=0; j<M.h; j++,c=64|(c^M.c+M.h^j)%42)
for(int f=(j+1==M.h)?13:4+(M.c&1);f--;)
d->AddText(0, 13*(i?Z:-Z), V2(a.x-(sz.x*.5f*ZI)+x*8*Z+sin(j+t*f), a.y-(sz.y*.5f*ZI)+(M.y+j)*13*Z+cos(x*f-t)), 0x3c68bb5b, &c, &c+1);
S|=((S&1)^((S&8)>>2))<<16;
S>>=1;
}
t0 = t;
} |
Tiny Loading Screen! Had a bunch of fun trying to get this as small I could, managed to get it just under 600 bytes for now. #define V ImVec2
#define R d->AddRectFilled
#define C(x) IM_COL32((sin(x) + 1) * 255 / 2, (cos(x) + 1) * 255 / 2, 99, 255)
#include <set>
void FX(ImDrawList* d, V a, V b, V s, ImVec4, float t) {
static auto z = 0.f;
if (t > z + 2) z += 2;
auto c = C(z + 2);
R(a, b, C(z));
for (auto B = b.x, i = 0.f, o = s.y / 8; i < 8; ++i, B = b.x) {
if (auto w = (i / 7) * .2f, x = std::max(t - z - w, 0.f); t - z < w + 1)
B = a.x + (x < .5 ? 8 * x * x * x * x : std::min(1 - pow(-2 * x + 2, 4.f) / 2, 1.f)) * s.x;
R(V(a.x, a.y + o * i), V(B, a.y + o * i + o), c);
}
} |
Here's my attempt at some abstract fireworks... with about four bytes to spare. The code has ended up pretty unreadable as a result, sadly. #define V ImVec2
#define R rand()
#define I int
#define F float
#define S ((F)R/32767)
#define T(d,b,e)p[j].d=(b*(j&1^j>>1?1:-1))+(e*((j>1)?1:-1))+c.d+a.d;
#define X(a)I a=128+(R&127);
struct P {F x,y,vx,vy,a;I l,s,f,d;};P p[8192]={0};
void A(V o, I f){P t;t.x=o.x;t.y=o.y;t.vx=S*3-1.5;t.vy=S*2.5-(f?4:1);t.l=R%(f?50:99);t.s=R;t.f=f;for(I j=0;j<9;j++){t.d=j;t.a=1-(F)j/9;for(I i=0;i<8192;i++)if(!p[i].l){p[i]=t;break;}}}
void FX(ImDrawList*d,V a,V b,V sz,V mn,F t0){I g=R;for(I i=200;i;--i)d->AddLine(V(a.x,a.y+i),V(b.x,a.y+i),IM_COL32(0,0,i,255));I e=0;for(I i=0;i<8192;i++){P&c=p[i];if(c.l){if(c.d)c.d--;else{srand(c.s);c.x+=c.vx;c.y+=c.vy;c.vy+=.04;c.l-=(c.vy>0)?1:0;F s=(S*3+.1)*(c.f+1);F n=(t0*(c.l<0?0:1))+(i*S*2.5-1.5);F sa=sin(n)*s;F ca=cos(n)*s;V p[4];for(I j=0;j<4;j++){T(x,sa,ca);T(y,ca,-sa);}X(r)X(g)X(b)d->AddConvexPolyFilled(p,c.f?4:3,IM_COL32(r,g,b,(c.f?255:c.l)*c.a));if(!c.l&&c.f&&c.a==1){I l=R%40+15;for(I j=0;j<l;j++)A(V(c.x,c.y),0);}}if(c.f)e++;}}
srand(g);if(e<512)A(V(S*420-50,200),1);} |
Old school plasma.
|
Guitar for strumming. #define V2 ImVec2
#define C1 0xA7A830FF
#define C2 0x775839FF
float amp[6], ml;
int pk;
void FX(ImDrawList* d, V2 a, V2 b, V2 s, ImVec4 m, float t)
{
if (m.z > -1)
pk |= 2;
m.y *= s.y; m.x *= s.x;
m.y += a.y; m.x += a.x;
float st = sin(10*t), th, y, w;
d->AddRectFilledMultiColor(V2(a.x, a.y+40), V2(b.x, b.y-40), C1, C1, C2, C2);
for (float i = a.x + 10, j = 20; i < b.x; i += (j += 10))
d->AddRectFilled(V2(i, a.y+38), V2(i + 8, b.y-38), 0xFF888888, 8);
for (int i = 0; i < 6; i++) {
y = a.y + 48 + i * 16.6; th = 4-i*.5f; w = 1;
int N = 10;
for (int j = 0; j < N; j++) {
float x = a.x + j * s.x / N, k = (w *= -1) * amp[i] * st;
d->AddBezierCurve(V2(x,y+k),V2(x+10,y+k),V2(x+s.x/N-10,y-k),V2(x+s.x/N,y-k),-1u,th);
}
amp[i] *= 0.9;
if (pk == 3) {
float A=ml, B=m.y;
if((A<=y&&B>y)||(A>=y&&B<y))amp[i]+=A-B;
}
}
ml = m.y;
if (pk >>= 1) d->AddTriangleFilled(V2(m.x, m.y), V2(m.x-15, m.y-15), V2(m.x+10, m.y-25), 0xFF0000FF);
} |
Complementary colors I guess? I have to optimize the hell out of it to get it under 1K, the code looks so ugly now :'( But it's quite fun! #define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define fract(x) (abs(x-floor(x)))
#define rand(x,se) (fract(sin(x)*se))
#define eps 1e-3
#define V2 ImVec2
#define C 10000.0f
float mix(float a,float b,float v) {return a+(b-a)*v;}float ss(float a,float b,float v) {return mix(a,b,3.0f*v*v-2.0f*v*v*v);}float perlin(float v,float se) {v=v*0.7f+eps;float f=floor(v);float s=fract(v);float a=rand(f,se);float b=rand(f+1.0f,se);return ss(a,b,s);}float perlin_d(float v,float se) {v *= 2.0f;float f=floor(v);float s=fract(v);float a=rand(f,se);float b=rand(f+1.0f,se);return ss(a,b,s);}void FX(ImDrawList* d,ImVec2 a,ImVec2 b,ImVec2 sz,ImVec4 mouse,float t) {t *= 0.3f;float sa[]={255.0f,0.0f};float sb[]={125.0f,130.0f};float sc[]={0.0f,255.0f};for(int i=0;i<2;i++) {for(int x=0;x<sz.x;x++) {float p=0.5f+rand(1.0f,(C-sa[i]));float bt=perlin(x/sz.x+t*p,C-sa[i])*sz.y;float tp=perlin(x/sz.x+t*p,C-sb[i])*sz.y;float h=tp-bt;d->AddRectFilled(V2(a.x+x,a.y+bt),V2(a.x+x+1,a.y+bt+h),IM_COL32(sa[i],sb[i],sc[i],200));}}} |
I updated the test bed today (to 0.22) to use Beautiful submissions everyone! |
Snake Game (781 bytes) #define v2 ImVec2
#define px(v,c) d->AddRectFilled(a+v*2,a+v*2+v2(2,2),c);
#define fr(v,x) for(int v=0;v<x;++v)
#define eq(l,r) l.x==r.x&l.y==r.y
#define kd(k) ImGui::IsKeyDown(ImGui::GetKeyIndex(k))
v2 sn[160*90]={{20,20}};
int ln=0,tg=4;
float lf;
v2 dr(1,0);
v2 fd(99,45);
void FX(ImDrawList* d, v2 a, v2 b, v2 sz, v2, float t)
{
if (t-lf>0.033f){
lf=t;
if (ln<tg){ln++;sn[ln]=sn[ln-1];}
else fr(x,ln)sn[x]=sn[x+1];
sn[ln]+=dr;
bool e=sn[ln].x<0|sn[ln].x>159|sn[ln].y<0|sn[ln].y>89;
fr(x,ln-1)e|=eq(sn[x],sn[ln]);
if(e)ln=0,tg=4,sn[0]={20,20};
if(eq(sn[ln],fd))tg+=4,fd={rand()%150+5.f,rand()%80+5.f};
if(kd(1))dr={-1,0};
if(kd(2))dr={1,0};
if(kd(3))dr={0,-1};
if(kd(4))dr={0,1};
}
fr(x,ln+1)px(sn[x],-1);
px(fd,-256);
} |
Mosaic. It wasn't what I was trying to do, but ended up in a neat place. #define v2 ImVec2
#define wh(a) ImColor(1.f,1.f,1.f,a)
#define px(v,c) d->AddRectFilled(a+v*2,a+v*2+v2(2,2),c);
#define fr(v,x) for(int v=0;v<x;++v)
#define frc(x) ((x)-int(x))
#define hash(x) (srand(x),ImLerp(rand()/32767.f,rand()/32767.f,0.5f))
#define noise(x) ImLerp(hash(x),hash(x+1),frc(x))
void FX(ImDrawList* d, v2 a, v2 b, v2 sz, v2 mm, float t)
{
fr(x,160)fr(y,90){
auto rx=x-80;
auto ry=y-45;
auto an=ImAtan2(rx,ry);an=an<0?M_PI*2+an:an;
auto len=(rx*rx+ry*ry+0.1f)+t*4;
auto n0 = noise(an);
auto n1 = noise(len);
auto al= n0+n1;
px(v2(x,y),wh(al));
}
} |
Hershey vectorial font! 3.8 KiB. I have not stripped the ASCII chars in the font to make the code fit under 1KiB, bc I wanted to make something useful as well. Sorry for breaking the rules! :D void Hershey(ImDrawList* d, ImVec2 pos, ImVec2 sca, ImVec2 old, char *s) {
static const char *fnt[] = {
"AQ","IKFVFH@@FCEBFAGBFC","FQEVEO@@MVMO","LVLZE:@@RZK:@@EMSM@@DGRG","[UIZI=@@MZ"
"M=@@RSPUMVIVFUDSDQEOFNHMNKPJQIRGRDPBMAIAFBDD","`YVVDA@@IVKTKRJPHOFODQDSEUGVIVK"
"UNTQTTUVV@@RHPGOEOCQASAUBVDVFTHRH","c[XMXNWOVOUNTLRGPDNBLAHAFBECDEDGEIFJMNNOOQ"
"OSNULVJUISIQJNLKQDSBUAWAXBXC","HKFTEUFVGUGSFQEP","KOLZJXHUFQELEHFCH?J<L:","KOD"
"ZFXHUJQKLKHJCH?F<D:","IQIVIJ@@DSNM@@NSDM","F[NSNA@@EJWJ","IKGBFAEBFCGBG@F>E=",\
"C[EJWJ","FKFCEBFAGBFC","CWUZC:","RUJVGUERDMDJEEGBJALAOBQERJRMQROULVJV","EUGRIS"
"LVLA","OUEQERFTGUIVMVOUPTQRQPPNNKDARA","PUFVQVKNNNPMQLRIRGQDOBLAIAFBECDE","GUN"
"VDHSH@@NVNA","RUPVFVEMFNIOLOONQLRIRGQDOBLAIAFBECDE","XUQSPUMVKVHUFREMEHFDHBKAL"
"AOBQDRGRHQKOMLNKNHMFKEH","FURVHA@@DVRV","^UIVFUESEQFOHNLMOLQJRHREQCPBMAIAFBECD"
"EDHEJGLJMNNPOQQQSPUMVIV","XUQOPLNJKIJIGJELDODPESGUJVKVNUPSQOQJPENBKAIAFBED","L"
"KFOENFMGNFO@@FCEBFAGBFC","OKFOENFMGNFO@@GBFAEBFCGBG@F>E=","DYUSEJUA","F[EMWM@@"
"EGWG","DYESUJEA","USDQDRETFUHVLVNUOTPRPPONNMJKJH@@JCIBJAKBJC","x\\SNRPPQMQKPJO"
"ILIIJGLFOFQGRI@@MQKOJLJIKGLF@@SQRIRGTFVFXHYKYMXPWRUTSUPVMVJUHTFREPDMDJEGFEHCJB"
"MAPASBUCVD@@TQSISGTF","ISJVBA@@JVRA@@EHOH","XVEVEA@@EVNVQURTSRSPRNQMNL@@ELNLQK"
"RJSHSERCQBNAEA","SVSQRSPUNVJVHUFSEQDNDIEFFDHBJANAPBRDSF","PVEVEA@@EVLVOUQSRQSN"
"SIRFQDOBLAEA","LTEVEA@@EVRV@@ELML@@EARA","ISEVEA@@EVRV@@ELML","WVSQRSPUNVJVHUF"
"SEQDNDIEFFDHBJANAPBRDSFSI@@NISI","IWEVEA@@SVSA@@ELSL","CIEVEA","KQMVMFLCKBIAGA"
"EBDCCFCH","IVEVEA@@SVEH@@JMSA","FREVEA@@EAQA","LYEVEA@@EVMA@@UVMA@@UVUA","IWEV"
"EA@@EVSA@@SVSA","VWJVHUFSEQDNDIEFFDHBJANAPBRDSFTITNSQRSPUNVJV","NVEVEA@@EVNVQU"
"RTSRSORMQLNKEK","YWJVHUFSEQDNDIEFFDHBJANAPBRDSFTITNSQRSPUNVJV@@MES?","QVEVEA@@"
"EVNVQURTSRSPRNQMNLEL@@LLSA","UURSPUMVIVFUDSDQEOFNHMNKPJQIRGRDPBMAIAFBDD","FQIV"
"IA@@BVPV","KWEVEGFDHBKAMAPBRDSGSV","FSBVJA@@RVJA","LYCVHA@@MVHA@@MVRA@@WVRA",""
"FUDVRA@@RVDA","GSBVJLJA@@RVJL","IURVDA@@DVRV@@DARA","LOEZE:@@FZF:@@EZLZ@@E:L:",
"COAVO>","LOJZJ:@@KZK:@@DZKZ@@D:K:","KQGPISKP@@DMIRNM@@IRIA","CQA?Q?","HKGVFUES"
"EQFPGQFR","RTPOPA@@PLNNLOIOGNELDIDGEDGBIALANBPD","RTEVEA@@ELGNIOLONNPLQIQGPDNB"
"LAIAGBED","OSPLNNLOIOGNELDIDGEDGBIALANBPD","RTPVPA@@PLNNLOIOGNELDIDGEDGBIALANB"
"PD","RSDIPIPKOMNNLOIOGNELDIDGEDGBIALANBPD","IMKVIVGUFRFA@@COJO","WTPOP?O<N;L:I"
":G;@@PLNNLOIOGNELDIDGEDGBIALANBPD","KTEVEA@@EKHNJOMOONPKPA","IIDVEUFVEWDV@@EOE"
"A","LKFVGUHVGWFV@@GOG>F;D:B:","IREVEA@@OOEE@@IIPA","CIEVEA","S_EOEA@@EKHNJOMOO"
"NPKPA@@PKSNUOXOZN[K[A","KTEOEA@@EKHNJOMOONPKPA","RTIOGNELDIDGEDGBIALANBPDQGQIP"
"LNNLOIO","RTEOE:@@ELGNIOLONNPLQIQGPDNBLAIAGBED","RTPOP:@@PLNNLOIOGNELDIDGEDGBI"
"ALANBPD","INEOEA@@EIFLHNJOMO","RROLNNKOHOENDLEJGILHNGOEODNBKAHAEBDD","IMFVFEGB"
"IAKA@@COJO","KTEOEEFBHAKAMBPE@@POPA","FQCOIA@@OOIA","LWDOHA@@LOHA@@LOPA@@TOPA",
"FRDOOA@@OODA","JQCOIA@@OOIAG=E;C:B:","IROODA@@DOOO@@DAOA","hOJZHYGXFVFTGRHQIOI"
"MGK@@HYGWGUHSIRJPJNILEJIHJFJDIBHAG?G=H;@@GIIGIEHCGBF@F>G<H;J:","CIEZE:","hOFZH"
"YIXJVJTIRHQGOGMIK@@HYIWIUHSGRFPFNGLKJGHFFFDGBHAI?I=H;@@IIGGGEHCIBJ@J>I<H;F:",""
"XYDGDIELGMIMKLOIQHSHUIVK@@DIEKGLILKKOHQGSGUHVKVM" };
for( char c, *glyph; (c = *s++, glyph = (char*)fnt[c - 32], c > 0 && c < 127); ) {
if( c != '\n' && c != '\r' ) {
if( c > 32 ) for( int pen = 0, i = 0; i < (glyph[0] - 65); i++ ) {
int x = glyph[2 + i*2 + 0] - 65, y = glyph[2 + i*2 + 1] - 65;
if( x == -1 && y == -1 ) pen = 0; else {
ImVec2 next = ImVec2(pos.x+sca.x*x, pos.y-sca.y*y);
if( !pen ) pen = 1; else d->AddLine(old, next, 0.9*(ImU32)-1);
old = next;
}
}
pos.x += sca.x * (glyph[1] - 65);
}
}
}
void FX(ImDrawList* d, ImVec2 a, ImVec2 b, ImVec2 sz, ImVec4 mouse, float t) {
ImVec2 pos(a.x,((a+b)/2).y), sca(1,sin(t*5)+1+0.5f);
char str[128]; sprintf(str, "Hello imgui! %5.2fs", t);
Hershey(d, pos, sca, ImVec2(), str);
} |
#define V2 ImVec2
#define W 64
#define H 48
#define S 0x07
#define T 0x1F
#define U 0x0F
#define I int
#define F float
I w=0,P[]={S,S,S,T,S,S,0x2F,U,S,0x47,U,S,0x57,0x17,S,0x67,T,S,0x77,T,S,0x8F,0x27,S,0x9F,0x2F,S,0xAF,0x3F,S,0xBF,0x47,S,0xC7,0x47,S,0xDF,0x4F,S,0xDF,0x57,S,0xDF,0x57,S,0xD7,0x5F,S,0xD7,0x5F,S,0xD7,0x67,U,0xCF,0x6F,U,0xCF,0x77,U,0xCF,0x7F,U,0xCF,0x87,0x17,0xC7,0x87,0x17,0xC7,0x8F,0x17,0xC7,0x97,T,0xBF,0x9F,T,0xBF,0x9F,T,0xFF,0xFF,0xFF};
char i[W*H];
void FX(ImDrawList *d,V2 a,V2 b,V2 sz,ImVec4,F t){if(!w){memset(i,0,W*H);memset(i+(H-1)*W,27,W);w=1;}for(I x=0;x<W;x++){for(I y=1;y<H;y++){I j=y*W+x,p=i[j];if(!p)i[j-W]=0;else{I r=I(3.f*rand()/RAND_MAX),d=j-r+1;i[d-W]=p-(r&1);}}};I j=0;F sx=1.f/W,sy=1.f/H,k=0.45f,ty=0;for(I y=0;y<H;y++,ty+=sy){F tx=0;for(I x=0;x<W;x++,tx+=sx){V2 c((tx+.5f*sx),(ty+.5f*sy));I *z=P+i[j++]*3;d->AddRectFilled(V2(a.x+(c.x-k*sx)*sz.x,a.y+(c.y-k*sy)*sz.y),V2(a.x+(c.x+k*sx)*sz.x,a.y+(c.y+k*sy)*sz.y),IM_COL32(z[0],z[1],z[2],255));}}} |
tribute to https://tixy.land/ 473 bytes
|
A Breakout/Arkanoid type of game implementation in 1014 bytes. (Control paddle with mouse, use right-click to reset)
Update:
|
Came across this by accident. I think it looks quite cool. 521 bytes #define V ImVec2
#define CF d->AddCircleFilled
#define RAND(a) (float)rand()/(float)(RAND_MAX/a)
void FX(ImDrawList*d,V a,V b,V s,ImVec4 m,float t) {
static bool o = true;
static V bs[1000];
if(o){
o=false;
for(int i=0;i<1000;++i){
float g=RAND(IM_PI/2)+(IM_PI/4);
float r=RAND(50)+5;
bs[i]=V(g,r);
}
}
for(int i=0;i<1000;++i){
float
g=bs[i].x,
r=bs[i].y;
r+=sin(t+i)*100;
CF(V(r*cos(g),r*sin(g))+(s/2+a)+V(r*cos(t),0),i%2+1,IM_COL32(r+100,50,fabs(r)+100,200));
}
} |
I made a Mandelbrot set visualization with mouse-centered zoom/de-zoom: I also took the liberty to change from Source code (1024 bytes)#include <complex>
ImVec2 shift(-2.12,-0.9);
float scale = 0.01;
float zoom_factor = 0.9;
size_t max_iter = 32;
void FX(ImDrawList* d, ImVec2 a, ImVec2, ImVec2 sz, ImVec4 m, float)
{
if((m.x >= 0 && m.x <= 1 && m.y >= 0 && m.y <= 1) && (m.z > 0 || m.w > 0))
{
float zf = m.z > 0 ? zoom_factor : 1 / zoom_factor;
shift.x -= (m.x * sz.x * scale * (zf - 1));
shift.y -= (m.y * sz.y * scale * (zf - 1));
scale *= zf;
}
for(size_t x = 0; x < sz.x; ++x)
{
for (size_t y = 0; y < sz.y; ++y)
{
std::complex<double> c(shift.x + x /(sz.x-1.0)*(sz.x * scale), shift.y + y /(sz.y-1.0)*(sz.y * scale)), z;
size_t iter;
for (iter = 0; iter < max_iter && std::abs(z) < 2.0; ++iter)
z = z * z + c;
double v = std::log(iter) / std::log(max_iter - 1);
if(iter < max_iter)
d->AddRectFilled(ImVec2(a.x+ x,a.y+ y), ImVec2(a.x+ x +1,a.y+ y +1), IM_COL32((v*255), 255-(v*255), 255, 255));
else
d->AddRectFilled(ImVec2(a.x+ x,a.y+ y), ImVec2(a.x+ x +1,a.y+ y +1), IM_COL32(0, 0,0, 255));
}
}
} |
Mandatory tunnel 971 bytes
|
Awesome stuff so far. I started by looking at some of the first entries, and decided to play with circles. So I went on googling for something to find some inspiration, and I though it would be cool to replicate this: Black and White Minimal Circles Anyway, while playing with the drawing algorithm something went wrong and I ended up with an out of control Death Star laser-shooting randomly onto the galaxy! Death Star - 926 bytes#define V2 ImVec2
#define CR(o,r,c) d->AddCircle(o,r,c)
#define LN(a,b,c) d->AddLine(a,b,c)
#define FORI(n) for(int i=0;i<n;++i)
void FX(ImDrawList*d,V2 a,V2 b,V2 sz,ImVec4,float t){
static float pr{t}, tm{};
static auto st=[](){ImVector<V2> v; v.resize(512); FORI(512) v[i]=V2(rand()%480,rand()%270); return v;}();
V2 hsz{sz/2}, o{a+hsz}, dir{sinf(tm),cosf(tm)}, c, sf;
float dt{}, rad{hsz.y*0.7}, r;
int cnt{rad/2}, sh{!(int(t)%2)}, inc;
FORI(512) CR(st[i],1,0xFF333333);
if(!sh) dt=t-pr,tm+=dt;
pr=t;
ImU32 BL{0xFF000000}, WH{0xFFFFFFFF}, G{0xFF00FF00};
FORI(cnt){r=rad-i,inc=i; c={o.x+inc*dir.x,o.y+inc*dir.y}; CR(c,r,WH);}
V2 la{o.x-rad,o.y}, lb{o.x+rad,o.y};
LN(la,lb,BL);
FORI(cnt){r=rad-(cnt+i), inc=(cnt-i); c={o.x+inc*dir.x,o.y+inc*dir.y}; CR(c,r,WH);}
if(sh){la=o+dir*rad/8; lb=o+dir*hsz.x*2; sf={3*sinf(t*1024),3*cosf(t*1024)}; LN(la,lb,G); LN(la+sf,lb+sf,G); LN(la-sf,lb-sf,G);}
} |
Following the Mandelbrot set visualization, this time I made a Julia sets visualization: Inspired by this Wikipedia gif, the Julia sets represented are generated by
where Source code (1024 bytes)#include <complex>
#define C(r,g,b) IM_COL32(255*(r), 255*(g), 255*(b), 255)
size_t max_iter = 256;
float color_f = 48.0;
float speed_f = 2.0;
ImU32 to_color(float v)
{
v = 1.f - std::log(v * color_f+1) / std::log(color_f+1);
size_t p = v * 5.0;
double g = (v * 5.0 - p);
ImU32 colors[] = {C(1, 0, 1-g),C(1, g, 0),C(1-g, 1, 0),C(0, 1, g),C(0, 1-g, 1),C(0, 0, 1),};
return colors[p];
}
void FX(ImDrawList* d, ImVec2 a, ImVec2, ImVec2 sz, ImVec4, float t)
{
for (size_t x = 0; x < sz.x; ++x)
for (size_t y = 0; y < sz.y; ++y)
{
std::complex<double> z(-2.1+x/(sz.x-1.0)*(sz.x*0.013), -1.15+y/(sz.y-1.0)*(sz.y*0.013));
std::complex<double> c(0.7885*std::cos(t/speed_f),0.7885*std::sin(t/speed_f));
size_t iter;
for (iter = 0; iter < max_iter && std::abs(z) < 2.0; ++iter)
z=z*z+c;
if(iter < max_iter)
d->AddRectFilled(ImVec2(a.x+x,a.y+y), ImVec2(a.x+x+1,a.y+y+1), to_color((float)iter / max_iter));
else
d->AddRectFilled(ImVec2(a.x+x,a.y+y), ImVec2(a.x+x+1,a.y+y+1), 0XFF000000);
}
} |
A little driving game. Use the mouse buttons to move left and right. #define V2 ImVec2
#define R d->AddRectFilled
#define RED 0xff0000ff
void FX(ImDrawList* d, V2 a, V2 b, V2 sz, ImVec4 m, float t)
{
static float mx = a.x + 160;
float dy = 36, dt = 8;
int i = fmodf(dt * t, 2) < 1 ? 1 : 0;
auto v = fmodf(dt * t, 1), y = a.y - dy + v * dy;
for (int s = 1 + sz.y / dy; s > 0; --s, y += dy) {
float c = sinf(t + v / dy - s / dy) * 40;
V2 tl = { c + a.x + sz.x / 2 - 64, y };
V2 br = { c + a.x + sz.x / 2 + 64, y + dy };
R(tl, br, (++i & 1) ? 0xffffffff : RED);
tl.x += 8;
br.x -= 8;
R(tl, br, 0xff3f3f3f);
}
if (m.z >= 0) mx--; if (m.w >= 0) mx++;
R({ mx - 8, b.y - sz.y / 4 - 15 }, { mx + 8, b.y - sz.y / 4 + 15 }, 0xff00ff00, 4);
R({ mx - 7, b.y - sz.y / 4 - 8 }, { mx + 7, b.y - sz.y / 4 + 12 }, 0xff007f00, 4);
R({ mx - 6, b.y - sz.y / 4 + 12 }, { mx - 2, b.y - sz.y / 4 + 14 }, RED);
R({ mx + 2, b.y - sz.y / 4 + 12 }, { mx + 6, b.y - sz.y / 4 + 14 }, RED);
} |
Inspired by this party, my entry is a Game of Life pulsar oscillator (see Wikipedia) Uses left mouse button clicks to process next generation. My algorithm is probably not efficient, and I need quite a big data input, so had to make the code ugly to get to 994 bytes:
|
@pmalin I love that that the compression of the gif paints in an extra mountain range on the right side. Extra scenic! |
Second entry: Sail boat! Based on a small game jam entry I made a few years back. Source is 1019 bytes -- thanks to @andwn for brainstorming additional ideas to shed off characters: #define C cos
#define W(I){F R=H(I)*62,X=a.x+s.x/8*((I%11)-1)+C(R+t)*10,Y=a.y+s.y/8*(I/11)+40+sin(R+t)*10,E=1-exp(-(I/11)/3.);\
d->AddTriangleFilled(V(X,Y),V(X+300,Y+90),V(X-300,Y+90),ImColor(.94f-.17f*E,.61-.25*E,.36+.38*E));}
using F=float;using V=ImVec2;
ImU32 c[7]={0xff00a4fb,0xff00a4fb,(ImU32)-1,(ImU32)-1,0xff262aa2,0xff01007d,0xff64c9fd};
F M=FLT_MAX;V N=V(M,M);F H(F x){F y=C(x)*42;return y-floor(y);}
void FX(auto *d,V a,V b,V s,auto m,F t){d->AddRectFilled(a,b,c[6]);int i=0,j=0,k=0;
for(;i<33;i++)W(i)
F x=C(t*1.3)*2+a.x+s.x*.5,y=15+C(t*1.4)*2.5+C(t*2)*3+a.y+s.y*.5,r=C(t)/10+C(t*1.33)/12,
f[98]={-11,-3.5,4,-24,1.5,-3.5,M,M,5.5,-2,3,-24,11,-2,M,M,2.8,-24,4,-24,4,-2,2.8,-2,M,M,-11,-4.4,4,-4.4,4,-3.5,-11,-3.5,M,M,-12,-2,12,-2,12,0,-12,0,M};
V *v=(V*)f;v[48]=N;
for(i=25;i--;){F d=.1308*i;v[i+23]=V(C(d)*11,sin(d)*8);};
for(;i<49;i++)
if(v[i].x==M){d->AddConvexPolyFilled(&v[j],i-j,c[k]);j=i+1;k++;}
else{v[i]=V(x+(C(r)*v[i].x-sin(r)*v[i].y)*3.5,y+(sin(r)*v[i].x+C(r)*v[i].y)*3.5);}
for(i=33;i<88;i++)W(i)} |
Got an hour to remove the STL dependency from my entry (particularly as I see there are some cool ports above) and polish it a bit. Calling it "spirals" -- source is now down to 1010 bytes, with some formatting retained :)
|
A little shot'em up. Lots of features bypassed to make it fit in 1Ko (missile, gui, sort, planet background, level of difficulty etc.) edit: updated sphere visual (1022b).
|
Inspired by 'Symmetry in Chaos' from Michael Field and Martin Golubitsky. 997 bytes.
|
There you go, 15 bytes removed#define Q 999
#define L(i,x)for(I i=0;i<x;i++)
#define D(a,b)pow(pow(a.p.x-b.p.x,2)+pow(a.p.y-b.p.y,2),.5)
#define S(...)L(i,Q)if(!E[i].i){E[i]={__VA_ARGS__};i=Q;}
#define J (rand()&511)*.002
#define H(a)a.h--;L(i,8)S(a.p,V(cos(J*9),sin(J*9))*99,2,120,0)
using V=ImVec2;using I=int;struct T{V p,v;I i=0,h=99,s=2;};T E[Q],C,&M=E[Q-1],&N=E[Q-2];void FX(ImDrawList*d,V a,V b,V sz,ImVec4 m,float t){C.p=a+sz/2;M.p=a+V(m.x,m.y)*sz;N.p=a+sz*V(.75,.5)+V(sin(t),cos(t*2))*40;if(t<2){M.i=N.i=9;M.s=1;}else{S(V(b.x,a.y+sz.y*J),V(-50-J*50,0),1,40,0)L(i,Q)if(E[i].i){T&e=E[i];e.p+=e.v/50;I j=50+16*e.i;d->AddCircleFilled(e.p,e.i>8?e.s*10+J*(99-e.h)*.1:e.i,ImColor(e.s&2?j:e.h,e.s&1?j:e.h,e.s?0:e.h)*2,32);if(D(C,e)>200+e.i)e.h=0;L(j,Q){T&f=E[j];if(e.h*f.h&&e.s*f.s==2&&D(e,f)<(f.i+e.i)){H(e);H(f);}}if(!e.h){if(e.i==8)L(i,16)S(e.p,V(cos(J*7),sin(J*7))*99,4,1)e.i=0;}if(e.i==2)e.h-=5;}if(M.h*N.h){if(J<.1)S(N.p,M.p-N.p,4,4)if(J<.01)S(N.p,V(-50,0),8,4)if(!m.z)L(j,4)S(M.p+V(0,(j&1)*(j-2)*4),V(500,j<3?(j-1)*250:0),4,1,1)}}} changes :
edit: nvm I can’t count, that’s not 15 at all, that’s only 5 my bad |
!m.z do not work on my visual since it is the mouse (a float) edit: finally i saved 16bytes (thx @Organic-Code) :), i'll try tonight to improve the gfx quality of the spheres |
That’s peculiar, I am building it using MVSC (not visual studio itself though) |
This is my entry, Wolf3D style sw rendering in imgui, called imguiWolf. |
Fluid paint #define U using
#define L for(I
#define M L y=Y;y--;)L x=X;x--;){
#define R return
#define Z [x][y]
enum{X=160,Y=90};U I=int;U F=float;U A=ImVec2;U B=ImVec4;U C=ImColor;U D=A[X][Y];U E=B[X][Y];A operator+(A a,A b){R{a.x+b.x, a.y+b.y};}A operator*(A v,F f){R{f*v.x,f*v.y};}A G(A v){R{v.x-I(v.x),v.y-I(v.y)};}A J(A p){R A(p.x*-.5+p.y*.87,-p.x*.87-p.y*.5);}F K(F a,F b){R a<b?a:b;}E c,d;D e,f,g,h,i;F j,k;void FX(ImDrawList*_,A a,A b,A,B m,F t){F s,z;M g Z=g Z*.9;d Z=c Z;f Z=e Z;}M A u((x+.5)/X,(y+.5)/Y),a=u*2,t(cos(a.x),sin(a.x)),v;s=.01;L l=4;l--;s*=3.7)L m=3;m--;t=J(t)){A q=t*s,r=u+q,p(cos(a.y),sin(a.y)),b,o,w;z=0;L i=3;i--;p=J(p)){b=p*s,w=G(r+b);I x=w.x*X,y=w.y*Y;o=f Z;z+=(o.x*b.y-o.y*b.x)/(b.x*b.x+b.y*b.y);}v=v+A(-q.y*.02,q.x*.03)*z*.33;}u=G(u+v);I i=u.x*X,m=u.y*Y;c Z=d[i][m];e Z=(f[i][m]+g Z*.08)*.99;}s=m.x,z=m.y;M F a=s*X-x,b=z*Y-y,d=1-K(sqrt(a*a+b*b)/12,1);d*=m.z>0;if(d)c Z=C::HSV(t-I(t),sin(t)*.3+.7,1);e Z=e Z+A((j-s)*16,(k-z)*9)*d*.5;}j=s,k=z;M s=a.x+x*2,z=a.y+y*2;_->AddLine({s,z},{s+1,z+2},C(c Z));}} Mouse left-click + drag to paint. Sorry for the heavily compressed code :-s! Inspired by flockaroo's fluid dynamics (https://www.shadertoy.com/view/MdKXRy). |
Ok, here is another one. I thought the ImDrawList coding party needed a disco ball. #define V ImVec2
#define F float
void R(F&x,F&y,F r){F s=sin(r),c=cos(r),t=c*x-s*y;y=s*x+c*y;x=t;}
F c,e,f,g,l,r,x,y,z;
int i,j,k,u,v,K=24,J=48;
F L(F a){l*=l>0;return sqrt(1-exp(-a*(l+.1)-l*l*l));}
void T(F u){R(x,z,c+6.28*u);}
V P(F t){t*=3.14/K;return V(sin(t),cos(t));}
void FX(ImDrawList*d,V a,V b,V S,ImVec4 I,F t){
V o[4],m=(a+b)/2;c=t/2;
k=sin(t*13)*24+24;j=-0xafefb0+k*0x101;d->AddRectFilledMultiColor(a,b,j,j+0x503010,j+0x4050,j+0x7040);
for(k=K;--k;){for(j=J;j--;){for(i=4;i--;){
u=j+(i%3>0);v=-(i/2);
V p=P(k+v);x=p.x;y=p.y;z=0;
T((F)u/J);e=x;f=y;z=S.y/(g=z+2.5);
o[i]=m+V(x,y)*z;}
V v1=P(k),v2=P(k-1);
x=v1.y-v2.y;y=v2.x-v1.x;z=0;
l=sqrt(x*x+y*y);x=x/l;y=y/l;T((j+.5)/J);
r=2*(x*e+y*f+z*g);
e-=r*x;f-=r*y;g-=r*z;
l=sqrt(e*e+f*f+g*g);
x=atan2(e,g);y=atan2(sqrt(e*e+g*g),f);
l=sin(x*5+sin(y*3+t))+sin(x*9+sin(y*5+t))+cos(y*4+sin(x*5+t));
l=l/4+.5;
I.x=l;I.y=l*.9*(.8+e/4);I.z=(.5-f/2)*l/2;I.w=1;
if(r>0)d->AddConvexPolyFilled(o,4,ImColor(I)),d->AddPolyline(o,4,0xff<<24,true,1);
}}} (1022 bytes) |
Amazing work all! As per the undefined behavior of what constitute a deadline of "Nov 30", let's make it maximum-optimistic Pacific Time, aka about 19 extra hours from the time of this post. What shall we do with this to provide some kind of climax?
|
3D Sierpinksi Triangle |
Hello, here's my entry, mixing random terrain generation and some kind of simulation (pseudo random movement, boundary checking). Randomness strives to eat all vegetation; once that happens, everything starts all over.
1022Kb, my backend is limited to 60 FPS, I hope the simulation runs well on other configs. Thanks for ImGui, thanks for all entries, this was a marvellous week ! |
Thought I'd do something with hexagons! 1024 bytes exactly.
|
I'm late to the party but here goes. seven segment timer (resizable).
|
#3606 (comment) Might be a headache to put into place though, not all code snippets assumes the same compiler parameters (I had to modify about half of those I tested) |
@mgood7123 you’ve posted ~15 messages on this repo and opened various issues today, please be kind to not treat this is a chat room and keep discussions focused and mindful that this is a shared space (people get notifications when you send a message) |
sorry |
is this available somewhere? if so where can i find it? |
how do you record the snippets and upload them on the GitHub? is there a imGui middle ware for there? |
This is very nice, and it's exactly what I am looking for but I tried to figure out how to replace the text at the end and it is the char c = 64 if you change the value then it will randomize another ASCII chars but could you please explain a little bit from that code maybe to change to 0 1 0 or maybe to display 'Thanks' |
ImDrawList coding party!
Two days ago I thought:
"It'd be fun to organize a contest for writing special effects using the ImDrawList api, with a constraint on source code size. May be fun to see what people can come up with using shape/vector-based api (quite different from a pixel-shading function). Would you participate?"
It's by no mean a great api but it has served many well, to draw custom widgets etc, let's get it some extra love..
Here's a testbed
imdrawlist_party.cpp
which you can paste in your application or any dear imgui example:https://gist.github.com/ocornut/51367cc7dfd2c41d607bb0acfa6caf66
Rules:
fx.inl
must be <= 1024 bytes.Prizes:
Function signature:
If not using a given parameter, you can omit its name in your function to save a few characters.
To record gif files you can use ShareX https://getsharex.com or ScreenToGif https://www.screentogif.com/
Let's get started! You can post on this thread, on discord or on twitter!
Known issues
The text was updated successfully, but these errors were encountered: