|
You have been asking the same questions for some time now. Realistically, the best way to do this is to create a class for each shape you want to draw, with a common base class, and make a list of that base class. Then you can make the class know how to build itself from the string you store in your file, and to generate a string which identifies the shape type and the details of that shape.
I'd go for something less verbose, you really only need to store numbers, just assign each shape type a number.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
where can I find algorithms for drawing different shapes, I found some to draw spiral and circle, but I need to have more shapes.
Can you please recommend any website(s) that helps?
thanks,
|
|
|
|
|
just more? nothing specific?
http://www.acm.org/tog/GraphicsGems/[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
thanks El Corazon,
I don't need any specific shape,
for example:
<br />
for( int i=0 ; i<200 ; ++i)<br />
{<br />
theta = 2+Math::PI*float(i)/10;<br />
r = Math::Sqrt(theta);<br />
x=r*Math::Cos(theta)+400;<br />
y=r*Math::Sin(theta)+400;<br />
}<br />
this algorithm will give me a very beautiful shape. I need more algorithms that would to the same.
|
|
|
|
|
sarah_malik wrote: I need more algorithms that would to the same.
there are many. It is called a polar graph, or polar equation. That particular one is one of the more simple ones.
x=r*cos(theta);
y=r*sin(theta);
is the translation from polar (radius=r, angle=theta) coordinates to Cartesian coordinates.
You can make your own and experiment with others from here:
http://www.analyzemath.com/polarcoordinates/polarcoordinates.html[^]
http://www.analyzemath.com/polarcoordinates/graphing_polar_equations.html[^]
I did many polar coordinates on my first computer, including a spider's web.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
|
The Grand Negus wrote: the number of things you can draw with formulas is seriously limited.
Actually, the number of things you can draw with formulas are infinite, but not all of them attractive. In many cases, one formula provides infinite variations, though subtle, and given multiple formulas and methods (like fractals?), the list goes on....
however... that was why I pointed to the graphics gems first, which covers algorithmic drawing in detail.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
|
sarah_malik wrote: but I just need algorithms that would draw such things.
check out the formulas behind fractals. There are many self-similar iterative design systems. http://en.wikipedia.org/wiki/Fractal[^] also L-Systems: http://en.wikipedia.org/wiki/L-system[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
THANK YOU.
|
|
|
|
|
You are welcome. The hardest part is trying to figure out what you are looking for. There are as many shapes as the imagination, and as many methods of getting them.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
The Grand Negus wrote: do you want to (1) write a program to produce art of a particular kind, or do you want to (2) use someone else's program to produce these works?
I'm trying to write a program that produces art
The Grand Negus wrote: I need to know what language(s) you know, your level of expertise, and how much time you're willing to spend on the thing.
I know C, C++, managed C++ and VB. I'm a beginner in the graphics field, actually this is my firt graphics program and I would spend maybe 1 to 2 weeks.
thanks,
|
|
|
|
|
sarah_malik wrote: I'm trying to write a program that produces art
Take a look at FractInt in the link that GN gave you. I haven't used fractint in years, but the idea was you could zoom in and out of fractals getting the core numbers to reproduce it. So you can find the art within the math, and get the numbers back out to reproduce it. I used to play around with it a lot. Fractals make for interesting art as you saw in the mosaic images. Fractals are a good tool, mathematically and visually interesting.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
The Grand Negus wrote: The source code (in Plain English) is also on the site.
You should try Ultimate C++, you could reduce the verbiage of that source by a factor of 3 or 4.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
The Grand Negus wrote: How 'bout them Mandelbrots?
Alive and well, and producing images through infinity.
http://users.erols.com/ziring/mandel.html[^]
http://www.codeproject.com/cpp/mandelbrot_obfuscation.asp[^]
or
void mandel(int xpt, int ypt)<br />
{<br />
long double x=0;<br />
long double y=0;
long double xnew=0;<br />
long double ynew=0;<br />
<br />
for(int k=0;k<=initer;k++)
{<br />
<br />
xnew=x*x-y*y + xpt*pixcorx+Minx;<br />
ynew=2*x*y + Maxy-ypt*pixcory;<br />
x=xnew;<br />
y=ynew;<br />
if ( (x*x+y*y)>4 ) break;
}
<br />
int color = k;<br />
if (color>15) color=color%15;<br />
if (k>=initer)<br />
putpixel(xpt,ypt,0);<br />
else<br />
putpixel(xpt,ypt,color);<br />
<br />
newcolor=color;<br />
}
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
I can't thank you enough guys. I really appreciate your help.
thanks for everything.
|
|
|
|
|
Hello frens, help me about how to code for flipping an image horizontally or vertically myself, as a general guide?
I need to do it without using the library functions.
madhav
|
|
|
|
|
The basic idea is to move the data for each pixel from it's original place to its flipped place.
How you code it depends on the layout of your image pixel data.
Typically it's in a packed form (like an array), where pixel data for a row is consecutive and
each row of pixel data follows the previous. To flip the pixels in-place (without needing a
second image buffer) you could use a pointer to the first row/column pixel data and a pointer to
the last row/column pixel data (whether you use row or column depends on if you are flipping
horizontally or vertically)...
Pseudocode for vertical flip:
Set FirstRowPtr to first row pixel data
Set LastRowPointer to last row pixel data
loop (imageheight / 2) times
{
swap FirstRowPtr pixel data with LastRowPointer pixel data
Set FirstRowPtr to next row pixel data
Set LastRowPointer to previous row pixel data
} For interlaced image data it's similar, but the row/col calculations are more complex.
Hope that helps a bit,
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
Imagine your image in a mirror reflected in the Y Axis:-
|
0 | 0 | 1 | 1 | 0 | 0
----------|----------
1 | 1 | 0 | 0 | 1 | 1
----------|----------
0 | 0 | 1 | 1 | 0 | 0
|
All we do to achieve this is to negate the X coordinate:-
|
-3,1 | -2,1 | -1,1 | 1,1 | 2,1 | 3,1
-------------------|------------------
-3,2 | -2,2 | -1,2 | 1,2 | 2,2 | 3,2
-------------------|------------------
-3,3 | -2,3 | -1,3 | 1,3 | 2,3 | 3,3
|
But now its in the wrong place so we need to shift it to bring it back:-
SHIFT ---------->>
|
0 | 0 | 1 | 0 | 0 | 1
----------|----------
1 | 1 | 0 | 1 | 1 | 0
----------|----------
0 | 0 | 1 | 0 | 0 | 1
|
So generally we have for an n x m array of pixels reflected in the Y axis (ie horizontal reflection):-
(x,y) -> (-x+n+1,y) (for arrays starting at 0 drop the '+1')
and for the same n x m array of pixels reflected in the X axis (ie vertical reflection):-
(x,y) -> (x,-y+m+1) (for arrays starting at 0 drop the '+1')
Of course this only works for simply defined pixel arrays!
|
|
|
|
|
Hi, i am writing a small app for a WMP Visualization. The app can be downloaded here[^] and the viz can be found here[^].
Can someone please have a look at the code and tell me what's wrong. For starters, i want to render an image in the background then warp it and draw it back to the screen. There are some problems with that. I use RAD C++ for the GUI (http://www.radcpp.com).
Here is some of the code
void Graphics::copyToTexture(WarpFile &wf) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
renderBackground(wf);
glCallList(displayList[DL_TEX_ENABLE]);
glBindTexture(GL_TEXTURE_2D, image);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex2f(0, 0);
glTexCoord2f(0, 0); glVertex2f(0, 512);
glTexCoord2f(1, 0); glVertex2f(512, 512);
glTexCoord2f(1, 1); glVertex2f(512, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, backTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0);
glCallList(displayList[DL_TEX_DISABLE]);
glBindTexture(GL_TEXTURE_2D,0);
SwapBuffers(hdc);
}
It needs to be compiled with Dev-C++, you may need OpenGLUT.dll i forgot to include it in the zip file.
Can someone please help me
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
I would like to help, but you don't say what the problem is. And I don't want to spend an afternoon going through code. Maybe you could say what you expected to obtain and what it is that you are obtaining? Also, I know OpenGL but I don't know what is a WMP.
It seems to me you are trying to draw something and then make OpenGL modify it for you. I'm not sure I understand what you want but in general you already have to have your data ready when you call OpenGL to render a 3D world. OpenGL is the one doing all the drawing (generally speaking) and usually doesn't process (or modify) an already drawn image.
I once made an application to wrap the real-time video feed from a web cam onto a 3D virtual object in the OpenGL world. Do you want to do something like that?
Rilhas
|
|
|
|
|
Rilhas wrote: I once made an application to wrap the real-time video feed from a web cam onto a 3D virtual object in the OpenGL world. Do you want to do something like that?
Pretty much. WMP stands for Windows Media Player and i am making a visualization for it. That is the image that is shown when you play a song. It is a moving image that is rendered in real-time and usually moves to the beat of the song. I want to warp the image i have drawn using a 2D array of warp points. I am currenty making an app that edits those points. When it draws the image, it renders it to a texture then draws quads using the points and maps the a section of the texture to it's respective quad. I then copy the screen (with the warped image) back to that texture and do the whole thing again each frame. The result is that the image has a blur/trace effect where the warped image constantly fades into the background.
Here are some pics http://img519.imageshack.us/img519/1388/viz1kx4.th.png http://img99.imageshack.us/img99/4991/screenshot4kj7.th.jpg
Check out the SwapBuffers post to see my latest problem and see if you can help me their.
Customer in computer shop: "Can you copy the Internet onto this disk for me?"
|
|
|
|
|
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
HDC hdcWindow;
static int nScreenWidth, nScreenHeight;
switch (message)
{
case WM_CREATE:
nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
SetTimer( hwnd,0,2000,NULL);
return 0 ;
case WM_LBUTTONDOWN:
{
HWND tBarHandle= NULL;
return 0;
}
case WM_PAINT:
{
hdc = BeginPaint (hwnd, &ps) ;
hdcWindow = GetWindowDC( hwnd);
HWND hDesktopWnd = GetDesktopWindow();
HDC Source = GetDC(hDesktopWnd);
HDC Destination = CreateCompatibleDC(Source);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight);
SelectObject(Destination,hCaptureBitmap);
BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY);
BitBlt(hdc,0,0 , nScreenWidth, nScreenHeight, Source, 0,0, SRCCOPY);
ReleaseDC(hDesktopWnd,Destination);
DeleteDC(Source);
DeleteObject(hCaptureBitmap);
EndPaint (hwnd, &ps) ;
}
return 0 ;
case WM_TIMER:
GetClientRect(hwnd,&rect);
InvalidateRect( hwnd, &rect, true);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
How to convert DDB format to DIB format using GETDIBits() function ????
|
|
|
|
|
Something like this maybe...
(warning - I haven't provided for a color table of any kind!! This means this won't work for a
palette-based video mode or a non BI_RGB DIB, which is why I force it to BI_RGB)
int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
HDC Source = ::GetDC(0);
HDC Destination = ::CreateCompatibleDC(Source);
HBITMAP hCaptureBitmap = ::CreateCompatibleBitmap(Source, nScreenWidth, nScreenHeight);
HGDIOBJ hOldBm = ::SelectObject(Destination, hCaptureBitmap);
::BitBlt(Destination,0,0,nScreenWidth,nScreenHeight, Source, 0, 0, SRCCOPY);
::SelectObject(Destination, hOldBm);
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, NULL, &bmi, DIB_RGB_COLORS);
bmi.bmiHeader.biCompression = BI_RGB;
BYTE *pPixelBytes = new BYTE[bmi.bmiHeader.biSizeImage];
::GetDIBits(Source, hCaptureBitmap, 0, nScreenHeight, pPixelBytes, &bmi, DIB_RGB_COLORS);
::ReleaseDC(0, Source);
::DeleteDC(Destination);
::DeleteObject(hCaptureBitmap);
delete[] pPixelBytes;
Also make sure you use the correct ReleaseDC/DeleteDC calls on the appropriate DCs.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|