Board index » delphi » 3 Questions

3 Questions

Greetings to all,

I have 2 questions that are presently puzzling me,

1) If i want a form's canvas to redraw itself after an application has been
maximised, should i use the applications OnMaximise event
(I currently use the OnPaint event, but this also seems to be called  when
an application is started, which i'd like to avoid) if this is the case how
should i access the OnMaximise event?

and

2) I'd like to experiment with cellular automata but don't know the best way
of representing a 2d grid environment visually (DrawGrid ?), ideally it
should be able to have differing cell colours and be able to access values
stored in a 2d array (with wrap-around), or have some way of achieving a
similar result.

3) On a similar note, Is there any way of drawing separate images to each
cell in a grid?

Many thanks to people that have answered my previous questions to the list,
all comments have been very useful.

Regards

PX

 

Re:3 Questions


Patrick Robinson <mak...@dial.pipex.com> skrev i en
nyhedsmeddelelse:876h7a$ss...@lure.pipex.net...

Quote
> 1) If i want a form's canvas to redraw itself after an application has
been
> maximised, should i use the applications OnMaximise event
> (I currently use the OnPaint event, but this also seems to be called  when
> an application is started, which i'd like to avoid) if this is the case
how
> should i access the OnMaximise event?

I would use the forms OnResize event and do a
  Refresh;

Quote
> 2) I'd like to experiment with cellular automata but don't know the best
way
> of representing a 2d grid environment visually (DrawGrid ?), ideally it
> should be able to have differing cell colours and be able to access values
> stored in a 2d array (with wrap-around), or have some way of achieving a
> similar result.

You could create a 2-dim, array:
var
  Cellular: array [0..99, 0..99] of Integer;

and you could use a TImage to draw/display it.

Quote
> 3) On a similar note, Is there any way of drawing separate images to each
> cell in a grid?

With a TImage you can draw anything you want.

Finn Tolderlund

Re:3 Questions


In article <876h7a$ss...@lure.pipex.net>, "Patrick Robinson"

Quote
<mak...@dial.pipex.com> writes:
>I have 2 questions that are presently puzzling me,

<snip>

There are three sorts of people in the world, those who can count and those who
can't <g>

Alan Lloyd
alangll...@aol.com

Re:3 Questions


And there are those of us with a mind buzzing with questions, who don't have
time to worry about whether their emails are completely error free

but thanks for taking your time to point it out

Regards

PX

P.S -  next time include an answer!

Quote
AlanGLLoyd wrote in message

<20000201114357.18188.00000...@nso-cb.aol.com>...
Quote
>In article <876h7a$ss...@lure.pipex.net>, "Patrick Robinson"
><mak...@dial.pipex.com> writes:

>>I have 2 questions that are presently puzzling me,

><snip>

>There are three sorts of people in the world, those who can count and those
who
>can't <g>

>Alan Lloyd
>alangll...@aol.com

Re:3 Questions


Quote
Finn Tolderlund wrote in message ...

>> 2) I'd like to experiment with cellular automata but don't know the best
>way
>> of representing a 2d grid environment visually (DrawGrid ?), ideally it
>> should be able to have differing cell colours and be able to access
values
>> stored in a 2d array (with wrap-around), or have some way of achieving a
>> similar result.

>You could create a 2-dim, array:
>var
>  Cellular: array [0..99, 0..99] of Integer;

>and you could use a TImage to draw/display it.

Would using TImage allow me to "zoom" in and out - or view in more detail? I
initially tried the above using a forms Canvas property but the problem was
the definition was too fine - i.e. I couldn't see my cells in any detail -
which is why i thought of TDrawGrid.

Regards
PX

Re:3 Questions


Patrick Robinson <mak...@dial.pipex.com> skrev i en
nyhedsmeddelelse:877770$kk...@lure.pipex.net...

Quote
> Would using TImage allow me to "zoom" in and out - or view in more detail?
I
> initially tried the above using a forms Canvas property but the problem
was
> the definition was too fine - i.e. I couldn't see my cells in any detail -
> which is why i thought of TDrawGrid.

Why do you think that you have to draw the cells in 1x1 pixel size?
If you want you can draw each in the size of 100x100 pixels or more.
It's up to you.

Finn Tolderlund

Re:3 Questions


Hi.

Quote
>1) If i want a form's canvas to redraw itself after an application has been
>maximised, should i use the applications OnMaximise event
>(I currently use the OnPaint event, but this also seems to be called  when
>an application is started, which i'd like to avoid) if this is the case how
>should i access the OnMaximise event?

Write a redraw proc and call it in OnMaximize and don't call it in OnPaint
or I misunderstood you.

Quote
>2) I'd like to experiment with cellular automata but don't know the best
way
>of representing a 2d grid environment visually (DrawGrid ?), ideally it
>should be able to have differing cell colours and be able to access values
>stored in a 2d array (with wrap-around), or have some way of achieving a
>similar result.

When I implemented Conway's Life I found out that it's much easier to write
your own component. There are several more reasons than just absence of
suitable components with needed and only needed functionality. Under certain
rules you'll have to examine very distributed or sparce (do not know the
right word) universes. In these cases storing them in 2d array is a very
very bad idea, so it's better to write a good component with needed
universe-storing routines.

Bye.
/lexi

Re:3 Questions


There are three sorts of people in the world, those who can count and those
who can't.

Quote
>Alan Lloyd

hahahahah.....
I couldn't stop laughing for 5 minutes...
I may say this - U R Genius (...not the mouse).

if U made this up...  I think that U should be elected president...

U have mu VOTE...
Popov Igor
-----------
i...@vkjetnet.co.yu
http://www.vkjetnet.co.yu/~igyp
-----------
OTPOR! do pobede

Re:3 Questions


Quote
>You could create a 2-dim, array:
>var
>  Cellular: array [0..99, 0..99] of Integer;

>and you could use a TImage to draw/display it.

don't do that.. U should use dynamic alocation as often as possible.
make your own component.

TCell = class (...)
    Image: TImage;
    Alive: boolean;
    ...
end;

TLifeTable = class (...)
private
    FCells: TList;
    FWidth:: integer;
    FHeight: integer;
    function GetCell (IndexX, IndexY: integer): TCell;
    procedure SetCell (IndexX, IndexY: integer; CellUnit: TCell);
    ...
public
    ...
    property Cell [IndexX, IndexY: integer]: TCell read GetCell write
SetCell default;
    property Height: integer read FHeight write FHeight;
    property Width: integer read FWidth write FWidth;
    ...
end;

function TLifeTable.GetCell (IndexX, IndexY: integer): TCell;
begin
    try
        Result := TList [IndexY * Width + IndexX]
    except
        Result := nil;
end;

procedure TLifeTable.SetCell (IndexX, IndexY: integer; CellUnit: TCell);
begin
    try
        TList [IndexY * Width + IndexX] := CellUnit;
    except
        ... {out of range} ...
end;

...

I hope that this will help U.

Popov Igor
-----------
i...@vkjetnet.co.yu
http://www.vkjetnet.co.yu/~igyp
-----------
OTPOR! do pobede

Other Threads