LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate Zig Zag Pattern Challenge

Solved!
Go to solution

I have been working on making pattern fills for the picture control. Drawing dots and lines using the picture control funcitons provided can be slow, but writing a boolean array to the pixel values of a picture control is fast, so I've built some patterns using array functions. I found that creating a zigzag pattern was quite a challenge. I've posted my solution and would welcome ideas for improvements to code clarity.

 

The rules are:

 

1. Line thickness is specified

2. Line legnth is specified (this is a somehwhat arbitrary value but is related to the number of horizontal or vertical steps from one peak of the zig zag to the other.

3. The pattern must optionally run vertically or horizontally

4. The pattern must be shiftable in in both x and y directions.

5. Final array size is specified

 

Here is a pattern of thickness 3, line legnth 3, and spacing 3.

 

zigzag.jpg

_____________
Creator of the BundleMagic plugin for LabVIEW!
Message 1 of 9
(3,883 Views)

Kudos just because I think it's an interesting problem. I don't have time to look at it in detail now, but maybe I will later if I remember. The approach that comes to mind for me, which I think might be simpler than what you're doing, is to start by initializing the entire array, then "drawing" horizontal or vertical lines across it of the correct width and offset. Then, loop through each row (column). Rotate each row in order by an increasing amount until you reach the line length, then decrease the rotation until you're back to 0, and repeat. You can do the Y shift by changing the height of the first horizontal line, and an X shift by changing the initial rotation value.

Message 2 of 9
(3,852 Views)

The way you proposed the question I couldn't help but give it a shot:

 

Create_Zig_Zag_Pattern.png

 

The algorithm is to build a tile which repeats itself and then fill the larger array with this tile.  I would divide this into Sub VIs (can swap out the first part if you ever need to generate other repeating patterns) but it's easier to show on the forum as one VI.  I have no idea why I decided to build a tile first rather than rotate the entire large array row by row (or column by column) as nathand suggested other than it would be cool to use this as a more general template for tesselating patterns (for me it seems easier to isolate each repeating section of the pattern).

 

I used the "semi-period" of the line instead of a line length (in your example semi-period would be 4).

 

I used Offset (for the same direction as the line) and Transverse Offset (for an offset perpendicular to the direction of the line), but it would be easy to map X and Y offsets to these values based on the Line Direction.

 

.

Best Regards,

John Passiak
Message 3 of 9
(3,811 Views)

It's an optical illusion.  The light grey lines look like they bend and sway back and forth.

Message 4 of 9
(3,790 Views)

Just for fun, here's an implementation of the approach I suggested. The offset directions (+/-) and origin are different than the original. It also doesn't have some of the bugs of the original. Only 2 For loops versus John's 4, but I think his approach is more elegant and probably more memory-efficient.

ZigZagPattern.png

Message 5 of 9
(3,744 Views)

I would just create a unit cell once (size of one repeat in each direction), then tile it into the final array.

Message 6 of 9
(3,737 Views)

@littlesphaeroid wrote:

... and would welcome ideas for improvements to code clarity.


I think you have bugs. For example look at the result of this input combination.

 

0 Kudos
Message 7 of 9
(3,726 Views)
Solution
Accepted by topic author littlesphaeroid

@altenbach wrote:

I would just create a unit cell once (size of one repeat in each direction), then tile it into the final array.


That's what I implemented here.

 

 

Best Regards,

John Passiak
Message 8 of 9
(3,710 Views)

Thank you guys for your awesome examples! I've really learned a lot. I've got a few other patterns to work out, and the one-cell repeating pattern is a good place to start with many of them. I'll come up with another challenge soon, and I look forward to sharing the results.

 

 

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 9 of 9
(3,673 Views)