Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help me solve a Spiral programming dilemma!

Posted on 1998-01-31
1
Medium Priority
?
171 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 120 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview

876 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