Create a zig zag effect in array

I have a one dimensional array that holds the pixels values for the image. I currently go through it like so:
for (int y = 0; y < height-1; y++) {
     offset =y*width;
     for (int x=0; x < width-1; x++) {
          pos = offset + x;
          oldPixel = pixels[pos];
...What I now want to do is instead of going in a constant left to right motion is to go in a zig zag motion. This means I want to go left to right on the first line then the second line is from right to left and then back to left to right again for the next line.
Any ideas on what would be the best way to do this?
Thanks.

4fingers wrote:
Any ideas on what would be the best way to do this?Are you sure about the limits? It usually looks like this,
for (int y=0; y<height; y++) {
The above will loop height times.
Anyway you can introduce a boolean variable called say leftToRight which is controlling the scanning direction,
boolean leftToRight = true;
for (int y = 0; y < height; y++) {
   offset =y*width;
   if (leftToRight) { // from left to right
      for (int x=0; x < width; x++) {
         pos = offset + x;
         oldPixel = pixels[pos];
   } else { // from right to left
      for (int x=width-1; x >= 0; x--) {
         pos = offset + x;
         oldPixel = pixels[pos];
   leftToRight = !leftToRight; // change direction

Similar Messages

  • Zig zag effect for shading

    Hi there,
    I'm wondering what tools I can use to create this zig-zag effect used for shading in illustrator. Thanks in advance!

    There's no effect to generate that. But you could use brushes to draw those triangle-shaped lines. You could even draw more than one at a time. Or you could use blends.
    THis only one example. You could use art brushes for other forms of strokes:

  • Extraneous line appears when using Zig Zag effect

    This is the procedure that I'm using:
    1. Create 3 horizontal lines with only a stroke color, no fill. Each line is a different stroke color.
    2. Using the Blend tool, blend the three lines to get a nice linear gradient.
    3. Make an Art Brush from the 3-line blend.
    4. Create a path, for example, just a straight line, and apply the new brush.
    5. Choose Effects > Distort > Zig Zag with Smooth turned on. If the zig zag is shallow and diagonal line appears in the path that does not belong, ruining the effect. The extraneous line will print, so it's not just something that appears on the screen.
    Is there any way to avoid this? If the bumps in the wave are steeper, the diagonal line doesn't appear.

    Hello Jay,
    <br />
    <br />What I did is to use really small circles (3 Circles: Red, Yellow, and Blue) Blend them together with specified steps of 100 (Option+Blend Tool+Click). The amount of steps depends of the distance between each circle.
    <br />
    <br />Then I created the "Art Brush" and apply it to a straight line.
    <br />
    <br />After that, I rotated a copy of the line 45° and a third line another 45° (this will make 90° with 3 lines).
    <br />
    <br />Selected the Vertical and Horizontal lines, then select the "Zig Zag" effect and set the values that you want. The diagonal line I reset the size of the "Zig Zag" effect to very low value.
    <br />
    <br />After that I use "Convert Anchor Point Tool" (Shift+C) to smooth the curve of the blending. To have better results I suggest to use more than 3 lines to make a 90° turn (Just keep in mind that the middle lines should have a "Zig Zag" effect size of low value.
    <br />
    <br />
    <a href="http://www.pixentral.com/show.php?picture=1fm7KrGLb3VxTRWESwjMVlnShprH" /></a>
    <img alt="Picture hosted by Pixentral" src="http://www.pixentral.com/hosted/1fm7KrGLb3VxTRWESwjMVlnShprH_thumb.jpg" border="0" />
    <br />
    <br />But another solution is to first make the Mask of the shape that you want, create a Rectangle with the gradient that you want and use the "Envelope Distorted" ("Envelope Distorted"+ "Make With Warp" + Style "Arc"). Please make sure that you already selected "Distort Linear Gradients" under "Envelope Options"
    <br />And then make the mask.
    <br />
    <br />
    <a href="http://www.pixentral.com/show.php?picture=1vG69C4xb8gausk6fxfmkMOE4ggtzB" /></a>
    <img alt="Picture hosted by Pixentral" src="http://www.pixentral.com/hosted/1vG69C4xb8gausk6fxfmkMOE4ggtzB_thumb.jpg" border="0" />
    <br />
    <br />
    <a href="http://www.pixentral.com/show.php?picture=1IUevEolmMjG7JkjMAKgf2N4zlb0" /></a>
    <img alt="Picture hosted by Pixentral" src="http://www.pixentral.com/hosted/1IUevEolmMjG7JkjMAKgf2N4zlb0_thumb.jpg" border="0" />
    <br />
    <br />I hope this helps!

  • Zig Zag Effect - How is a segment calculated on a circle?

    I have a perfect circle, to which I have applied the Zig Zag effect. I have specified 2 ridges per segment. If I am correct in assuming that a "ridge" is the high, outer part, I end up with 6 ridges on my circle. If I specify 10 redges per segment, I get 22.
    So what does Illustrator consider a segment on a circle, and other than trial and error, how can I get a desired number of ridges?

    Ridges Per Segment means Points Per Segment. Expand Appearance and then count the points.
    Then try it again, but set the Size slider to zero.
    In both cases, you'll have 12 points; the original four and eight added (two per segment).
    You have six "star points" because there is an anchorPoint at each trough and each crest; 6 pairs of trough and crest makes six waves.
    JET

  • Symmetry Question, Zig-Zag Effect

    I'm working with the Zig-Zag effect and have noticed an anomaly, or not the result I expected. The effect seems to be symmetrical except on one area of the underlying path at one anchor point. Relative and Absolute both yield a non-symmetrical result. Is there a way to get complete symmetry with this effect? I'm working on some snowflakes to import into After Effects and would like for them to be symmetrical.
    Any help is much appreciated. Thanks, Bob

    There are a lot of unobservant designers out there.
    This one came from Wiki:

  • Distort/Zig-Zag Effect

    I'm wondering if there are any effects that would distort or zig-zag the last frame of a shot for a "passage of time" emulation. Or, is this something I'd have to do in Motion or After Effects?
    Or, could someone recommend other good effects to emulate the passage of time?

    In FCP, there is a ripple filter. You need to key the effect, in effect, making a transition. TO do this extend the length of video by about 30 or 45 frames (or what ever you need) and then with the blade tool, cut it. add the Ripple filter.. Key it, and add the cross dissolve transition over it.. Take your incoming video and place it on a track below.... you can also try cutting a piece there and add the ripple effect, and see what effects result. Hope this makes sense.

  • How do I create a pond ripple effect?

    Hey guys, I'm designing a wrap for a hummer. My client wants it to look like the hummer has a force field and show a few bullets hitting the truck and causing a ripple. I googled this and found out that the "zig zag" filter under "distort" does this. Only problem is, this option is greyed out on my comp. It could be that my project file is half a gigabite (required for the size of printing on the truck). Could someone please help me figure out how to use this option or even suggest another program I can use to do this? I can't think of any other way.
    This is the design I want the effect on
    This is the effect I want.

    Hi again.
    Let's start at the beginning. Perspective. Shock waves propogate in concentric circles from the point of impact. Viewed at a 90 degree angle to the plane being struck, the shock waves will appear exactly as that, concentric circles, not ellipses. The side of the Hummer is vertical, so the viewing angle of a typical observer will be about 90 degrees. Creating concentic ellipses will make it appear as though the shockwaves are out of plane with the side of the Hummer.
    My first post was a demonstration of principle. How to create the basic skeleton. What happens next depends on what you think the shock wave should look like. I wouldn't think it would look exactly like a high energy impact on a force field. A drop falling into a pond is not exactly high energy. They will both have concentric rings, but the distribution and profile of the waves would be different, I would expect. A physicist could properly inform us.
    Anyway, I repeated a slight variation on the process on a 732mb file. As you note, the Zig Zag filter was not available. I didn't spend time perfecting the wave frequency and such.
    1. Make a circular selection where you want the shockwave. (Make it elliptical if you're still not convinced about that.)
    2. Copy the selection to a new layer. Ctrl+J is the easiest way.
    3. Ctrl+Click on the layer thumb to create a transparency selection.
    4. Convert the selection into a Layer Mask. Layer>Layer Mask>Reveal Selection.
    5. Select the Mask thumb. Ctrl+Click on the Mask thumb. You should get a circular selection.
    6. Apply the gradient (radial) to the selection from the center. (You're painting the gradient onto the layer mask.) It will look like nothing happened.
    7. Apply Bevel/Emboss to taste. Now you will be able to see the rings. I used the Ring-Double gloss contour to tart it up.
    8. The Ripple effect is available at this file size. I applied it to to taste.
    The number and spacing of the rings is determined by the number and spacing of the alternating 0 and 100 percent transparency pairs on the gradient applied to the mask. It's endlessly adjustable. If you want, you could double down with another layer, as in the tutuorial. The actual appearance of the rings can be modified for days just in the effects pallet. When you add Ripple or other effects to the rings, I would think you could get just about anything you want. Without too much trouble. It all depends on what you think a projectile striking a force field should look like. You can paint on the layer mask to lighten or darken portions.
    But I just had another thought. With the Marqee Tool set to rectangular, select a work area surrounding where you want the shock wave. Copy it to a new layer. Create a new document and paste the new layer into it. Then you should be able to use the Zig Zag effect as in the tutorial. Then paste or drag the layers back into the original document and align to the original work layer. Delete both work layers. I just tried it and it worked for me in my 732mb file. But using the Zig Zag pond ripple seems to offer less flexiblity than the layer mask method. If assigned this task I would use a mask.
    FWIW.
    Lee

  • Zig zag line following a curve

    how do i make a zig zag line follow a curve and have the 'teeth' be evenly spaced/sized?

    ok, i think i got it nailed..heres how it works for me.
    1.draw the free form line.
    2. apply Roughen Effect, set size at 0, DETAIL value affects the "'teeth' per inch" spacing, POINTS set at-smooth
    3. apply Zig Zag Effect, SIZE affects 'depth/height of 'teeth'", check 'absolute', RIDGES PER SEGMENT-set at 0, POINTS--is checked corner because i need a sharp edge 'tooth'
    thats it..Very cool, thanks to all who answered, this is something i have always been trying to figure out, and now i have an answer..Great resource, i will recommend to my colleagues too!

  • I would like to create a wavy line (the zig zag feature is not exactly what I need here) to outline

    I would like to create a wavy line (the zig zag feature is not exactly what I need here) to outline a shape and then fill it with a solid color. Any ideas?
    This is approx what I want; however the undulation needs to be more round and less peaked

    Barbara,
    If you wish to create a gap between the wavy line and the underlying object, you may:
    1) Select the wavy line and Object>Expand Appearance;
    2) In the Appearance palette flyout tick New Stroke, drag it beneath the original stroke and increase the Stroke Weight as desired and change the colour to white.
    If you wish to make the gap transparent, you may:
    3) Select the wavy line and Object>Expand Appearance and Ungroup;
    4) Select the white path and the underlying object and in the Transparency palette flyout tick Make Opacity Mask with Clip unticked and Invert Mask ticked.
    It may be done in other ways, too.

  • Zig Zag Filter Issues

    I am  using Illustrator CS4 on a Macbook Pro with Mountain Lion...on to the issue.
    The first time I used the zig zag filter today I got exactly the effect I wanted:
    Then when edited it to to take it from 15 ridges to 14, this is what happened:
    I didn't change anything but the number of ridges per segement. 
    Subsequently I tried opening a new document (as well as restarting Illustrator) and creating a totally new line and applying the zig zag filter and got the same weird result again.  I compared my appearance panel settings and everything is the same except the appearance of the thumbnail.  I know this must be something easy that I'm overlooking but for the life of me I can't figure out what it is!

    Your path has a fill. You went from an odd number of points making the start and end at the top of the zig zag, to an evwn number of points making the start at the top and the end at the bottom. Illustrator is simply auto-filling an open path.

  • A zig zag box

    hi all
    how do i create a box with on edge zig zagged like the one in this website
    http://www.danielmoir.com/
    any insight would be grateful

    Illustrator - 4 paths. Apply Effect > Distort & Transform > Zig Zag to bottom path. Join path corners. Copy... Paste into Photoshop as Shape layer.

  • Straight lines become zig-zag when viewed in Premiere Elements 11

    I am sure there's an easy answer to my problem but I can't seem to locate it. I am new to video editing and Premiere Elements 11. I have a Sony HDR-CX200 that I use specifically to record tennis matches. I have a recorded a tennis match in 1080i at 60i fps that was transferred from the camcorder to my Window 7 computer using Sony's PlayMemories software which creates a .m2ts file. When I viewed the .m2ts video in both PlayMemories and Windows Media Player the video looked great. I want to be able to view the video in HD on both computer monitor and tv.
    I imported the .m2ts file into Premiere Elements 11 using drag and drop.The file appeared to impotrt without any issue and the still pic looked good. However, when I pressed play the pic broke up. You can easily see this in the tennis lines which start out straight but when played they break into a zig-zag look. I have attached a short video that shows this problem. I want to be able to edit my tennis videos in Premiere because I've already just paid for it and it's suppose to be one of the best video editing programs out there.
    I have looked over discussions of interlacing but don't understand why the pic only looks bad when played in Premiere Elements and looks good in Windows Media  Player and Sony's PlayMemories. I wonder if there is some setting I am overlooking.
    Any help would be greatly appreciated.

    So far, this is a guess.
    Viewing and playback of a video is a medium difficulty task for a computer.  Taking the same file into an editing situation is a high difficulty task.  Editing AVCHD video, is an extra high difficulty task for a computer.  It is doubtful you will work your computer harder doing anything else.
    The real time preview in the monitor during editing can be improved with what is referred to as "real time rendering".  You know when it is necessary when a yellow colored bar shows up above the time line.  When you see it, press Enter and wait a bit. 
    Can you provide more information about the computer and how you got the short video to YouTube?  Also, how did you open the project?  And can you check what the project settings are?  The YouTube looks nothing like what I have uploaded using my two Sony camcorders. 
    I think this is fixable.  Lots of people get great results from PrE11.
    Bill

  • Peaks and valleys detection of a zig-zag shape waveform

    Hi,
    I have 2 waveforms coming in and I would like to detect the peaks and valleys(with the location, or ) and write them to a spreadsheet file. 
    In a pattern like this
    peak #1(waveform 1)            peak #1(waveform 2)                  Location of peak#1(waveform 1)              Location of peak #1(waveform 2)   
    valley #1(waveform 1)           valley #1(waveform 2)                Location of valley#1(waveform 1)             Locationo of valley#1(waveform 2)
    peak #2(waveform 1)            peak #2(waveform 2)                  Location of peak#2(waveform 1)              Location of peak #2(waveform 2)
    valley #2(waveform 1)           valley#2(waveform 2)                  Location of valley#2(waveform 1)            Location of valley #2(waveform 2)
      The waveforms come in with varing heights, kind of like a wiggling zig zag shape.  Sometimes the peaks/valleys are very smooth and kind of hard to differentiate from the others. 
    Thanks.

    If you search the forums for peak detect, you will find a number of hits.  Also, here is a recent thread discussin peak detection without setting a pulse width.
    Basically, you want to use the peak detection.vi located in Signal Processing > Signal Operation.  That will find your peaks and valleys.
    In order to put all of this into Excel/Spreadsheet (do you have / want to use the Excel Toolkit or just the Write to Spreadsheet.vi?), you will need to  feed all of your points into a build array and a shift register and then when you are done aquiring data, feed that into the Write to spreadsheet.vi or to a vi for excel.
    The formating will depend on how you feed the data into your array, ie wave 1, location 1 or wave 1 , wave 2, etc
    Kenny
    Kenny

  • Gradient on a zig-zag shape

    Hello Illustrator experts out there!
    I'm stuck trying to apply a gradient to a zig-zag object that I've created on Illustrator. I want every peak to be black and the gradient should be kind of rounded (but not radial). The center of the shape should show the transition betwen the darker color and the lighter one.
    Please see image attached:
    How do I achieve this using the gradient tool?
    Many thanks in advance and I look forward to your replies!

    I hope this is what you're talking about. In the Gradient panel, first change the direction of the gradient. Then add in 3 other markers to your gradient bar and position them accordingly. (You can type in the exact position where it says Location. If you double click on a marker, you will then see a K (levels of black). Type in the numbers shown in my preview for each marker. I hope this helps.

  • Eden generation utilization doing zig zag movement in range of 2 Gbs

    Hi,
    I'm running an application where the app produces approximately 15 MB of data per second, but the heap memory utilization in CMS Eden space shows zig zag movement ranging from 100 MB to 2.5 GB for a period of 15 seconds or so. In other words, if my app generates data in range of few MBs then how come the young generation space utilization(in Jconsole) can grow in GBs in such a short span of time?
    Any insight will be helpful.
    Thanks,
    Ashish

    801023 wrote:
    Hi,
    I'm running an application where the app produces approximately 15 MB of data per secondHow did you measure/calculate that value?
    , but the heap memory utilization in CMS Eden space shows zig zag movement ranging from 100 MB to 2.5 GB for a period of 15 seconds or so.Which would come down to about 160MB of objects per second. How do you generate the 15MB and what makes you sure that nothing more is generated?
    In other words, if my app generates data in range of few MBs then how come the young generation space utilization(in Jconsole) can grow in GBs in such a short span of time?Creating temporary objects that get garbage collected quickly can lead to this behaviour (and it's precisely what Eden Space is designed to handle).
    Why do you think that's a problem, by the way?

Maybe you are looking for

  • IC WebClient - Text "Problem description" with formular?

    Hello, Did someone already tried to generate/ create/ attach a customer-specific "Text formular" in the IC WebClient (transaction "service ticket")? => There is currently a "Text subscreen" in the ICW service ticket, containing the following Text Typ

  • Best course of action for lost iPhone

    Hi Can any one advise the best security strategy when you loose an iPhone 3GS. I have it password protected and the data on it is of my prime concern. It seems that if II wipe it I can no longer send messages or attempt to locate it. Also if someone

  • No Serializer found to serialize a 'org.w3c.dom.Element' using encoding style ...

    I use oc4j903 and win2k. I write a document style web service following Demo for Stateless Java Document Web Services. I Create an EAR file using WebServicesAssembler and deploy it .and my config.xml: <web-service> <display-name>Stateful Java Documen

  • JRE 1.6 focus issue

    Hi all- We recently installed JRE 1.6.0_12 after being on an old version of JRE 1.4.2 for years. When we did this, we noticed two applications that would normally pop up a child window in front of the parent window suddenly pop up the window behind t

  • Itunes locks up on startup

    Have had itunes 10.5 (the latest and greatest) and it worked fine.  today it has decided to lock up on start up.  No new programs added.  No viruses found.  I tried to do a repair install but have the same problem.  I then removed itunes completely a