Skip to content

Instantly share code, notes, and snippets.

@klmr
Created February 19, 2015 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klmr/864a87d25c048736a11f to your computer and use it in GitHub Desktop.
Save klmr/864a87d25c048736a11f to your computer and use it in GitHub Desktop.
GDI golf
// stdafx.h isn’t needed.
// However, we DO need the line break after the include,
// even in the golf version.
#include <windows.h>
// _tmain => main; VC++ accepts both.
int main()
{
HDC h = GetDC(0);
// Remove i++ here …
for (int i = 0; i < 50;){
// 65793 == 0x010101; multiplying with 1…50 generates
// grey tones and is much shorter than RGB macro use
SelectObject(h, CreatePen(0, 9, i*65793));
// i * 9 + 9 == i * 10
// … add i++ here.
Rectangle(h, i * 9, i * 9, i * 10, i++ * 10);
}
}
#include <windows.h>
int main(){HDC h=GetDC(0);for(int i=0;i<50;){SelectObject(h,CreatePen(0,9,i*65793));Rectangle(h,i*9,i*9,i*10,i++*10);}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment