Howdy, Stranger!

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

How create a line between touch 1 and touch 2?

edited December 2014 in General Posts: 4

Can't find answer nowhere

Comments

  • dave1707dave1707 Mod
    edited December 2014 Posts: 7,155

    @Apselon Try this.


    function setup() x1,y1=0,0 x2,y2=0,0 end function draw() background(40, 40, 50) stroke(255) strokeWidth(2) if x1+y1>0 and x2+y2>0 then line(x1,y1,x2,y2) end fill(255) if x1+y1>0 then ellipse(x1,y1,10) end if x2+y2>0 then ellipse(x2,y2,10) end end function touched(t) if t.state==BEGAN then if x1+y1==0 then x1=t.x y1=t.y elseif x2+y2==0 then x2=t.x y2=t.y else x1=t.x y1=t.y x2,y2=0,0 end end end
  • @dave1707
    Thank you

  • dave1707dave1707 Mod
    Posts: 7,155

    @Apselon Here's a stripped down version that uses Boolean variables.


    function setup() first=true end function draw() background(40, 40, 50) stroke(255) strokeWidth(2) if show then line(x1,y1,x2,y2) end end function touched(t) if t.state==BEGAN then if first then x1,y1=t.x,t.y first,show=false,false else x2,y2=t.x,t.y first,show=true,true end end end
Sign In or Register to comment.