News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Random Graphics Generator

Started by Bieb, February 24, 2005, 08:11:42 PM

Previous topic - Next topic

Bieb

I've got an interesting problem now.  Several years ago, back when I used QBASIC (hehe, I didn't even used to know what C or ASM were) I wrote a very interesting program that I called the random graphics generator.  It would take 8 seed numbers from the user.  Then, it would enter an infinate loop where it would draw a series of lines, points, and circles on the screens, using the seed numbers to get coordinates and color codes.  Then it would use an algorithm to change all the numbers by using arithmatic operations with both constant nuwbers and other seed numbers used for variation, and draw all over again.  The program was incredible.  It drew the most astounding graptics you could imagine, and because of the algorithm I used (which I just sat down and made up completely randomly) using different seed numbers could allow for a huge variation in the graphics it would draw.  Unfortunately, it was lost several years ago in a hard disk crash.  There might be someone out there who still has it on their computer, but I doubt I'll ever find a copy.

So, I plan to try and recreate it using assembly.  Problem is, I don't know anything about graphics in Win32 ASM.  I remember when I was learning game programming in Visual Basic that I could draw things on a picturebox control.  So, how exactly would I go about doing that?  I just need to be able to draw circles, lines, and points in different colors.

petezl

I'm sure I still got some .bas stuff on floppies, somewhere in the attic, I'll have a dig around. It might give some ideas as starting points. From what I remember, one likely way forward is to use a Static with a BITMAP style and use pens, circle and line commands. I should imagine that trying to convert the code from bas to asm would be almost impossible, it might be better to see the screen results of a bas file and try to recreate it, using the original code for guidance.
Unless you want to use directX but that's out of my league.

Peter.
Cats and women do as they please
Dogs and men should realise it.

QvasiModo

Check out the MSDN site (http://msdn.microsoft.com), at the "GDI" section, you'll see there are API calls (somewhat) similar to the old QBASIC commands to draw on the screen. You can start from here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/wingdistart_9ezp.asp

Hope that helps! :)

P1

Quote from: Bieb on February 24, 2005, 08:11:42 PM... I wrote a very interesting program that I called the random graphics generator. ...
You did not tell us the name, but did you try Googling with the name??

Regards,  P1  :8)

Bieb

Petezl, I'm not trying to port it, since I don't have the original .BAS's.  Qvasi, I'll have a look at that.  Thanks.  P1, the name of it was just the Random Graphics Generator.  I've tried Googling it with no success.  I'll try some QBASIC forums that I might have given it to people on...

Bieb

Okay, I've found that there's a whole load of functions that start with line.  To start with, I put a Picture control down (I'm using Easy Code), and in my WM_CREATE code, I had it retrieve and store the handle to the Picture and then call a procedure that invokes the Line function using the parameters HandleOfPictureBox, 0, 0, 50, 50, FALSE , 00009900h.  And it does nothing.  I've tried setting the bbox parameter to TRUE, but it doesn't do anything then, either.  So, what am I missing?

petezl

Bieb,
Q1)  (Easy code I don't know)  In Masm you need to:  in WM_CREATE - create your colored pen or you won't see it as it will be default. do all your line painting in WM_PAINT (obviously)  like SelectObject redPen, do the drawing then select the oldPen before leaving WM_PAINT.
On WM_DESTROY call DeleteObject redPen. The window your drawing on really needs to be created as a Static with no owner and with SS_BITMAP style.  I'll knock together a simple example and post it.

Q2)  I've retrieved a pile of old floppies from the attic. The nearest I've got to what you were talking about is a user  defined torrus.bas. See attached. Quite cool   :8) for for the time it was created.
Peter.

[attachment deleted by admin]
Cats and women do as they please
Dogs and men should realise it.

Bieb

An example would be very helpful.  Thanks.

petezl

Bieb, Attached is a simple example. I put everything in the paint procedure and used the client area for simplicity of demonstration, but would normally create the pens in WM_CREATE (don't forget to save the default), select pens at random in WM_PAINT (but don't save them) then in WM_DESTROY restore the default pen and delete the ones you created.
Peter.

[attachment deleted by admin]
Cats and women do as they please
Dogs and men should realise it.

Bieb

Thanks.  Easy Code, by the way, still uses MASM code.  It's just an IDE that lets you visually design windows and then auto - generates the code to set it all up.

Bieb

Okay, I think I understand all this drawing stuff now.  Now for (hopefully) my last noob question of the day.  Can I send the PAINT message from other points in the program?

petezl

That line ex. I send you last night? well it was late and although it will work fine, it's quite lousey code if your doing intensive painting.
I'll do a better example (for my own benefit as well as yours!) .
To call paint you can use UpdateWindow or InvalidateRect.
invoke InvalidateRect, hWnd, addr rect, 0, 0
Peter.
ps. If I make mistakes, it's because I have to reboot between Linux and windows write or test code.
Cats and women do as they please
Dogs and men should realise it.

petezl

Bieb, I've just written a better version from scratch using  a static control. No doubt it could be improved but it uses the pens more sensibly.
Well commented...
Peter.

[attachment deleted by admin]
Cats and women do as they please
Dogs and men should realise it.

Bieb

Thanks, that was an excellent example.  What exactly is a static control, though?  Other than that, I think I pretty much understand the use of the GDI now.  I've written a slightly more complicated example that uses the whole window as a drawing surface, with loads of comments, for anyone interested, in Easy Code.  Thanks again for showing me how to do this.

[attachment deleted by admin]

petezl

A static control is really just a "Static Text" window.  When you add the SS_BITMAP style it makes the window transparent. This creates much more versitality than painting directly to the client area ( and it keeps a bit of uniformity in the coding as well) . For instance, you can  use a pattern brush to paint a bitmap in the client area (Background) then draw in the static window so that you have a superimposed picture or drawing on the top (much like layers in photoshop).
Peter.
Cats and women do as they please
Dogs and men should realise it.