Solved

Help me solve a Spiral programming dilemma!

Posted on 1998-01-31
1
146 Views
Last Modified: 2010-04-04
I have a small program to write. But when I said that I would do it, it seemed a lot simplier that it does now.

I have to make a program that displays something which I can only label as an "Hypnotic disc"-like spiral. You know, the kind of 2 colors spirals that start on a single point in the center and expand, and when you rotate it, it seem to "go-in" or "go-out" (depending if you rotate it clockwise or counter-clockwise)

Now, using delphi I really don't know how to do it! It must be full screen, have 2 spirals, one red, and one blue. the background must be black.

and the hard part is that it must rotate!! can anyone help? should I use DirectX? is there a way to switch to a 320x200 screen mode from within delphi??

i'm really at a loss. Thanks for ANY help!

(and if such a small program exists, please point me in that direction!!)
0
Comment
Question by:efortier
1 Comment
 
LVL 5

Accepted Solution

by:
ronit051397 earned 60 total points
ID: 1358074
This source from Lloyd's help file creates two spirals in a metafile file. You can then load the metafile and see what it does. This code was tested on Delphi 1. Hope it will help.



CONST W = 1000; H = 500; R2 = 353;

procedure TForm1.Button1Click(Sender: TObject);

VAR CDC : hDC;

  procedure spiral(CV: TCanvas; Colr: TColor; AngInc: Double;
    RInc: Integer; Sgn1, Sgn2: Integer);
  VAR Theta: Double;
  begin
    Sgn1 := Sgn1 DIV Abs(Sgn1);
    Sgn2 := Sgn2 DIV Abs(Sgn2);
    CV.pen.Color := Colr;
    Theta := 0;
    CV.MoveTo(H,H);
    WHILE Theta < pred(H DIV RInc) DO
      BEGIN
        Theta := Theta + AngInc;
        CV.LineTo(H+Sgn1*Round(RInc*Theta*Cos(Sgn2*Theta)),
                  H+Sgn1*Round(RInc*Theta*Sin(Sgn2*Theta)));
      END;
  end;

begin
  DeleteFile('EXAMPLE.WMF');
  WITH TBitmap.Create DO
    try
      CDC := CreateMetafile(NIL);
      Canvas.Handle := CDC;
      SetMapMode(Canvas.Handle, MM_ANISOTROPIC);
      SetWindowExt(Canvas.Handle, W, W);
      WITH Canvas DO
        BEGIN
          {==== replace with your own image-creation code ===}
          Brush.Color := clWhite;
          pen.Width := 10;
          pen.Style := psInsideFrame;
          pen.Color := clBlack;
          Ellipse(0,0,W,W);
          Spiral(Canvas, clRed, pi/4, 18, 1, 1);
          Spiral(Canvas, clBlue, pi/4, 18, -1, 1);

          Pen.Color := clBlack;
          PolyLine([Point(H,0), Point(H,H), Point(H-R2, H+R2),
            Point(H,H), Point(H,W), Point(H,H),
            Point(H+R2,H+R2)]);
          {====== end image-creation code =====}
        END;
      WITH TMetafile.Create DO
        try
          Handle := CloseMetafile(CDC);
          Inch   := W;
          Height := 128;
          Width  := 128;
          SaveToFile('EXAMPLE.WMF');
        finally
          Free;
        end;
    finally

      Free;
    end;
end;

{ This code came from Lloyd's help file! }
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now