Moving line

edited March 2016 in How To...

The img is only to help me explain a bit better what i'm trying to do. So, the img on the background as the points (A and B) are static images, but i want to make the line to move from point A to B, as in GPS.

line

Tagged:

Answers

  • Answer ✓

    Yes.

    look at lerp() to make this

    draw a line from A to the lerp() point and increase amt in draw()

    No for-loop

    It's a direct line without the Z

  • I'm going to try it then. Thank you

  • PImage map, startLocation, endLocation; 
    float x, target;
    
    void setup() {
      size(320, 320);
    
      // IMAGENS
      map = loadImage ("img/map.png");
      startLocation = loadImage ("img/startLocation.png");
      endLocation = loadImage ("img/endLocation.png");
    
      // IMAGEM DE FUNDO
      background (0);
    
      x = width/12;
      target = 210;
    }
    
    void draw() {
    
      // MAPA
      background (map);
    
      x = lerp(x, target, 0.020);
    
      // LOCALIZAÇÃO DO CARRO
      image (startLocation, width/11, height/1.6);
      startLocation.resize (0, 20);
    
      // LOCALIZAÇÃO DO USER
      image (endLocation, width/1.6, height/2.5 );
      endLocation.resize (0, 20);
    
      // CAMINHO DO USER
      stroke ( 255, 100, 100);
      line ( x, 160, 38, 222);
    }
    

    this is what i got. i wonder if, instead of doing with a line i could put the "endLocation " img moving. is that possible?

  • Answer ✓

    Yes

  • I'm trying to make the "endLocation " img moving, but i can´t, and at this point i dont know what i'm doing xD, ahaha. Can you please show me how? I already try PVectors but still failed. I want to believe it is because i never used lerp() or PVectors, but at this point i have no idea

  • Answer ✓

    First, you lerp x

    but you forgot to lerp y as well

    Then just say

    image(endLocation, x, y );

    also you need to increase the amt value :

    amt += .05;

    and use it in both lerp()-lines

    Remark:

    to do this properly I suggest better names

    That lets you have control and a good over view over your own code.

    e.g. you use numbers in line or lerp - very confusing

    Better use variables throughout

    Like startX, startY

    endX, endY (all four are fixed)

    then currentX , currentY = they come from the lerp()-lines

Sign In or Register to comment.