Mercurial > hg > Members > yutaka > manager
view task/Run.cc @ 7:febf899d0043
mandelbrot
author | yutaka@localhost.localdomain |
---|---|
date | Mon, 12 Apr 2010 00:32:34 +0900 |
parents | 39d405bc46b7 |
children | ec2c1003f9b6 |
line wrap: on
line source
#include <stdio.h> #include <math.h> #include "Run.h" typedef struct { float red; float green; float bule; float alpha; } rgb_t; void mandelbrot(float &za, float &zb, float cx, float cy) { float tmp_za = za; float tmp_zb = zb; za = tmp_za * tmp_za - tmp_zb * tmp_zb + cx; zb = 2 * tmp_za * tmp_zb + cy; } void set_rgb(rgb_t rgb, int *pixels) { *pixels = (char)rgb.red | ((char)rgb.green) << 8 | ((char)rgb.bule) << 16 | ((char)rgb.alpha) << 24; //*pixels = 255; } void run(void *in, void *out, int size_in, int size_out) { int *pixels = (int*)out; int *location = (int*)in; for (int l = location[0]; l <= location[0] + size_out; l += 4) { int x = l / 4 % 1920; int y = l / 4 / 1920; float a = 0; float b = 0; float cx = (x - 1200) / 500.f; float cy = (y - 540) / 500.f; int i; for (i = 0; i < 255; i++) { mandelbrot(a, b, cx, cy); if( a*a + b*b > 4) { break; } } rgb_t rgb; rgb.red = 255 * sin(i); rgb.green = 255 * sin(i); rgb.bule = 255 * cos(i); rgb.alpha = 1; set_rgb( rgb, &pixels[(l - location[0]) / 4] ); } //printf("location[0] %d\n",location[0]); //printf("location[1] %d\n",location[1]); //rgb.red = 0; //rgb.green = 255; //rgb.bule = 255; //rgb.alpha = 1; }