關於小畫家(bezier)曲線 |
尚未結案
|
howard15230
一般會員 發表:3 回覆:0 積分:0 註冊:2010-09-27 發送簡訊給我 |
不好意思~請教各位一下
目前我看書已經把bezier曲線畫出來了 可是因為我的點是動態的,我是把顏色改成白色清除曲線 我想問是說有沒有別的方法清除 程式如下 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "e11_1gu.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int md,mm; int mu; //MouseUp int xo,yo; //x_old,y_old TPoint p[10]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- // 貝茲曲線 void __fastcall TForm1::btnarcClick(TObject *Sender) { md=0; mm=0; mu=0; Form1->Caption="貝茲曲線"; } //--------------------------------------------------------------------------- void __fastcall TForm1::imgMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { md ; //MouseDown if (md==1) { p[0]=Point(X,Y); p[1]=Point(X,Y); img->Canvas->TextOut(X-20,Y-20,"(x0,y0)"); } } //--------------------------------------------------------------------------- void __fastcall TForm1::btnendClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::imgMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (md==0) //未按左鍵而移動滑鼠,則離開。 return; switch (mu) { case 0: //直線的貝茲曲線 if (mm==0) { //繪第一個曲線 p[3]=Point(X,Y); p[2]=Point(X,Y); img->Canvas->PolyBezier(p,3); xo=X; //x_old yo=Y; //y_old mm=1; } if (mm==1) { //再移動時,先刪除剛剛的曲線,再劃新的曲線 img->Canvas->Pen->Color=clWhite; p[2]=Point(xo,yo); p[3]=Point(xo,yo); img->Canvas->PolyBezier(p,3); img->Canvas->Pen->Color=clBlue; p[2]=Point(X,Y); p[3]=Point(X,Y); img->Canvas->PolyBezier(p,3); xo=X; yo=Y; } break; case 1: //一個折點的貝茲曲線 if (md==2) { //再移動時,先刪除剛剛的圖形,再劃新的圖形 img->Canvas->Pen->Color=clWhite; p[2]=Point(xo,yo); img->Canvas->PolyBezier(p,3); img->Canvas->Pen->Color=clBlue; p[2]=Point(X,Y); img->Canvas->PolyBezier(p,3); xo=X; yo=Y; } break; case 2: //兩個折點的曲線 if ( mm==0) { //先擦 Case 1 的單一折點曲線 p[2]=Point(xo,yo); img->Canvas->Pen->Color=clWhite; img->Canvas->PolyBezier(p,3); // img->Canvas->FillRect(ClientRect); //畫 case 2 的第一條曲線 p[1]=Point(X,Y); img->Canvas->Pen->Color=clBlue; img->Canvas->PolyBezier(p,3); xo=X; //x_old yo=Y; //y_old mm=1; //Orgmap->Assign(img->Picture->Bitmap); } if (md==3 && mm==1) { //再移動時,先刪除剛剛的曲線,再劃新的曲線 img->Canvas->Pen->Color=clWhite; p[1]=Point(xo,yo); img->Canvas->PolyBezier(p,3); //img->Canvas->FillRect(ClientRect); img->Canvas->Pen->Color=clBlue; p[1]=Point(X,Y); img->Canvas->PolyBezier(p,3); xo=X; yo=Y; } break; } } //--------------------------------------------------------------------------- //MouseUp void __fastcall TForm1::imgMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mu ; switch (mu) { case 1: p[3]=Point(X,Y); mm=0 ; img->Canvas->TextOut(X,Y,"(x3,y3)"); xo=X; yo=Y; break; case 2: p[2]=Point(X,Y); mm=0 ; img->Canvas->TextOut(X,Y,"(x2,y2)"); img->Canvas->Pixels[X][Y]=clRed; xo=X; yo=Y; break; case 3: p[1]=Point(X,Y); mm=0 ; img->Canvas->TextOut(X,Y,"(x1,y1)"); img->Canvas->Pixels[X][Y]=clRed; break; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { img->Picture=0; } //--------------------------------------------------------------------------- [/code] |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |