Results 1 to 5 of 5

Thread: [RESOLVED] Drawing Checkerboard or matrix with offset squares

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    421

    Resolved [RESOLVED] Drawing Checkerboard or matrix with offset squares

    Heed help

    I can make regular checkerboard or matrix with crisscrossing intersections but I don't know how to make one with offset squares. The picture included shows a regular board on the left and a board with offset squares on the right.

    I need to be able to have different size matrix like 6x6, 6x7, 5x9, 4x6, 8x8, etc and any size squares

    Can anyone help me. Thank you.
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,036

    Re: Drawing Checkerboard or matrix with offset squares

    Not much to the basics, but needs a little tweaking if you want the cells all square:

    Name:  sshot1.png
Views: 115
Size:  1.6 KB

    Name:  sshot2.png
Views: 109
Size:  1.6 KB


    Not much to it. What did I miss?
    Attached Files Attached Files

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    421

    Re: Drawing Checkerboard or matrix with offset squares

    Very nice, dilettante, thank you

    Now I have another problem. I'm working on a game where the sides of the squares can be removed or put back depending on how the game progresses. I think this means that the lines need to be made of line controls so I have control over each and every line. Also, the lines need to be alternate colors of blue and red. The size of the box that these lines are in are determined by the size and number of squares. The attached picture shows what I am talking about. Note the missing lines. This is done by the program when certain events take place in the course of the game.
    Attached Images Attached Images  
    Last edited by Ordinary Guy; Sep 22nd, 2019 at 04:23 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    421

    Re: Drawing Checkerboard or matrix with offset squares

    Here's a code I put together to illustrate what I'm trying to do. It works but I think it's somewhat complicated and it's fixed (hard coded) so that it will only allow one size. This code only does the vertical blue/red lines using line controls.

    Code:
    Private Sub cmdDrawVertOffsetLines_Click()
     Dim n As Integer, n0 As Integer, n1 As Integer, n2 As Integer
     Dim k As Integer
     Dim BlueVLines As Integer
     Dim RedVLines As Integer
      
     Rows = CInt(Text1.Text)
     Cols = CInt(Text2.Text)
    
     Picture1.Picture = Nothing
     Picture1.AutoSize = False
     
     n1 = 0
     
     Picture1.Width = Cols * 69 + 1
     Picture1.Height = Rows * 69 + 1
      
     For k = 0 To Rows \ 2 - 1
       '
       ' Draw vertical lines 1st, 3rd, and 5th  row
       '
       n0 = 0
       n2 = 0
       n1 = n1 + 1
    
       For n = 0 To Picture1.Width Step 70
         BlueVLines = BlueVLines + 1
         
         Load BlueVertLine(BlueVLines): BlueVertLine(BlueVLines).Visible = True
         BlueVertLine(BlueVLines).X1 = n2: BlueVertLine(BlueVLines).x2 = n2
         BlueVertLine(BlueVLines).Y1 = (n1 - 1) * 69: BlueVertLine(BlueVLines).y2 = n1 * 69
         
         If n0 Mod 2 = 0 Then
           n2 = n2 + 68
         Else
           n2 = n2 + 70
         End If
         n0 = n0 + 1
       Next n
    
       '
       ' Draw vertical lines 2nd, 4th, and 6th row
       '
       n0 = 0
       n2 = 69
       n1 = n1 + 1
     
       For n = 0 To Picture1.Width Step 70
         RedVLines = RedVLines + 1
         
         Load RedVertLine(RedVLines): RedVertLine(RedVLines).Visible = True
         RedVertLine(RedVLines).X1 = n2: RedVertLine(RedVLines).x2 = n2
         RedVertLine(RedVLines).Y1 = (n1 - 1) * 69: RedVertLine(RedVLines).y2 = n1 * 69
         
         If n0 Mod 2 = 0 Then
           n2 = n2 + 68
         Else
           n2 = n2 + 70
         End If
       
         n0 = n0 + 1
       Next n
     Next k
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    421

    Re: Drawing Checkerboard or matrix with offset squares

    OK, I got it to work for all sizes both vertical and horizontal lines

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