したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

662774さん:2008/11/03(月) 17:09:11 ID:CENbthlg0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <windows.h>
#include <tchar.h>
#include <process.h>

template<typename T>
class comp{
public:
T r, i;

comp(){
comp(0);
}
comp(T a){
comp(a, 0);
}
comp(T a, T b){
r = a;
i = b;
}

comp operator+(const comp &a){
comp b;
b.r = this->r + a.r;
b.i = this->i + a.i;
return b;
}
comp operator*(const comp &a){
comp b;
b.r = this->r * a.r - this->i * a.i;
b.i = this->r * a.i + this->i * a.r;
return b;
}
T abs(){
return this->r * this->r + this->i + this->i;
}
};

template<typename T>
T abs(T a){
return a >= 0 ? a : -a;
}

template<typename T>
T abs(comp<T> a){
return a.abs();
}

const int c = 10000;

template<typename T>
int in(T a){
T b = 0;
for(int i = 0; i < c; i++){
if(abs(b) >= 2) return i;
b = b * b + a;
}
return -1;
}

const TCHAR *className = _T("test");

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
switch(msg){
case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_PAINT:{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);

const static COLORREF ref[] = {
RGB(0xFF, 0x00, 0x00),
RGB(0x00, 0xFF, 0x00),
RGB(0x00, 0x00, 0xFF),
RGB(0xFF, 0xFF, 0x00),
RGB(0xFF, 0x00, 0xFF),
RGB(0x00, 0xFF, 0xFF),
};

for(int i = -450; i < 200; ++i){
for(int j = -300; j < 300; ++j){
//SetPixel(hdc, i + 450, j + 300, RGB(0xFF, 0xFF, 0));
int ret = in(comp<double>((double)i / (double)300, abs((double)j / (double)300)));
if(ret == -1){
SetPixel(hdc, i + 450, j + 300, RGB(0, 0, 0));
}else{
//SetPixel(hdc, i + 450, j + 300, ref[(ret / 1) % (sizeof(ref) / sizeof(ref[0]))]);
}
}
}

EndPaint(hWnd, &ps);

break;
}

default:
return DefWindowProc(hWnd, msg, wp, lp);
}
return 0;
}

unsigned int __stdcall thread(void *){
RECT rc = {0, 0, 800, 800};
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);

HWND hWnd = CreateWindowEx(
0,
className,
_T("test"),
WS_OVERLAPPEDWINDOW,
rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top,
NULL,
NULL,
GetModuleHandle(NULL),
NULL
);
ShowWindow(hWnd, SW_SHOW);

MSG msg;
while(1){
BOOL ret = GetMessage(&msg, NULL, 0, 0);
if(ret == 0 || ret == -1){
break;
}
DispatchMessage(&msg);
}

return 0;
}

int main(int argc, char **argv){

WNDCLASSEX wc = {sizeof(wc)};
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = className;
wc.hIconSm = NULL;

RegisterClassEx(&wc);

HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, thread, NULL, NULL, NULL);

std::string str;
while(1){
std::getline(std::cin, str);
if(str == "end"){
break;
}
}
}


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板