Tin học Phần mềm Paint viết bằng.......Pascal !

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
Chắc suất Đại học top - Giữ chỗ ngay!!

ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.

Bây giờ mới thấy Pascal nó lợi hại đến mức nào. Cả Paint mà nó cũng làm được luôn nè :D
Mã:
 Program Paint;
 uses crt,dos,graph;
 const
      _Line = 1;
      _Rectangle = 2;
      _Ellipse = 3;
      _Free = 4;
      _Fill = 5;
      _Clear = 6;

      _MnX = 5;
      _MnY = 105;
      _MxX = 635;
      _MxY = 455;

 type TPoint = record
               X1,Y1,X2,Y2: integer;
               N: integer;
               end;

 var gd,gm: integer;
     Pt,Pm: TPoint;
     Shape : integer;
     Col: Word;
     Size: integer;
     k: char;
     f: Text;

 function mousex:word;assembler;asm
 mov ax,3; int 33h; mov ax,cx end;

 function mousey:word;assembler;asm
 mov ax,3; int 33h; mov ax,dx end;

 function leftclick:boolean;assembler;asm
 mov ax,3; int 33h; and bx,1; mov ax,bx end;

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Function PointNear(Cx,Cy: integer): Boolean;
 var x,y: integer;
 Begin
      PointNear := False;
      for x := Cx - 5 to Cx + 5 do
          for y := Cy - 5 to Cy + 5 do
          if (Mousex = x) and (Mousey = y) then PointNear := True;
 End;

 Procedure DrawMouse;
 var x,y: string;
 Begin
      if (Mousex <> Pm.X1) or (Mousey <> Pm.Y1) then
      begin
      SetFillStyle(1,Black);
      Bar(0,_MxY+5,639,479);
      Str(Mousex-_MnX,X);
      Str(Mousey-_MnY,y);
      Pm.X1 := Mousex;
      Pm.Y1 := Mousey;
      OutTextXy(10,_MxY+10,X+' , ' + Y);
      end;
 End;

 Procedure Choose(sh: integer);
 Begin
      HideMouse;
      SetFillStyle(1,Black);
      Bar(_MnX,81,_MxX,_MnY-7);

      SetLineStyle(0,0,1);
      SetFillStyle(1,Red);
      SetColor(Red);
      FillEllipse((sh-1)*80+40,90,5,5);
      ShowMouse;
 End;

 Procedure DrawShape;
 Begin
      SetColor(White);
      SetLineStyle(0,0,3);
      RecTangle(0,0,639,_MnY-5);
      RecTangle(0,_MnY-5,639,_MxY+5);

      SetLineStyle(0,0,1);

      RecTangle(10,20,70,80);
      RecTangle(90,20,150,80);
      RecTangle(170,20,230,80);
      RecTangle(250,20,310,80);
      RecTangle(330,20,390,80);
      RecTangle(410,20,470,80);
      RecTangle(490,20,550,80);
      RecTangle(570,20,630,80);

      SetLineStyle(0,0,3);
      Line(15,25,65,75);
      Rectangle(100,30,140,70);
      Circle(200,50,20);
      Line(255,25,270,35);
      Line(270,35,263,55);
      Line(263,55,305,75);
      SetFillStyle(1,White);
      Bar(350,40,370,70);
      Bar(340,30,370,40);

      SetFillStyle(1,Col);
      Bar(420,30,460,70);

      SetFillStyle(1,White);
      FillEllipse(520,50,Size*7,Size*7);

      OutTextXy(580,45,'Clear');
 End;

 Procedure Draw;
 Begin
      HideMouse;
      SetColor(White);
      SetLineStyle(0,0,Size);
      case Shape of
      _Line: if Pt.N = 2 then begin Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _RecTangle: if Pt.N = 2 then begin RecTangle(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _Ellipse: if Pt.N = 2 then begin Ellipse((Pt.X1+Pt.X2) div 2,
      (Pt.Y1+Pt.Y2) div 2,0,360,
      abs(Pt.X2 - Pt.X1) div 2,abs(Pt.Y2 - Pt.Y1) div 2);
      PutPixel(Pt.X1,Pt.Y1,Black);Pt.N := 0;end;
      _Free: if (Pt.N <> 0) and (Pt.X2 > 1) then begin
             Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);
             if Pt.N = 2 then Pt.N := 0;end;
      _Fill: begin PutPixel(Pt.X1,Pt.Y1,Col);
      SetFillStyle(1,Col);FloodFill(Pt.X1+1,Pt.Y1+1,White);Pt.N:=0;end;
      _Clear: if (Pt.N <> 0) and (Pt.X1 >= _MnX+3*Size)
      and (Pt.Y1 >= Size*3+_MnY) then begin SetFillStyle(1,Black);
      SetColor(Black);
              FillEllipse(Pt.X1,Pt.Y1,3*Size,3*Size);Pt.N := 0;end;
                 end;
      ShowMouse;
 End;

 Procedure GetShape;
 Begin
      if MouseArea(10,20,70,80) then begin Shape := _Line;Pt.N:=0;Choose(1);end
      else
      if MouseArea(90,20,150,80) then begin Shape := _RecTangle;Pt.N:=0;Choose(2);end
      else
      if MouseArea(170,20,230,80) then begin Shape := _Ellipse;PT.N:=0;Choose(3);end
      else
      if MouseArea(250,20,310,80) then begin Shape := _Free;Pt.X2 := 0;Pt.N:=0;choose(4);end
      else
      if MouseArea(330,20,390,80) then begin Shape := _Fill;Pt.N:=0;choose(5);end
      else
      if MouseArea(410,20,470,80) then
      begin
           inc(col);
           if col > 15 then Col := 1;

           HideMouse;
           SetFillStyle(1,Col);
           Bar(420,30,460,70);
           ShowMouse;
      end
      else
      if MouseArea(490,20,550,80) then
      begin
           inc(Size,2);
           if Size > 3 then Size := 1;

           HideMouse;
           SetFillStyle(1,Black);
           Bar(491,21,549,79);
           SetFillStyle(1,white);
           SetColor(White);
           FillEllipse(520,50,Size*7,Size*7);
           ShowMouse;
      end
      else
      if MouseArea(570,20,630,80) then begin Shape := _Clear;Pt.N:=0;Choose(8);end;
 End;

 Procedure GetPoint;
 Begin
      if LeftClick then
      begin
           if (Pt.N = 0) and not PointNear(Pt.X2,Pt.Y2) then
           begin Pt.X1 := Mousex-1;Pt.Y1 := Mousey-1;
           Pt.N := 1;PutPixel(Mousex-1,Mousey-1,White);end
           else
           if (Pt.N = 1) and not PointNear(Pt.X1,Pt.Y1) then
           begin Pt.X2 := Mousex;Pt.Y2 := Mousey;
           Pt.N := 2;end;
      end;
      Draw;
 End;

 Procedure Save;
 var x,y,c: integer;
 Begin
      HideMouse;
      OutTextXy(150,_MxY+10,'Saving...');
      ReWrite(f);
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               c := GetPixel(x,y);
               writeln(f,c);
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Open;
 var x,y,c,code: integer;
     s: string;
 Begin
      HideMouse;
      Reset(f);
      OutTextXy(150,_MxY+10,'Opening...');
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               Readln(f,s);
               Val(s,c,Code);
               if Code = 0 then
               PutPixel(x,y,c)
               else begin break;x := 635;end;
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Start;
 Begin
      Shape := _Line;
      Col := white;
      Size := 1;
      Pt.N := 0;
      Choose(1);
      Assign(f,'Picture.txt');
 End;

 BEGIN
      InitGraph(gd,gm,'');
      InitMouse;
      ShowMouse;
      Start;
      DrawShape;
      repeat
      if (Mousex >= _MnX) and (MouseX <= _MxX) and
      (Mousey >= _MnY) and (Mousey <= _MxY) then
      DrawMouse;
      k := #0;
      if Keypressed then k := readkey;
      GetShape;
      if MouseArea(_MnX,_MnY,_MxX,_MxY) then
      GetPoint;
      if k = 's' then Save
      else if k = 'o' then Open;
      until k = #27;
      CloseGraph;
 END.

upload_2018-7-6_16-52-17.png
Từ trái sang phải lần lượt là
1) Đường thẳng: Cần tọa độ 2 điểm để vẽ. Các bạn chấm 2 điểm thì nó sẽ vẽ một đường màu trắng, không có màu khác nha.
2) Hình chữ nhật: Cũng cần tọa độ 2 điểm để vẽ, đó là tọa độ 2 đỉnh đối của hình chữ nhật.
3) Hình Ellipse: Cũng cần tọa độ 2 điểm để vẽ. Hình Ellipse vẽ được sẽ nội tiếp hình chữ nhật với 2 điểm mà mình đã chấm.
4) Vẽ tự do: Cứ mỗi lần Click chuột trên màn hình thì nó sẽ nối điểm trước đó với điểm mình Click, để Vẽ hình mới thì cần phải Click lại ô này một làn nữa.
5,6) Tô màu: Màu sắc sẽ được chọn ở ô thứ 6, Click vào hình kín để tô màu.
7) Kích thước đường: Click vào thì nó sẽ thay đổi kích thước đường mình vẽ ra.
8) Xóa: Click vào một điểm thì nó sẽ tạo một đường tròn màu đen có tâm là điểm mình Click để xóa hình.

Ngoài ra nó còn có thể Lưu hình mình vẽ rồi mở lên.
Bấm "s" để lưu hình,"o" để mở hình, sau khi thực hiện xong nó sẽ có tiếng "bip". Vì nó lưu hơi lâu nên mình làm vậy để biết khi nào nó làm xong.

Demo trước vài hình :p

upload_2018-7-6_17-1-4.png
(Cái này là lúc nó đang mở File)

upload_2018-7-6_17-1-34.png
(Cái này là nó mở xong rồi, mình vẽ trước rồi lưu lại :) )

upload_2018-7-6_17-2-44.png
(Cái này là mình chọn chế độ Xóa)

À quên nữa.....Bấm ESC để thoát chương trình nha :p
@ka1412 , @Nguyễn Tùng Ân
 

S I M O

Cựu Phụ trách nhóm Anh
Thành viên
19 Tháng tư 2017
3,385
9
4,341
649
Nam Định
Trái tim của Riky-Kun
Bây giờ mới thấy Pascal nó lợi hại đến mức nào. Cả Paint mà nó cũng làm được luôn nè :D
Mã:
 Program Paint;
 uses crt,dos,graph;
 const
      _Line = 1;
      _Rectangle = 2;
      _Ellipse = 3;
      _Free = 4;
      _Fill = 5;
      _Clear = 6;

      _MnX = 5;
      _MnY = 105;
      _MxX = 635;
      _MxY = 455;

 type TPoint = record
               X1,Y1,X2,Y2: integer;
               N: integer;
               end;

 var gd,gm: integer;
     Pt,Pm: TPoint;
     Shape : integer;
     Col: Word;
     Size: integer;
     k: char;
     f: Text;

 function mousex:word;assembler;asm
 mov ax,3; int 33h; mov ax,cx end;

 function mousey:word;assembler;asm
 mov ax,3; int 33h; mov ax,dx end;

 function leftclick:boolean;assembler;asm
 mov ax,3; int 33h; and bx,1; mov ax,bx end;

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Function PointNear(Cx,Cy: integer): Boolean;
 var x,y: integer;
 Begin
      PointNear := False;
      for x := Cx - 5 to Cx + 5 do
          for y := Cy - 5 to Cy + 5 do
          if (Mousex = x) and (Mousey = y) then PointNear := True;
 End;

 Procedure DrawMouse;
 var x,y: string;
 Begin
      if (Mousex <> Pm.X1) or (Mousey <> Pm.Y1) then
      begin
      SetFillStyle(1,Black);
      Bar(0,_MxY+5,639,479);
      Str(Mousex-_MnX,X);
      Str(Mousey-_MnY,y);
      Pm.X1 := Mousex;
      Pm.Y1 := Mousey;
      OutTextXy(10,_MxY+10,X+' , ' + Y);
      end;
 End;

 Procedure Choose(sh: integer);
 Begin
      HideMouse;
      SetFillStyle(1,Black);
      Bar(_MnX,81,_MxX,_MnY-7);

      SetLineStyle(0,0,1);
      SetFillStyle(1,Red);
      SetColor(Red);
      FillEllipse((sh-1)*80+40,90,5,5);
      ShowMouse;
 End;

 Procedure DrawShape;
 Begin
      SetColor(White);
      SetLineStyle(0,0,3);
      RecTangle(0,0,639,_MnY-5);
      RecTangle(0,_MnY-5,639,_MxY+5);

      SetLineStyle(0,0,1);

      RecTangle(10,20,70,80);
      RecTangle(90,20,150,80);
      RecTangle(170,20,230,80);
      RecTangle(250,20,310,80);
      RecTangle(330,20,390,80);
      RecTangle(410,20,470,80);
      RecTangle(490,20,550,80);
      RecTangle(570,20,630,80);

      SetLineStyle(0,0,3);
      Line(15,25,65,75);
      Rectangle(100,30,140,70);
      Circle(200,50,20);
      Line(255,25,270,35);
      Line(270,35,263,55);
      Line(263,55,305,75);
      SetFillStyle(1,White);
      Bar(350,40,370,70);
      Bar(340,30,370,40);

      SetFillStyle(1,Col);
      Bar(420,30,460,70);

      SetFillStyle(1,White);
      FillEllipse(520,50,Size*7,Size*7);

      OutTextXy(580,45,'Clear');
 End;

 Procedure Draw;
 Begin
      HideMouse;
      SetColor(White);
      SetLineStyle(0,0,Size);
      case Shape of
      _Line: if Pt.N = 2 then begin Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _RecTangle: if Pt.N = 2 then begin RecTangle(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _Ellipse: if Pt.N = 2 then begin Ellipse((Pt.X1+Pt.X2) div 2,
      (Pt.Y1+Pt.Y2) div 2,0,360,
      abs(Pt.X2 - Pt.X1) div 2,abs(Pt.Y2 - Pt.Y1) div 2);
      PutPixel(Pt.X1,Pt.Y1,Black);Pt.N := 0;end;
      _Free: if (Pt.N <> 0) and (Pt.X2 > 1) then begin
             Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);
             if Pt.N = 2 then Pt.N := 0;end;
      _Fill: begin PutPixel(Pt.X1,Pt.Y1,Col);
      SetFillStyle(1,Col);FloodFill(Pt.X1+1,Pt.Y1+1,White);Pt.N:=0;end;
      _Clear: if (Pt.N <> 0) and (Pt.X1 >= _MnX+3*Size)
      and (Pt.Y1 >= Size*3+_MnY) then begin SetFillStyle(1,Black);
      SetColor(Black);
              FillEllipse(Pt.X1,Pt.Y1,3*Size,3*Size);Pt.N := 0;end;
                 end;
      ShowMouse;
 End;

 Procedure GetShape;
 Begin
      if MouseArea(10,20,70,80) then begin Shape := _Line;Pt.N:=0;Choose(1);end
      else
      if MouseArea(90,20,150,80) then begin Shape := _RecTangle;Pt.N:=0;Choose(2);end
      else
      if MouseArea(170,20,230,80) then begin Shape := _Ellipse;PT.N:=0;Choose(3);end
      else
      if MouseArea(250,20,310,80) then begin Shape := _Free;Pt.X2 := 0;Pt.N:=0;choose(4);end
      else
      if MouseArea(330,20,390,80) then begin Shape := _Fill;Pt.N:=0;choose(5);end
      else
      if MouseArea(410,20,470,80) then
      begin
           inc(col);
           if col > 15 then Col := 1;

           HideMouse;
           SetFillStyle(1,Col);
           Bar(420,30,460,70);
           ShowMouse;
      end
      else
      if MouseArea(490,20,550,80) then
      begin
           inc(Size,2);
           if Size > 3 then Size := 1;

           HideMouse;
           SetFillStyle(1,Black);
           Bar(491,21,549,79);
           SetFillStyle(1,white);
           SetColor(White);
           FillEllipse(520,50,Size*7,Size*7);
           ShowMouse;
      end
      else
      if MouseArea(570,20,630,80) then begin Shape := _Clear;Pt.N:=0;Choose(8);end;
 End;

 Procedure GetPoint;
 Begin
      if LeftClick then
      begin
           if (Pt.N = 0) and not PointNear(Pt.X2,Pt.Y2) then
           begin Pt.X1 := Mousex-1;Pt.Y1 := Mousey-1;
           Pt.N := 1;PutPixel(Mousex-1,Mousey-1,White);end
           else
           if (Pt.N = 1) and not PointNear(Pt.X1,Pt.Y1) then
           begin Pt.X2 := Mousex;Pt.Y2 := Mousey;
           Pt.N := 2;end;
      end;
      Draw;
 End;

 Procedure Save;
 var x,y,c: integer;
 Begin
      HideMouse;
      OutTextXy(150,_MxY+10,'Saving...');
      ReWrite(f);
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               c := GetPixel(x,y);
               writeln(f,c);
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Open;
 var x,y,c,code: integer;
     s: string;
 Begin
      HideMouse;
      Reset(f);
      OutTextXy(150,_MxY+10,'Opening...');
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               Readln(f,s);
               Val(s,c,Code);
               if Code = 0 then
               PutPixel(x,y,c)
               else begin break;x := 635;end;
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Start;
 Begin
      Shape := _Line;
      Col := white;
      Size := 1;
      Pt.N := 0;
      Choose(1);
      Assign(f,'Picture.txt');
 End;

 BEGIN
      InitGraph(gd,gm,'');
      InitMouse;
      ShowMouse;
      Start;
      DrawShape;
      repeat
      if (Mousex >= _MnX) and (MouseX <= _MxX) and
      (Mousey >= _MnY) and (Mousey <= _MxY) then
      DrawMouse;
      k := #0;
      if Keypressed then k := readkey;
      GetShape;
      if MouseArea(_MnX,_MnY,_MxX,_MxY) then
      GetPoint;
      if k = 's' then Save
      else if k = 'o' then Open;
      until k = #27;
      CloseGraph;
 END.

View attachment 63449
Từ trái sang phải lần lượt là
1) Đường thẳng: Cần tọa độ 2 điểm để vẽ. Các bạn chấm 2 điểm thì nó sẽ vẽ một đường màu trắng, không có màu khác nha.
2) Hình chữ nhật: Cũng cần tọa độ 2 điểm để vẽ, đó là tọa độ 2 đỉnh đối của hình chữ nhật.
3) Hình Ellipse: Cũng cần tọa độ 2 điểm để vẽ. Hình Ellipse vẽ được sẽ nội tiếp hình chữ nhật với 2 điểm mà mình đã chấm.
4) Vẽ tự do: Cứ mỗi lần Click chuột trên màn hình thì nó sẽ nối điểm trước đó với điểm mình Click, để Vẽ hình mới thì cần phải Click lại ô này một làn nữa.
5,6) Tô màu: Màu sắc sẽ được chọn ở ô thứ 6, Click vào hình kín để tô màu.
7) Kích thước đường: Click vào thì nó sẽ thay đổi kích thước đường mình vẽ ra.
8) Xóa: Click vào một điểm thì nó sẽ tạo một đường tròn màu đen có tâm là điểm mình Click để xóa hình.

Ngoài ra nó còn có thể Lưu hình mình vẽ rồi mở lên.
Bấm "s" để lưu hình,"o" để mở hình, sau khi thực hiện xong nó sẽ có tiếng "bip". Vì nó lưu hơi lâu nên mình làm vậy để biết khi nào nó làm xong.

Demo trước vài hình :p

View attachment 63451
(Cái này là lúc nó đang mở File)

View attachment 63452
(Cái này là nó mở xong rồi, mình vẽ trước rồi lưu lại :) )

View attachment 63453
(Cái này là mình chọn chế độ Xóa)

À quên nữa.....Bấm ESC để thoát chương trình nha :p
@ka1412 , @Nguyễn Tùng Ân
Cảm thấy bạn rất giỏi phần này
 

Tạ Đặng Vĩnh Phúc

Cựu Trưởng nhóm Toán
Thành viên
10 Tháng mười một 2013
1,559
2,715
386
25
Cần Thơ
Đại học Cần Thơ
Bây giờ mới thấy Pascal nó lợi hại đến mức nào. Cả Paint mà nó cũng làm được luôn nè :D
Mã:
 Program Paint;
 uses crt,dos,graph;
 const
      _Line = 1;
      _Rectangle = 2;
      _Ellipse = 3;
      _Free = 4;
      _Fill = 5;
      _Clear = 6;

      _MnX = 5;
      _MnY = 105;
      _MxX = 635;
      _MxY = 455;

 type TPoint = record
               X1,Y1,X2,Y2: integer;
               N: integer;
               end;

 var gd,gm: integer;
     Pt,Pm: TPoint;
     Shape : integer;
     Col: Word;
     Size: integer;
     k: char;
     f: Text;

 function mousex:word;assembler;asm
 mov ax,3; int 33h; mov ax,cx end;

 function mousey:word;assembler;asm
 mov ax,3; int 33h; mov ax,dx end;

 function leftclick:boolean;assembler;asm
 mov ax,3; int 33h; and bx,1; mov ax,bx end;

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Function PointNear(Cx,Cy: integer): Boolean;
 var x,y: integer;
 Begin
      PointNear := False;
      for x := Cx - 5 to Cx + 5 do
          for y := Cy - 5 to Cy + 5 do
          if (Mousex = x) and (Mousey = y) then PointNear := True;
 End;

 Procedure DrawMouse;
 var x,y: string;
 Begin
      if (Mousex <> Pm.X1) or (Mousey <> Pm.Y1) then
      begin
      SetFillStyle(1,Black);
      Bar(0,_MxY+5,639,479);
      Str(Mousex-_MnX,X);
      Str(Mousey-_MnY,y);
      Pm.X1 := Mousex;
      Pm.Y1 := Mousey;
      OutTextXy(10,_MxY+10,X+' , ' + Y);
      end;
 End;

 Procedure Choose(sh: integer);
 Begin
      HideMouse;
      SetFillStyle(1,Black);
      Bar(_MnX,81,_MxX,_MnY-7);

      SetLineStyle(0,0,1);
      SetFillStyle(1,Red);
      SetColor(Red);
      FillEllipse((sh-1)*80+40,90,5,5);
      ShowMouse;
 End;

 Procedure DrawShape;
 Begin
      SetColor(White);
      SetLineStyle(0,0,3);
      RecTangle(0,0,639,_MnY-5);
      RecTangle(0,_MnY-5,639,_MxY+5);

      SetLineStyle(0,0,1);

      RecTangle(10,20,70,80);
      RecTangle(90,20,150,80);
      RecTangle(170,20,230,80);
      RecTangle(250,20,310,80);
      RecTangle(330,20,390,80);
      RecTangle(410,20,470,80);
      RecTangle(490,20,550,80);
      RecTangle(570,20,630,80);

      SetLineStyle(0,0,3);
      Line(15,25,65,75);
      Rectangle(100,30,140,70);
      Circle(200,50,20);
      Line(255,25,270,35);
      Line(270,35,263,55);
      Line(263,55,305,75);
      SetFillStyle(1,White);
      Bar(350,40,370,70);
      Bar(340,30,370,40);

      SetFillStyle(1,Col);
      Bar(420,30,460,70);

      SetFillStyle(1,White);
      FillEllipse(520,50,Size*7,Size*7);

      OutTextXy(580,45,'Clear');
 End;

 Procedure Draw;
 Begin
      HideMouse;
      SetColor(White);
      SetLineStyle(0,0,Size);
      case Shape of
      _Line: if Pt.N = 2 then begin Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _RecTangle: if Pt.N = 2 then begin RecTangle(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _Ellipse: if Pt.N = 2 then begin Ellipse((Pt.X1+Pt.X2) div 2,
      (Pt.Y1+Pt.Y2) div 2,0,360,
      abs(Pt.X2 - Pt.X1) div 2,abs(Pt.Y2 - Pt.Y1) div 2);
      PutPixel(Pt.X1,Pt.Y1,Black);Pt.N := 0;end;
      _Free: if (Pt.N <> 0) and (Pt.X2 > 1) then begin
             Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);
             if Pt.N = 2 then Pt.N := 0;end;
      _Fill: begin PutPixel(Pt.X1,Pt.Y1,Col);
      SetFillStyle(1,Col);FloodFill(Pt.X1+1,Pt.Y1+1,White);Pt.N:=0;end;
      _Clear: if (Pt.N <> 0) and (Pt.X1 >= _MnX+3*Size)
      and (Pt.Y1 >= Size*3+_MnY) then begin SetFillStyle(1,Black);
      SetColor(Black);
              FillEllipse(Pt.X1,Pt.Y1,3*Size,3*Size);Pt.N := 0;end;
                 end;
      ShowMouse;
 End;

 Procedure GetShape;
 Begin
      if MouseArea(10,20,70,80) then begin Shape := _Line;Pt.N:=0;Choose(1);end
      else
      if MouseArea(90,20,150,80) then begin Shape := _RecTangle;Pt.N:=0;Choose(2);end
      else
      if MouseArea(170,20,230,80) then begin Shape := _Ellipse;PT.N:=0;Choose(3);end
      else
      if MouseArea(250,20,310,80) then begin Shape := _Free;Pt.X2 := 0;Pt.N:=0;choose(4);end
      else
      if MouseArea(330,20,390,80) then begin Shape := _Fill;Pt.N:=0;choose(5);end
      else
      if MouseArea(410,20,470,80) then
      begin
           inc(col);
           if col > 15 then Col := 1;

           HideMouse;
           SetFillStyle(1,Col);
           Bar(420,30,460,70);
           ShowMouse;
      end
      else
      if MouseArea(490,20,550,80) then
      begin
           inc(Size,2);
           if Size > 3 then Size := 1;

           HideMouse;
           SetFillStyle(1,Black);
           Bar(491,21,549,79);
           SetFillStyle(1,white);
           SetColor(White);
           FillEllipse(520,50,Size*7,Size*7);
           ShowMouse;
      end
      else
      if MouseArea(570,20,630,80) then begin Shape := _Clear;Pt.N:=0;Choose(8);end;
 End;

 Procedure GetPoint;
 Begin
      if LeftClick then
      begin
           if (Pt.N = 0) and not PointNear(Pt.X2,Pt.Y2) then
           begin Pt.X1 := Mousex-1;Pt.Y1 := Mousey-1;
           Pt.N := 1;PutPixel(Mousex-1,Mousey-1,White);end
           else
           if (Pt.N = 1) and not PointNear(Pt.X1,Pt.Y1) then
           begin Pt.X2 := Mousex;Pt.Y2 := Mousey;
           Pt.N := 2;end;
      end;
      Draw;
 End;

 Procedure Save;
 var x,y,c: integer;
 Begin
      HideMouse;
      OutTextXy(150,_MxY+10,'Saving...');
      ReWrite(f);
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               c := GetPixel(x,y);
               writeln(f,c);
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Open;
 var x,y,c,code: integer;
     s: string;
 Begin
      HideMouse;
      Reset(f);
      OutTextXy(150,_MxY+10,'Opening...');
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               Readln(f,s);
               Val(s,c,Code);
               if Code = 0 then
               PutPixel(x,y,c)
               else begin break;x := 635;end;
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Start;
 Begin
      Shape := _Line;
      Col := white;
      Size := 1;
      Pt.N := 0;
      Choose(1);
      Assign(f,'Picture.txt');
 End;

 BEGIN
      InitGraph(gd,gm,'');
      InitMouse;
      ShowMouse;
      Start;
      DrawShape;
      repeat
      if (Mousex >= _MnX) and (MouseX <= _MxX) and
      (Mousey >= _MnY) and (Mousey <= _MxY) then
      DrawMouse;
      k := #0;
      if Keypressed then k := readkey;
      GetShape;
      if MouseArea(_MnX,_MnY,_MxX,_MxY) then
      GetPoint;
      if k = 's' then Save
      else if k = 'o' then Open;
      until k = #27;
      CloseGraph;
 END.

View attachment 63449
Từ trái sang phải lần lượt là
1) Đường thẳng: Cần tọa độ 2 điểm để vẽ. Các bạn chấm 2 điểm thì nó sẽ vẽ một đường màu trắng, không có màu khác nha.
2) Hình chữ nhật: Cũng cần tọa độ 2 điểm để vẽ, đó là tọa độ 2 đỉnh đối của hình chữ nhật.
3) Hình Ellipse: Cũng cần tọa độ 2 điểm để vẽ. Hình Ellipse vẽ được sẽ nội tiếp hình chữ nhật với 2 điểm mà mình đã chấm.
4) Vẽ tự do: Cứ mỗi lần Click chuột trên màn hình thì nó sẽ nối điểm trước đó với điểm mình Click, để Vẽ hình mới thì cần phải Click lại ô này một làn nữa.
5,6) Tô màu: Màu sắc sẽ được chọn ở ô thứ 6, Click vào hình kín để tô màu.
7) Kích thước đường: Click vào thì nó sẽ thay đổi kích thước đường mình vẽ ra.
8) Xóa: Click vào một điểm thì nó sẽ tạo một đường tròn màu đen có tâm là điểm mình Click để xóa hình.

Ngoài ra nó còn có thể Lưu hình mình vẽ rồi mở lên.
Bấm "s" để lưu hình,"o" để mở hình, sau khi thực hiện xong nó sẽ có tiếng "bip". Vì nó lưu hơi lâu nên mình làm vậy để biết khi nào nó làm xong.

Demo trước vài hình :p

View attachment 63451
(Cái này là lúc nó đang mở File)

View attachment 63452
(Cái này là nó mở xong rồi, mình vẽ trước rồi lưu lại :) )

View attachment 63453
(Cái này là mình chọn chế độ Xóa)

À quên nữa.....Bấm ESC để thoát chương trình nha :p
@ka1412 , @Nguyễn Tùng Ân

E làm a nhớ lại một thời chinh chiến với đồ họa DOS, nhưng nên hiện đại hơn đi e. Viết cho windows và các nền tảng khác đi nhé
Sau đây là màn khoe của:
10857842_298395400370027_549613193316520743_n.jpg
 

ka1412

Học sinh chăm học
Thành viên
24 Tháng mười một 2017
874
730
121
Hà Nội
CNN | Life
Bây giờ mới thấy Pascal nó lợi hại đến mức nào. Cả Paint mà nó cũng làm được luôn nè :D
Mã:
 Program Paint;
 uses crt,dos,graph;
 const
      _Line = 1;
      _Rectangle = 2;
      _Ellipse = 3;
      _Free = 4;
      _Fill = 5;
      _Clear = 6;

      _MnX = 5;
      _MnY = 105;
      _MxX = 635;
      _MxY = 455;

 type TPoint = record
               X1,Y1,X2,Y2: integer;
               N: integer;
               end;

 var gd,gm: integer;
     Pt,Pm: TPoint;
     Shape : integer;
     Col: Word;
     Size: integer;
     k: char;
     f: Text;

 function mousex:word;assembler;asm
 mov ax,3; int 33h; mov ax,cx end;

 function mousey:word;assembler;asm
 mov ax,3; int 33h; mov ax,dx end;

 function leftclick:boolean;assembler;asm
 mov ax,3; int 33h; and bx,1; mov ax,bx end;

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Function PointNear(Cx,Cy: integer): Boolean;
 var x,y: integer;
 Begin
      PointNear := False;
      for x := Cx - 5 to Cx + 5 do
          for y := Cy - 5 to Cy + 5 do
          if (Mousex = x) and (Mousey = y) then PointNear := True;
 End;

 Procedure DrawMouse;
 var x,y: string;
 Begin
      if (Mousex <> Pm.X1) or (Mousey <> Pm.Y1) then
      begin
      SetFillStyle(1,Black);
      Bar(0,_MxY+5,639,479);
      Str(Mousex-_MnX,X);
      Str(Mousey-_MnY,y);
      Pm.X1 := Mousex;
      Pm.Y1 := Mousey;
      OutTextXy(10,_MxY+10,X+' , ' + Y);
      end;
 End;

 Procedure Choose(sh: integer);
 Begin
      HideMouse;
      SetFillStyle(1,Black);
      Bar(_MnX,81,_MxX,_MnY-7);

      SetLineStyle(0,0,1);
      SetFillStyle(1,Red);
      SetColor(Red);
      FillEllipse((sh-1)*80+40,90,5,5);
      ShowMouse;
 End;

 Procedure DrawShape;
 Begin
      SetColor(White);
      SetLineStyle(0,0,3);
      RecTangle(0,0,639,_MnY-5);
      RecTangle(0,_MnY-5,639,_MxY+5);

      SetLineStyle(0,0,1);

      RecTangle(10,20,70,80);
      RecTangle(90,20,150,80);
      RecTangle(170,20,230,80);
      RecTangle(250,20,310,80);
      RecTangle(330,20,390,80);
      RecTangle(410,20,470,80);
      RecTangle(490,20,550,80);
      RecTangle(570,20,630,80);

      SetLineStyle(0,0,3);
      Line(15,25,65,75);
      Rectangle(100,30,140,70);
      Circle(200,50,20);
      Line(255,25,270,35);
      Line(270,35,263,55);
      Line(263,55,305,75);
      SetFillStyle(1,White);
      Bar(350,40,370,70);
      Bar(340,30,370,40);

      SetFillStyle(1,Col);
      Bar(420,30,460,70);

      SetFillStyle(1,White);
      FillEllipse(520,50,Size*7,Size*7);

      OutTextXy(580,45,'Clear');
 End;

 Procedure Draw;
 Begin
      HideMouse;
      SetColor(White);
      SetLineStyle(0,0,Size);
      case Shape of
      _Line: if Pt.N = 2 then begin Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _RecTangle: if Pt.N = 2 then begin RecTangle(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _Ellipse: if Pt.N = 2 then begin Ellipse((Pt.X1+Pt.X2) div 2,
      (Pt.Y1+Pt.Y2) div 2,0,360,
      abs(Pt.X2 - Pt.X1) div 2,abs(Pt.Y2 - Pt.Y1) div 2);
      PutPixel(Pt.X1,Pt.Y1,Black);Pt.N := 0;end;
      _Free: if (Pt.N <> 0) and (Pt.X2 > 1) then begin
             Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);
             if Pt.N = 2 then Pt.N := 0;end;
      _Fill: begin PutPixel(Pt.X1,Pt.Y1,Col);
      SetFillStyle(1,Col);FloodFill(Pt.X1+1,Pt.Y1+1,White);Pt.N:=0;end;
      _Clear: if (Pt.N <> 0) and (Pt.X1 >= _MnX+3*Size)
      and (Pt.Y1 >= Size*3+_MnY) then begin SetFillStyle(1,Black);
      SetColor(Black);
              FillEllipse(Pt.X1,Pt.Y1,3*Size,3*Size);Pt.N := 0;end;
                 end;
      ShowMouse;
 End;

 Procedure GetShape;
 Begin
      if MouseArea(10,20,70,80) then begin Shape := _Line;Pt.N:=0;Choose(1);end
      else
      if MouseArea(90,20,150,80) then begin Shape := _RecTangle;Pt.N:=0;Choose(2);end
      else
      if MouseArea(170,20,230,80) then begin Shape := _Ellipse;PT.N:=0;Choose(3);end
      else
      if MouseArea(250,20,310,80) then begin Shape := _Free;Pt.X2 := 0;Pt.N:=0;choose(4);end
      else
      if MouseArea(330,20,390,80) then begin Shape := _Fill;Pt.N:=0;choose(5);end
      else
      if MouseArea(410,20,470,80) then
      begin
           inc(col);
           if col > 15 then Col := 1;

           HideMouse;
           SetFillStyle(1,Col);
           Bar(420,30,460,70);
           ShowMouse;
      end
      else
      if MouseArea(490,20,550,80) then
      begin
           inc(Size,2);
           if Size > 3 then Size := 1;

           HideMouse;
           SetFillStyle(1,Black);
           Bar(491,21,549,79);
           SetFillStyle(1,white);
           SetColor(White);
           FillEllipse(520,50,Size*7,Size*7);
           ShowMouse;
      end
      else
      if MouseArea(570,20,630,80) then begin Shape := _Clear;Pt.N:=0;Choose(8);end;
 End;

 Procedure GetPoint;
 Begin
      if LeftClick then
      begin
           if (Pt.N = 0) and not PointNear(Pt.X2,Pt.Y2) then
           begin Pt.X1 := Mousex-1;Pt.Y1 := Mousey-1;
           Pt.N := 1;PutPixel(Mousex-1,Mousey-1,White);end
           else
           if (Pt.N = 1) and not PointNear(Pt.X1,Pt.Y1) then
           begin Pt.X2 := Mousex;Pt.Y2 := Mousey;
           Pt.N := 2;end;
      end;
      Draw;
 End;

 Procedure Save;
 var x,y,c: integer;
 Begin
      HideMouse;
      OutTextXy(150,_MxY+10,'Saving...');
      ReWrite(f);
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               c := GetPixel(x,y);
               writeln(f,c);
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Open;
 var x,y,c,code: integer;
     s: string;
 Begin
      HideMouse;
      Reset(f);
      OutTextXy(150,_MxY+10,'Opening...');
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               Readln(f,s);
               Val(s,c,Code);
               if Code = 0 then
               PutPixel(x,y,c)
               else begin break;x := 635;end;
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Start;
 Begin
      Shape := _Line;
      Col := white;
      Size := 1;
      Pt.N := 0;
      Choose(1);
      Assign(f,'Picture.txt');
 End;

 BEGIN
      InitGraph(gd,gm,'');
      InitMouse;
      ShowMouse;
      Start;
      DrawShape;
      repeat
      if (Mousex >= _MnX) and (MouseX <= _MxX) and
      (Mousey >= _MnY) and (Mousey <= _MxY) then
      DrawMouse;
      k := #0;
      if Keypressed then k := readkey;
      GetShape;
      if MouseArea(_MnX,_MnY,_MxX,_MxY) then
      GetPoint;
      if k = 's' then Save
      else if k = 'o' then Open;
      until k = #27;
      CloseGraph;
 END.

View attachment 63449
Từ trái sang phải lần lượt là
1) Đường thẳng: Cần tọa độ 2 điểm để vẽ. Các bạn chấm 2 điểm thì nó sẽ vẽ một đường màu trắng, không có màu khác nha.
2) Hình chữ nhật: Cũng cần tọa độ 2 điểm để vẽ, đó là tọa độ 2 đỉnh đối của hình chữ nhật.
3) Hình Ellipse: Cũng cần tọa độ 2 điểm để vẽ. Hình Ellipse vẽ được sẽ nội tiếp hình chữ nhật với 2 điểm mà mình đã chấm.
4) Vẽ tự do: Cứ mỗi lần Click chuột trên màn hình thì nó sẽ nối điểm trước đó với điểm mình Click, để Vẽ hình mới thì cần phải Click lại ô này một làn nữa.
5,6) Tô màu: Màu sắc sẽ được chọn ở ô thứ 6, Click vào hình kín để tô màu.
7) Kích thước đường: Click vào thì nó sẽ thay đổi kích thước đường mình vẽ ra.
8) Xóa: Click vào một điểm thì nó sẽ tạo một đường tròn màu đen có tâm là điểm mình Click để xóa hình.

Ngoài ra nó còn có thể Lưu hình mình vẽ rồi mở lên.
Bấm "s" để lưu hình,"o" để mở hình, sau khi thực hiện xong nó sẽ có tiếng "bip". Vì nó lưu hơi lâu nên mình làm vậy để biết khi nào nó làm xong.

Demo trước vài hình :p

View attachment 63451
(Cái này là lúc nó đang mở File)

View attachment 63452
(Cái này là nó mở xong rồi, mình vẽ trước rồi lưu lại :) )

View attachment 63453
(Cái này là mình chọn chế độ Xóa)

À quên nữa.....Bấm ESC để thoát chương trình nha :p
@ka1412 , @Nguyễn Tùng Ân
t vẫn chưa cài được unit graph :v. Hôm trước ghost máy lại mất luôn.
P/s: C# hay C++ làm được cái này không?
 
Last edited:

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
t vẫn chưa cài được unit graph :v. Hôm trước ghost máy lại mất luôn.
P/s: C# hay C++ làm được cái này không?
Chắc là được.
Muốn cài thư viện Graph thì copy file Graph.tpu trong thư mục Units với file EGAVGA.Bgi trong thư mục BGI bỏ vào thư mục BIN nha :p
upload_2018-7-6_20-43-23.png
upload_2018-7-6_20-44-30.png
 

Attachments

  • upload_2018-7-6_20-44-16.png
    upload_2018-7-6_20-44-16.png
    158.9 KB · Đọc: 103
  • Like
Reactions: S I M O

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
E làm a nhớ lại một thời chinh chiến với đồ họa DOS, nhưng nên hiện đại hơn đi e. Viết cho windows và các nền tảng khác đi nhé
Sau đây là màn khoe của:
10857842_298395400370027_549613193316520743_n.jpg
E không biết viết Code kiểu này, anh chỉ e với ạ :)
Nhìn có vẻ hiện đại hơn
 
  • Like
Reactions: S I M O

Tạ Đặng Vĩnh Phúc

Cựu Trưởng nhóm Toán
Thành viên
10 Tháng mười một 2013
1,559
2,715
386
25
Cần Thơ
Đại học Cần Thơ
E không biết viết Code kiểu này, anh chỉ e với ạ :)
Nhìn có vẻ hiện đại hơn

* A sử dụng hệ đồ họa VGA 320x200x8 bit color, mode 3 của interrupt 0x10
* A viết lại thư viện sử dụng đồ họa trên bằng assembly, các hình ảnh nạp từ file...
 

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh

Quang Trungg

Học sinh xuất sắc
Thành viên
14 Tháng mười một 2015
4,677
7,747
879
20
Hà Nội
THCS Mai Dịch

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,619
744
21
Phú Yên
Trường THPT Lương Văn Chánh
Nhờ anh chút ^^
Làm sao để copy chữ từ ngoài vào pascal ạ?Em xem hết trang trên mạng mà không tìm được.Hay là anh kết nối teamview giúp em chút @@
Có lẽ mình nên dành một bài đăng riêng cho việc này.
- Mở NotePad lên.
- Copy Code dán vào NotePad
- Lưu lại với tên .Pas trong thư mục Bin của DosBox
- Mở Pascal lên và chạy :D
 
  • Like
Reactions: son_gohan

Tống Huy

Cựu TMod Cộng đồng
Thành viên
25 Tháng sáu 2018
4,084
7,241
691
19
Hà Tĩnh
THPT Lê Hữu Trác
Bây giờ mới thấy Pascal nó lợi hại đến mức nào. Cả Paint mà nó cũng làm được luôn nè :D
Mã:
 Program Paint;
 uses crt,dos,graph;
 const
      _Line = 1;
      _Rectangle = 2;
      _Ellipse = 3;
      _Free = 4;
      _Fill = 5;
      _Clear = 6;

      _MnX = 5;
      _MnY = 105;
      _MxX = 635;
      _MxY = 455;

 type TPoint = record
               X1,Y1,X2,Y2: integer;
               N: integer;
               end;

 var gd,gm: integer;
     Pt,Pm: TPoint;
     Shape : integer;
     Col: Word;
     Size: integer;
     k: char;
     f: Text;

 function mousex:word;assembler;asm
 mov ax,3; int 33h; mov ax,cx end;

 function mousey:word;assembler;asm
 mov ax,3; int 33h; mov ax,dx end;

 function leftclick:boolean;assembler;asm
 mov ax,3; int 33h; and bx,1; mov ax,bx end;

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 Function PointNear(Cx,Cy: integer): Boolean;
 var x,y: integer;
 Begin
      PointNear := False;
      for x := Cx - 5 to Cx + 5 do
          for y := Cy - 5 to Cy + 5 do
          if (Mousex = x) and (Mousey = y) then PointNear := True;
 End;

 Procedure DrawMouse;
 var x,y: string;
 Begin
      if (Mousex <> Pm.X1) or (Mousey <> Pm.Y1) then
      begin
      SetFillStyle(1,Black);
      Bar(0,_MxY+5,639,479);
      Str(Mousex-_MnX,X);
      Str(Mousey-_MnY,y);
      Pm.X1 := Mousex;
      Pm.Y1 := Mousey;
      OutTextXy(10,_MxY+10,X+' , ' + Y);
      end;
 End;

 Procedure Choose(sh: integer);
 Begin
      HideMouse;
      SetFillStyle(1,Black);
      Bar(_MnX,81,_MxX,_MnY-7);

      SetLineStyle(0,0,1);
      SetFillStyle(1,Red);
      SetColor(Red);
      FillEllipse((sh-1)*80+40,90,5,5);
      ShowMouse;
 End;

 Procedure DrawShape;
 Begin
      SetColor(White);
      SetLineStyle(0,0,3);
      RecTangle(0,0,639,_MnY-5);
      RecTangle(0,_MnY-5,639,_MxY+5);

      SetLineStyle(0,0,1);

      RecTangle(10,20,70,80);
      RecTangle(90,20,150,80);
      RecTangle(170,20,230,80);
      RecTangle(250,20,310,80);
      RecTangle(330,20,390,80);
      RecTangle(410,20,470,80);
      RecTangle(490,20,550,80);
      RecTangle(570,20,630,80);

      SetLineStyle(0,0,3);
      Line(15,25,65,75);
      Rectangle(100,30,140,70);
      Circle(200,50,20);
      Line(255,25,270,35);
      Line(270,35,263,55);
      Line(263,55,305,75);
      SetFillStyle(1,White);
      Bar(350,40,370,70);
      Bar(340,30,370,40);

      SetFillStyle(1,Col);
      Bar(420,30,460,70);

      SetFillStyle(1,White);
      FillEllipse(520,50,Size*7,Size*7);

      OutTextXy(580,45,'Clear');
 End;

 Procedure Draw;
 Begin
      HideMouse;
      SetColor(White);
      SetLineStyle(0,0,Size);
      case Shape of
      _Line: if Pt.N = 2 then begin Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _RecTangle: if Pt.N = 2 then begin RecTangle(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);Pt.N := 0;end;
      _Ellipse: if Pt.N = 2 then begin Ellipse((Pt.X1+Pt.X2) div 2,
      (Pt.Y1+Pt.Y2) div 2,0,360,
      abs(Pt.X2 - Pt.X1) div 2,abs(Pt.Y2 - Pt.Y1) div 2);
      PutPixel(Pt.X1,Pt.Y1,Black);Pt.N := 0;end;
      _Free: if (Pt.N <> 0) and (Pt.X2 > 1) then begin
             Line(Pt.X1,Pt.Y1,Pt.X2,Pt.Y2);
             if Pt.N = 2 then Pt.N := 0;end;
      _Fill: begin PutPixel(Pt.X1,Pt.Y1,Col);
      SetFillStyle(1,Col);FloodFill(Pt.X1+1,Pt.Y1+1,White);Pt.N:=0;end;
      _Clear: if (Pt.N <> 0) and (Pt.X1 >= _MnX+3*Size)
      and (Pt.Y1 >= Size*3+_MnY) then begin SetFillStyle(1,Black);
      SetColor(Black);
              FillEllipse(Pt.X1,Pt.Y1,3*Size,3*Size);Pt.N := 0;end;
                 end;
      ShowMouse;
 End;

 Procedure GetShape;
 Begin
      if MouseArea(10,20,70,80) then begin Shape := _Line;Pt.N:=0;Choose(1);end
      else
      if MouseArea(90,20,150,80) then begin Shape := _RecTangle;Pt.N:=0;Choose(2);end
      else
      if MouseArea(170,20,230,80) then begin Shape := _Ellipse;PT.N:=0;Choose(3);end
      else
      if MouseArea(250,20,310,80) then begin Shape := _Free;Pt.X2 := 0;Pt.N:=0;choose(4);end
      else
      if MouseArea(330,20,390,80) then begin Shape := _Fill;Pt.N:=0;choose(5);end
      else
      if MouseArea(410,20,470,80) then
      begin
           inc(col);
           if col > 15 then Col := 1;

           HideMouse;
           SetFillStyle(1,Col);
           Bar(420,30,460,70);
           ShowMouse;
      end
      else
      if MouseArea(490,20,550,80) then
      begin
           inc(Size,2);
           if Size > 3 then Size := 1;

           HideMouse;
           SetFillStyle(1,Black);
           Bar(491,21,549,79);
           SetFillStyle(1,white);
           SetColor(White);
           FillEllipse(520,50,Size*7,Size*7);
           ShowMouse;
      end
      else
      if MouseArea(570,20,630,80) then begin Shape := _Clear;Pt.N:=0;Choose(8);end;
 End;

 Procedure GetPoint;
 Begin
      if LeftClick then
      begin
           if (Pt.N = 0) and not PointNear(Pt.X2,Pt.Y2) then
           begin Pt.X1 := Mousex-1;Pt.Y1 := Mousey-1;
           Pt.N := 1;PutPixel(Mousex-1,Mousey-1,White);end
           else
           if (Pt.N = 1) and not PointNear(Pt.X1,Pt.Y1) then
           begin Pt.X2 := Mousex;Pt.Y2 := Mousey;
           Pt.N := 2;end;
      end;
      Draw;
 End;

 Procedure Save;
 var x,y,c: integer;
 Begin
      HideMouse;
      OutTextXy(150,_MxY+10,'Saving...');
      ReWrite(f);
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               c := GetPixel(x,y);
               writeln(f,c);
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Open;
 var x,y,c,code: integer;
     s: string;
 Begin
      HideMouse;
      Reset(f);
      OutTextXy(150,_MxY+10,'Opening...');
      for x := _MnX to _MxX do
          for y := _MnY to _MxY do
          begin
               Readln(f,s);
               Val(s,c,Code);
               if Code = 0 then
               PutPixel(x,y,c)
               else begin break;x := 635;end;
          end;
      Close(f);
      sound(1000);
      Delay(100);
      Nosound;
      ShowMouse;
      DrawMouse;
 End;

 Procedure Start;
 Begin
      Shape := _Line;
      Col := white;
      Size := 1;
      Pt.N := 0;
      Choose(1);
      Assign(f,'Picture.txt');
 End;

 BEGIN
      InitGraph(gd,gm,'');
      InitMouse;
      ShowMouse;
      Start;
      DrawShape;
      repeat
      if (Mousex >= _MnX) and (MouseX <= _MxX) and
      (Mousey >= _MnY) and (Mousey <= _MxY) then
      DrawMouse;
      k := #0;
      if Keypressed then k := readkey;
      GetShape;
      if MouseArea(_MnX,_MnY,_MxX,_MxY) then
      GetPoint;
      if k = 's' then Save
      else if k = 'o' then Open;
      until k = #27;
      CloseGraph;
 END.

View attachment 63449
Từ trái sang phải lần lượt là
1) Đường thẳng: Cần tọa độ 2 điểm để vẽ. Các bạn chấm 2 điểm thì nó sẽ vẽ một đường màu trắng, không có màu khác nha.
2) Hình chữ nhật: Cũng cần tọa độ 2 điểm để vẽ, đó là tọa độ 2 đỉnh đối của hình chữ nhật.
3) Hình Ellipse: Cũng cần tọa độ 2 điểm để vẽ. Hình Ellipse vẽ được sẽ nội tiếp hình chữ nhật với 2 điểm mà mình đã chấm.
4) Vẽ tự do: Cứ mỗi lần Click chuột trên màn hình thì nó sẽ nối điểm trước đó với điểm mình Click, để Vẽ hình mới thì cần phải Click lại ô này một làn nữa.
5,6) Tô màu: Màu sắc sẽ được chọn ở ô thứ 6, Click vào hình kín để tô màu.
7) Kích thước đường: Click vào thì nó sẽ thay đổi kích thước đường mình vẽ ra.
8) Xóa: Click vào một điểm thì nó sẽ tạo một đường tròn màu đen có tâm là điểm mình Click để xóa hình.

Ngoài ra nó còn có thể Lưu hình mình vẽ rồi mở lên.
Bấm "s" để lưu hình,"o" để mở hình, sau khi thực hiện xong nó sẽ có tiếng "bip". Vì nó lưu hơi lâu nên mình làm vậy để biết khi nào nó làm xong.

Demo trước vài hình :p

View attachment 63451
(Cái này là lúc nó đang mở File)

View attachment 63452
(Cái này là nó mở xong rồi, mình vẽ trước rồi lưu lại :) )

View attachment 63453
(Cái này là mình chọn chế độ Xóa)

À quên nữa.....Bấm ESC để thoát chương trình nha :p
@ka1412 , @Nguyễn Tùng Ân
Anh giỏi quá ! =)
Cái gì cũng giỏi :)
Em mượn code nhé ! ( Xin để tránh lỗi bản quyền :p)
 
Top Bottom