0
我正在嘗試製作生長線的動畫,它將看起來像該線正在朝着畫布寬度的末端移動,並且該線的開始將僅是線的終點應該是增長 這裏是我的代碼在android PLZ上畫線的類將幫助任何幫助將被設置。如何在畫布上製作生長線動畫android
package com.example.line;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.view.View;
public class MyPlay extends View{
float startx = 30;
float starty = 60;
float endx=0;
float endy=0;
public MyPlay(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawColor(Color.WHITE);
Paint textPaint = new Paint();
textPaint.setARGB(50, 254, 10, 50);
textPaint.setColor(Color.RED);
textPaint.setTextAlign(Align.CENTER);
textPaint.setTextSize(20);
canvas.drawText("Made by Skyrush", canvas.getWidth()/2, canvas.getHeight()/2, textPaint);
Paint linePaint = new Paint();
linePaint.setColor(Color.BLACK);
linePaint.setStrokeWidth(2);
//canvas.drawLine(startx, starty, endx, endy, linePaint);
if(endx < canvas.getWidth()){
endx = startx+5;
endy = starty-5;
canvas.drawLine(startx, starty, endx, endy, linePaint);
invalidate();
}
invalidate();
}
}
所以我才明白正確的;你有兩個點p0 =(x0,y0)和p1 =(x1,y1),你想要從p0增長到p1?如果是這樣,對_linear interpolation_做一些研究會有很大的幫助。 – harism
我有兩個點p0 =(x0,y0)和p1 =(x1,y1),我想要一條從p0到p1的線,然後像p1(x1 + 5,y1 + 5)一樣以某種速度前進,直到它到達畫布寬度。 –
確實有人知道如何獲得所需的輸出,請幫助,因爲我現在正在通過製作簡單的動畫來學習 –