Howdy, Stranger!

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

line-splitting glitch

edited August 2013 in Bugs Posts: 16

Like the title states, I've come across a line-splitting glitch

function draw()
circlegraphed = image(450,450)
setContext(circlegraphed)
background(0,0)
noFill()
strokeWidth(0.1)
stroke(255, 255, 255, 255)


ellipse(300,300,250)
setContext()

if plottedcircle == nil then

     plottedcircle = {}


               for y = 450,1, -1 do
                    for x = 450,1,-1 do
                    r,g,b,ad = circlegraphed:get(x,y)
                    if r ~= 0 then
        plottedcircle[#plottedcircle + 1] = vec2(x,y)
                    end
                    end
                end
        parameter.integer("t",1,#plottedcircle,1)
    print(#plottedcircle,plottedcircle[1])
end


line(300,300,plottedcircle[t].x,plottedcircle[t].y)
end

I don't know how else to describe it. But I know this should not be happening.
The sample code is above. If you want to see for yourself.

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    This is probably not the cause, but you should definitely not be defining a parameter in draw. Do this in setup. You can change the value in draw afterwards, if you want

  • IgnatzIgnatz Mod
    Posts: 5,396

    Same with setContext. Do this in setup (just once), then sprite the image in draw

  • edited August 2013 Posts: 16

    @ignatz I'm still getting the same glitch.
    Code update down below

    function setup()
        print("Hello World!")
        circlegraphed = image(450,450)
    setContext(circlegraphed)
    background(0,0)
    noFill()
    strokeWidth(0.1)
    stroke(255, 255, 255, 255)
    
    
    ellipse(300,300,250)
    setContext()
    
    if plottedcircle == nil then
    
         plottedcircle = {}
    
    
                   for y = 450,1, -1 do
                        for x = 450,1,-1 do
                        r,g,b,ad = circlegraphed:get(x,y)
                        if r ~= 0 then
            plottedcircle[#plottedcircle + 1] = vec2(x,y)
                        end
                        end
                    end
            parameter.integer("t",1,#plottedcircle,1)
        print(#plottedcircle,plottedcircle[1])
    end
    
    end
    
    function draw()
    background(0, 40, 50)
    strokeWidth(5)
    line(300,300,plottedcircle[t].x,plottedcircle[t].y)
    end
    
  • IgnatzIgnatz Mod
    edited August 2013 Posts: 5,396

    Try this. Nearly all the code can go in setup. And if you draw a line 0.1 pixels wide, at an angle, of course it will have gaps. I have made it 1 pixel wide.

    function setup()
        circlegraphed = image(450,450)
        setContext(circlegraphed)
        noFill()
        strokeWidth(1)
        stroke(255, 255, 255, 255)   
        ellipse(300,300,250)
        setContext()
        parameter.integer("t",1,99,0)
        if plottedcircle == nil then plottedcircle = {} end
        for y = 450,1, -1 do
            for x = 450,1,-1 do
                r,g,b,ad = circlegraphed:get(x,y)
                if r ~= 0 then
                    plottedcircle[#plottedcircle + 1] = vec2(x,y)
                end
            end
        end
        t=#plottedcircle
    end   
    
    function draw()
        background(0)
        line(300,300,plottedcircle[t].x,plottedcircle[t].y)
    end
    
  • edited August 2013 Posts: 16

    @Ignatz I know you meant well but what I neglected to post is that when I first found said glitch I started with a strokewidth of 1 the reason I reduced the width size was because of the glitch that resulted.

    On a side note now the lines resetting itself as I change its parameter value. Its still essentially splitting itself just in a more limited quantity.

    The 99 in your in your parameter alteration? Is the highest it can go since its set as its maximum.

    If you really want to allow the full range of values you need the total number of indices set up with in your parameter as its maximum and you want to grab that before you establish your parameters.

  • IgnatzIgnatz Mod
    Posts: 5,396

    What exactly is the problem, then?

    "Line splitting" doesn't make it very clear to me.

  • edited August 2013 Posts: 16

    @Ignatz the line should go from one direction to the other in a clockwise or counterclockwise manner without any deviation in direction unless the parameters reflect/cause said deviation.

    But in each iteration of the code (both yours and mine). The line deviates from the direction it should be going.

    It does not follow the change in parameter value. I think the line thickness may be to blame.

    if it could be brought down to the size of a pixel perhaps the deviation would be gone.

    When I say "line splitting"? I mean just that. The line literally splits in two it moves in two separate directions at the same time but denies half the circle.

    @Simeon? Anyone from twolivesleft? I consider this a glitch do you have further insight?

  • IgnatzIgnatz Mod
    edited August 2013 Posts: 5,396

    The fault is in your code. There is no glitch. Please don't call on Simeon prematurely.

    Your loops that "read" the circle, take slices from the top of the circle, and work down - because you loop through rows first and then columns. So you are capturing the pixels in each row that belong to the circle, and there is one on each side. So your table of values has alternate values from the left and right of the circle.

    As a result, the table values do NOT go round the circle in a clockwise or anti clockwise direction. And, as t increases, it is alternately drawing a pixel on the right and then the left, causing the apparent splitting effect.

    If you print out all the values of the plotted circle table, you will see what I mean. Here is a list of some of them. Note how the x value jumps to the left and right every few values.

    t ............. plottedcircle[t].
    1000 (179.000000, 323.000000).
    1001 (178.000000, 323.000000).
    1002 (423.000000, 322.000000).
    1003 (422.000000, 322.000000).
    1004 (421.000000, 322.000000).
    1005 (180.000000, 322.000000)

  • IgnatzIgnatz Mod
    Posts: 5,396

    PS if you're trying to make a speedometer type needle, there is no need for any of this code. Just use simple trigonometry.

  • dave1707dave1707 Mod
    Posts: 7,807

    @beu5mi I'm not sure if I can explain what I think is happening, but here goes. It looks like the end of the line is tracing the outline of the circle. As the t parameter is slowly changed, the line moves from an x,y position near the right top of the circle, then moves to the opposite x,y value near the left top of the circle. As the t parameter increases, the line flips back and forth tracing the outline of the circle down each side until the lines meet again at the bottom.
    But I'm not sure what you're trying to accomplish. Are you trying to move the line in a circular motion, either clockwise or counter clockwise depending on the t parameter.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @dave1707 - looks like a speedo to me, much easier ways to do that!

  • dave1707dave1707 Mod
    edited August 2013 Posts: 7,807

    @beu5mi Are you trying to do this.


    function setup()     parameter.integer("t",0,720,0)     radius=200     w=WIDTH/2     h=HEIGHT/2 end function draw()     background(40, 40, 50)     stroke(255)     strokeWidth(3)     x=math.sin(math.rad(t))*radius     y=math.cos(math.rad(t))*radius         line(w,h,w+x,h+y) end
Sign In or Register to comment.