j'ai tenté un essai d'animation dans le canvas avec asphyre dont voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,AsphyreDevices,AsphyreEvents,AsphyreTimer,Vectors2;
 
type TEspacemath=record
     O:TPoint2;
     grd:single;//valeur des graduations
     end;
 
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Déclarations privées }
  i:integer;
  theta,w,t:single;
  espace:Tespacemath;
  function x(val:single):single;
  function y(val:single):single;
  function convert(val:single):single;
  procedure configureDevice(sender:TAsphyreDevice;Tag:TObject;var config:TscreenConfig);
  procedure TimerEvent(sender:TObject);
  procedure ProcessEvent (sender:TObject);
  procedure RenderCallback(sender:TAsphyreDevice;Tag:TObject);
  public
    { Déclarations publiques }
  end;
 
 
var
  Form1: TForm1;
 
implementation
  Const R=10;
{$R *.dfm}
 
procedure TForm1.configureDevice(sender:TAsphyreDevice;Tag:TObject;var config:TscreenConfig);
begin
config.WindowHandle:=self.Handle;
config.Width:=clientwidth;
config.height:=clientheight;
config.windowed:=true;
config.bitdepth:=bd24bit;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
width:=screen.Width;
height:=screen.Height div 2;
position:=poscreencenter;
formstyle:=fsstayontop;
if (not Devices.Initialize(Configuredevice,self)) then
begin
  MessageDlg('asphyre n''a pas pu s''initialiser' ,mtError,[mbOk],0); 
  Close();
  Exit;
end;
timer.Enabled:=true;
timer.OnTimer:=timerevent;
timer.MaxFPS:=100; //freq des images
 
with espace do begin
               O:=point2(0,clientheight);
               grd:=clientwidth/100;
end;
w:=40*pi/180; //vitesse angulaire 40°/s
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
Devices.Finalize;
end;
 
procedure TForm1.RenderCallback(sender:TAsphyreDevice;Tag:TObject);
var j:integer;
 
begin
 
with sender.Canvas do begin
LineAntialias:=true;
LineWidth:=1;
for j := 0 to 50 do begin
                    lineex(point2(x(2*j),y(0)),point2(x(2*j),y(100)),$ffffffff);
                    lineex(point2(x(0),y(2*j)),point2(x(100),y(2*j)),$ffffffff);
end;
LineWidth:=5;
lineex(point2(x(0),y(2)),point2(x(100),y(2)),$ff00ffff);
LineWidth:=7;
//ROUE
circle(x(R*theta+R),y(R+2),convert(R),60,$ffff0000);
LineWidth:=5;
lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta)),y(R+2+R*sin(-theta))),$ffff0000);
lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+pi/2)),y(R+2+R*sin(-(theta+pi/2)))),$ffff0000);
lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+3*pi/2)),y(R+2+R*sin(-(theta+3*pi/2)))),$ffff0000);
lineex(point2(x(R*theta+R),y(R+2)),point2(x(R*theta+R+R*cos(theta+pi)),y(R+2+R*sin(-(theta+pi)))),$ffff0000);
//
 
end;
end;
 
procedure TForm1.TimerEvent(sender:TObject);
begin
caption:=floattostr(t)+' s';
t:=t+1/timer.MaxFPS;
If convert(R*THETA)>clientwidth then begin theta:=0; t:=0;end;
theta:=w*t;
DefDevice.Render(rendercallback,self,$ff000000);
Timer.Process;
end;
 
procedure TForm1.ProcessEvent (sender:TObject);
begin
//rien
end;
 
function TForm1.x(val:single):single;
begin
result:=espace.O.X+espace.grd*val;
end;
 
function TForm1.y(val: Single):single;
begin
result:=espace.O.y-espace.grd*val;
end;
 
function Tform1.convert(val:single):single;
begin
result:=val*espace.grd;
end;
 
end.
peu importe l'animation...c'était un essai...
je suis passé en coordonnées mathématiques, c'est plus cool pour raisonner.

Je gagne en fluidité, c'est certain lol
mais le onpaint ? (comment ça marche ?-> Dessin qui se redessine difficilement après déplacement de la fiche en dehors de l'écran...De plus, le timer qui semble s'arrêter momentanément..

Et en agrandissement(wsmaximised) la fenêtre, déformation du dessin alors que tout est fait en fonction de la largeur de l'écran ?

donc distorsion du canvas...