Results 1 to 4 of 4

Thread: (vb6) - Concentric square in picturebox minimum/maximum and opposite

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2021
    Posts
    79

    (vb6) - Concentric square in picturebox minimum/maximum and opposite

    I have on the form
    1 timer
    1 picture1

    Through this code I produce concentric squares from the center of the picture to the maximum of the picture. And it works well.

    Code:
    Dim increase As Integer  
    Dim ratio As Single  
    Dim X As Integer  
    Dim Y As Integer  
      
    Private Sub Form_Load()  
    Picture1.ScaleMode = 3  
    ratio = Picture1.ScaleHeight / Picture1.ScaleWidth  
    X = Picture1.ScaleWidth / 2  
    Y = Picture1.ScaleHeight / 2  
    increase = 0  
    Timer1.Interval = 50  
    End Sub  
      
    Private Sub Timer1_Timer()  
    increase = increase + 10  
    Picture1.Line (X - (increase), Y - (increase * ratio))-(X + (increase), Y + (increase * ratio)), vbRed, B  
    If X - increase < 0 Then  
    Picture1.Cls  ' here the cycle starts again
    X = Picture1.ScaleWidth / 2  
    Y = Picture1.ScaleHeight / 2  
    increase = 0  
    End If  
    End Sub
    I would like to get the opposite now: that is, once the squares have reached the maximum they must do the opposite, from the outside to the central point of the picture. And continue from the inside to the maximum and from the maximum to the center. I tried with

    Code:
    increase = increase - 10
    and maybe add a timer but it doesn't work. Where to modify to succeed in my intent?
    Thanks

  2. #2
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: (vb6) - Concentric square in picturebox minimum/maximum and opposite

    Use INC as Increment amount
    Code:
    Dim increase      As Integer
    Dim ratio         As Single
    Dim X             As Integer
    Dim Y             As Integer
    Dim INC           As Integer
    
    Private Sub Form_Load()
        INC = 10
        Picture1.ScaleMode = 3
        ratio = Picture1.ScaleHeight / Picture1.ScaleWidth
        X = Picture1.ScaleWidth / 2
        Y = Picture1.ScaleHeight / 2
        increase = 0
        Timer1.Interval = 50
    End Sub
    
    Private Sub Timer1_Timer()
        increase = increase + INC
        Picture1.Line (X - (increase), Y - (increase * ratio))-(X + (increase), Y + (increase * ratio)), vbRed, B
        If X - increase < 0 Or X - increase > Picture1.ScaleWidth / 2 Then
            INC = -INC         ' Invert direction
            Picture1.Cls       ' here the cycle starts again
        End If
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2021
    Posts
    79

    Re: (vb6) - Concentric square in picturebox minimum/maximum and opposite

    Reexre,
    i immediately tested the tip. And... excellent and quick solution !
    Now I integrate the routine into the program and the problem
    is already solved at the first shot. Thank you.
    Really fantastic this approach.
    Thanks.

  4. #4
    Lively Member
    Join Date
    Mar 2015
    Posts
    104

    Re: (vb6) - Concentric square in picturebox minimum/maximum and opposite

    Made a concentric Rectangle Program with mouse drag operation.

    You can adjust the line width, gap size and change colour.

    Name:  concentricrect2.png
Views: 84
Size:  40.2 KB

    Its over here on GitHub: https://github.com/BoleeMan/Concentric-Rectangles

    Click Code and then Download Zip

    Enjoy.
    Last edited by CreativeDreamer; Jan 14th, 2022 at 11:04 PM.

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