Results 1 to 9 of 9

Thread: Disco Background Fader

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Disco Background Fader

    VB Code:
    1. Option Explicit
    2.  
    3. Dim r As Byte, g As Byte, b As Byte, d(3) As Byte, flag As Byte
    4.  
    5. Private Sub Form_Load()
    6.     Randomize
    7.     r = 255: g = 255: b = 255: flag = 0
    8.  
    9. End Sub
    10.  
    11. Function Ran(ByVal a As Byte, ByVal c As Byte)
    12.    
    13.     If ((Rnd > 0.667 Or c = 0) And c < 255) Then
    14.         c = c + 1
    15.         d(a) = 2
    16.     ElseIf ((Rnd <= 0.5 Or c = 255) And c > 0) Then
    17.         c = c - 1
    18.         d(a) = 1
    19.     Else
    20.         d(a) = 0
    21.     End If
    22.  
    23.     Ran = c
    24.    
    25. End Function
    26.  
    27. Function DoIt(ByVal a As Byte, ByVal c As Byte)
    28.     If ((d(a) = 2 And c < 255) Or c = 0) Then
    29.         c = c + 1
    30.         d(a) = 2
    31.     Else
    32.         If ((d(a) = 1 And c) Or c = 255) Then
    33.             c = c - 1
    34.             d(a) = 1
    35.         End If
    36.        
    37.         If a = 3 Then
    38.             If (d(1) + d(2) + d(3) = 0) Then flag = 1
    39.         End If
    40.     End If
    41.  
    42.     DoIt = c
    43.  
    44. End Function
    45.  
    46. Function Disco()
    47.  
    48.     If flag Then
    49.         r = DoIt(1, r)
    50.         g = DoIt(2, g)
    51.         b = DoIt(3, b)
    52.         flag = flag - 1
    53.     Else
    54.         r = Ran(1, r)
    55.         g = Ran(2, g)
    56.         b = Ran(3, b)
    57.         flag = 50
    58.     End If
    59.    
    60.     Me.BackColor = RGB(r, g, b)
    61.  
    62. End Function
    63.  
    64. Private Sub Timer1_Timer()
    65. Disco
    66. End Sub

    NOTE: This was converted from HTML, i think the link to its HTML source was www.wsabstract.com

  2. #2

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Trouble with this is that Labels flicker like mad, even if AutoRedraw is set to True. Anybody know how to stop labels flickering?

    Dont say dont use them neither!

  3. #3
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    Someplace 'ore the rainbow
    Posts
    392
    try locking the form (LockWindow API I think), then update it, then unlock.

    cjqp
    When your answer is the Arc Sin of 1.015, you should check your Pythagorean triple.

  4. #4

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Too much hassle, just as easy to use locked Textboxes - which dont flicker

  5. #5
    Member
    Join Date
    Mar 2004
    Location
    INDIA
    Posts
    36

    DISCO BACKGROUND FADER

    HI

    COULD U PLEASE GUIDE HOW TO USE THE PROG. I ADDED A TIMER BUT ...........


    ONIL

    ALSO AT
    [email protected]
    [email protected]

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Did you set an interval for the Timer? 10 ms will do it.


    Has someone helped you? Then you can Rate their helpful post.

  7. #7
    Member
    Join Date
    Mar 2004
    Location
    INDIA
    Posts
    36

    VALUE OF A AND C

    THANKS WITH INTERVAL AS 10 ms IT WORKS. ANOTHER QUERY

    IN BOTH THE FUNCTIONS Ran AND DoIt HOW DOES, IN THE STARTING a GETS A VALUE 1 AND C = 255?

    PLEASE BEAR WITH MY DOUBTS AND HELP

    ONIL

  8. #8

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Disco Background Fader

    The interval may need changing on the timer, try changing it to 255 - i cant remember the actual value

  9. #9

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Quit convert to delphi...was bored

    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
      R,G,B: Byte; //Dim r As Byte, g As Byte, b As Byte
      D,Flag: Byte; //Dim d(3) As Byte, flag As Byte
    
    implementation
    
    {$R *.dfm}
    
    //Function Ran(ByVal a As Byte, ByVal c As Byte)
    function Ran(A: Byte; C:Byte): Byte;
    begin
      //If ((Rnd > 0.667 Or c = 0) And c < 255) Then
      if (Random >0.667) or (C = 0) and (C <255) then
      begin
        //c = c + 1
        C:= C + 1;
        //d(a) = 2
        A:= 2;
        D:= (A);
      end
      else
      if (Random <=0.5) or (C = 255) and (C >0) then
      begin
        //c = c - 1
        C:= C -1;
        //d(a) = 1
        A:= 1;
        D:= (A);
      end
      else
      begin
        //d(a) = 0
        A:= 0;
        D:= (A);
      end;
      //Ran = c
      Ran:= C;
    end;
    //End Function
    
    //Function DoIt(ByVal a As Byte, ByVal c As Byte)
    function DoIt(A: Byte; C: Byte): Byte;
    begin
      //If ((d(a) = 2 And c < 255) Or c = 0) Then
      if (D + A = 2) and (C <255) or (C = 0) then
      begin
        //c = c + 1
        C:= C + 1;
        //d(a) = 2
        A:= 2;
        D:= A;
      end
      else
      //If ((d(a) = 1 And c) Or c = 255) Then
      if (D + A = 1 + C) or (C = 255) then
      begin
        //c = c - 1
        C:= C -1;
        //d(a) = 1
        A:= 1;
        D:= A;
        //If a = 3 Then
        if A = 3 then
        begin
          //If (d(1) + d(2) + d(3) = 0) Then flag = 1
          if (D + 1) + (D + 2) + (D + 3) = 0 then Flag:= 1;
        end;
      end;
      //DoIt = c
      DoIt:= C;
    end;
    //End Function
    
    //Function Disco()
    function Disco: Integer;
    begin
      //If Flag Then
      if Flag = -1 then
      begin
        R:= DoIt(1, R); //r = DoIt(1, r)
        G:= DoIt(2, G); //g = DoIt(2, g)
        B:= DoIt(1, B); //b = DoIt(3, b)
        Flag:= Flag -1; //flag = flag - 1
      end
      else
      if Flag = 50 then
      begin
        R:= Ran(1, R); //r = Ran(1, r)
        G:= Ran(2, G); //g = Ran(2, g)
        B:= Ran(3, B); //b = Ran(3, b)
        Flag:= Flag + 50; //flag = 50
      end;
      //Me.BackColor = RGB(r, g, b)
      Form1.Color:= RGB(R,G,B);
    end;
    
    //Private Sub Form_Load()
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Enabled:= True;
      Timer1.Interval:= 10;
    
      //Randomize;
      Randomize;
      R:= 255; //r = 255
      G:= 255; //g = 255
      B:= 255; //b = 255
      Flag:= 0; //flag = 0
    end;
    
    //Private Sub Timer1_Timer()
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      //Disco
      Disco;
    end;
    //End Sub
    
    end.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width