October 6th, 2012, 11:29 PM
How to draw pixel-level color gradients in CScrollView ?
I have a very general question. I wish to plot a mathematical function on a 2-dimensional grid. The function will be represented by 3 sets of floats, x-values, y-values, and z-values. Obviously, it is impossible to plot 3 such data sets on a 2D grid, so one approach is to use pixel coloration to represent the z-values.
Those examples (and there are many to be found) show something like the function of the complex variable z, f(z) = exp(z). I have attached a exp(z).jpg example of the imaginary part of the plot exp(z).
My question is: How to accomplish such a gradient colorization, assuming one already has the data?
I have experimented with Gdiplus SetPixel, but I have not figured out how to produce a smooth gradient. Obviously, I'm in way over my head, but I had hoped someone might lead me in the right direction.
Here's my attempt to create a simple gradient:
You can see my lame result also attached mygrad.jpg. Your thoughts greatly appreciated. How would you do this ?
CDC * pDC = GetDC();
HWND hwnd = GetSafeHwnd();
CDC * pdc = GetDC();
HDC hdc = ::GetDC(hwnd);
COLORREF cr = RGB(192, 192, 192);
for(int x = 10; x <= 600; x++)
for(int y = 10; y <= 400; y++)
SetPixelV(hdc, x, y, cr);
cr += 1;
Click Here to Expand Forum to Full Width