Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Infinite Line

edited August 2014 in General Posts: 145

I've been designing an infinite line scrolling down a screen. However, there are 2 problems. First, the intersections are don't look like exact intersections. Secondly, the line flickers occasionally. Could someone help improve this?

Here is the code:

  -- Use this function to perform your initial setup
  function setup()
  print("Hello World!")
  linex={}
  liney={}

   xcounter = 0
   ycounter = 0
   linex[1] = math.random(WIDTH/10,WIDTH/1.1)
   liney[1] = ycounter

   for i=2,6 do
        x = math.random(WIDTH/10,WIDTH/1.1)
        y = math.random(HEIGHT/5,HEIGHT/4)
        ycounter = ycounter + y  
        linex[i] = x
        liney[i] = ycounter
  end
end

-- This function gets called once every frame
function draw()

    strokeWidth(10)
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness


    -- Do your drawing here

    for i = 1,5 do
         line(linex[i],liney[i],linex[i+1],liney[i+1])        

         if(liney[2]<0)then

            table.remove(liney,1)
            table.remove(linex,1)

            x = math.random(WIDTH/10,WIDTH/1.1)
            y = math.random(HEIGHT/5,HEIGHT/4)

            linex[6] = x
            liney[6] = y+HEIGHT   
      end


     for i=1,5 do

           liney[i] = liney[i] -3
    end


end




   end
Tagged:

Comments

  • IgnatzIgnatz Mod
    edited August 2014 Posts: 5,396

    @austinmccoy - this change to your line code should fix the joins

    line(linex[i],liney[i]+2,linex[i+1],liney[i+1]-2) 
    

    I don't see the flickering - the lines sometimes look a little shimmery, but I think that is just the effect of the anti-aliasing that blends the white line into the dark background

  • What could I do to reduce the shimmering? Even a light background doesn't reduce the shimmering that much.

  • IgnatzIgnatz Mod
    Posts: 5,396

    When you pause the program, the lines look sharp, so I think it is the anti-aliasing at work (and you can't turn it off).

    I would play around with colour combinations to see if you can reduce it. It is just a visual effect.

  • Okay, thanks!

  • IgnatzIgnatz Mod
    Posts: 5,396

    Also try playing with the drawing settings, like smoothing. Others know more about that than I do.

  • Smoothing doesn't seem to help. However, additive blending reduces the frequency of the shimmering.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @austinmccoy - ah, good work =D>

Sign In or Register to comment.