# Discussion: Sapin de Noël

1. ## Sapin de Noël

Bonsoir !

Voici un modeste essai de sapin de Noël.

Pour faire les boules, j'ai copié le code des bombes du Démineur de Paul Toth.

 Code : Sélectionner tout - Visualiser dans une fenêtre à part
```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127{\$FRAME_WIDTH 210}
{\$FRAME_HEIGHT 400}
{\$BACKGROUND \$303030}

program Sapin;

uses
Flash8, Couleurs, Etoile;

{ --- Extrait modifié de FlashMine.fpr --------------------------------------- }

type
TBoule = class(MovieClip)
constructor Create(Name: string; x, y, c, d: Integer);
procedure IsBomb(color: Integer);
end;

TMatrix = class
matrixType: string;
x,y,w,h   : Double;
r         : Double;
constructor Create;
end;

var
Boules  : array[0..9] of TBoule;
Matrix : TMatrix;

constructor TBoule.Create(Name: string; x, y, c, d: Integer);
begin
inherited Create(nil, Name, d);
_x := x;
_y := y;
IsBomb(c);
end;

var
a    : Double;
c1,s1: Double;
c2,s2: Double;
r2   : Double;
begin
a := 3.14/4;
c1 := cos(a);
s1 := sin(a);
a := 3.14/8;
c2 := cos(a);
s2 := sin(a);
end;

procedure TBoule.IsBomb(color: Integer);
begin
lineStyle(0, color);
circle(8);
endFill;
end;

constructor TMatrix.Create;
begin
matrixType := 'box';
x := -4.5;
y := -4.5;
w := 6;
h := 6;
r := 0;
end;

{ --- Fin de l'extrait ------------------------------------------------------- }

var
Etoile: TEtoile;
i: Integer;

begin
with _root do
begin
lineStyle(0, Bistre);
moveTo(100-10, 355);
beginFill(DarkBrown);
lineTo(100+10, 355);
lineTo(100+10, 395);
lineTo(100-10, 395);
lineTo(100-10, 355);
endFill();
lineStyle(0, DarkGreen);
for i := 0 to 4 do
begin
moveTo(100, 275-60*i);
beginFill(Green);
lineTo(100+80, 355-60*i);
lineTo(100-80, 355-60*i);
lineTo(100, 275-60*i);
endFill();
end;
end;

Matrix := TMatrix.Create;

Boules[0] := TBoule.Create('cell_0', 020+10, 355+10, DarkRed, 0);
Boules[1] := TBoule.Create('cell_0', 180-10, 355+10, DarkRed, 1);
Boules[2] := TBoule.Create('cell_0', 020+10, 295+10, DarkRed, 2);
Boules[3] := TBoule.Create('cell_0', 180-10, 295+10, DarkRed, 3);
Boules[4] := TBoule.Create('cell_0', 020+10, 235+10, DarkRed, 4);
Boules[5] := TBoule.Create('cell_0', 180-10, 235+10, DarkRed, 5);
Boules[6] := TBoule.Create('cell_0', 020+10, 175+10, DarkRed, 6);
Boules[7] := TBoule.Create('cell_0', 180-10, 175+10, DarkRed, 7);
Boules[8] := TBoule.Create('cell_0', 020+10, 115+10, DarkRed, 8);
Boules[9] := TBoule.Create('cell_0', 180-10, 115+10, DarkRed, 9);

Etoile := TEtoile.Create(nil, '', 10);
Etoile._x := 100;
Etoile._y := 20;
Etoile.tracerUneEtoile(4, 14, 8, Tangerine, Yellow);
end.```

 Code : Sélectionner tout - Visualiser dans une fenêtre à part
```123456789101112131415161718192021222324252627282930313233343536373839404142434445unit Etoile;

interface

uses
Flash8;

{ --- Extrait d'Etoile.fpr --------------------------------------------------- }

type
TEtoile = class(MovieClip)
procedure tracerUneEtoile(r1, r2, n, c1, c2: Integer);
end;

implementation

procedure TEtoile.tracerUneEtoile(r1, r2, n, c1, c2: Integer);
var
da : Double;
i : Integer;
a : Double;
r : Integer;
x,y : Double;
begin
da := Math.PI / n;
lineStyle(0, c1);
moveTo(r2, 0);
beginFill(c2);
for i := 1 to 2 * n do
begin
a := da * i;
if (i mod 2) = 0 then
r := r2
else
r := r1;
x := r * cos(a);
y := r * sin(a);
lineTo(x, y);
end;
endFill();
end;

{ --- Fin de l'extrait ------------------------------------------------------- }

end.```

2. Une version améliorée, avec un début d'animation.

3. J'ai amélioré le dessin de l'arbre, remplaçant les droites par des courbes.

J'ai ajouté aussi une variation dans l'allumage des boules.

4. Voici le dernier état de mon arbre de Noël.

 Code : Sélectionner tout - Visualiser dans une fenêtre à part
```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
{ ---------------------------------------------------------------------------- }
{ --- Arbre de Noël 2012 ----------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ --- FlashPascal 2 v12.07.07 ------------------------------------------------ }
{ ---------------------------------------------------------------------------- }

{\$FRAME_WIDTH 210}
{\$FRAME_HEIGHT 400}
{\$FRAME_RATE 3}
{\$BACKGROUND \$404040}

program Sapin;

uses
Flash8, Couleurs, Etoile;

{ --- tBoule (extrait modifié de FlashMine.fpr) ------------------------------ }

type
tBoule = class(MovieClip)
constructor Create(Name: string; x, y, c, d: Integer);
procedure IsBomb(color: Integer);
end;

tMatrix = class
matrixType: string;
x,y,w,h   : Double;
r         : Double;
constructor Create;
end;

constructor tBoule.Create(Name: string; x, y, c, d: Integer);
begin
inherited Create(nil, Name, d);
_x := x;
_y := y;
IsBomb(c);
end;

var
a    : Double;
c1,s1: Double;
c2,s2: Double;
r2   : Double;
begin
a := 3.14/4;
c1 := cos(a);
s1 := sin(a);
a := 3.14/8;
c2 := cos(a);
s2 := sin(a);
end;

var
Matrix: tMatrix;

procedure tBoule.IsBomb(color: Integer);
begin
lineStyle(0, color);
circle(8);
endFill;
end;

constructor tMatrix.Create;
begin
matrixType := 'box';
x := -4.5;
y := -4.5;
w := 6;
h := 6;
r := 0;
end;

{ --- tHorloge --------------------------------------------------------------- }

type
tHorloge = class(MovieClip)
time: integer;
constructor Create;
procedure onEnterFrame; override;
end;

var
a: array[0..9] of boolean;

procedure P1; var i: integer;
begin for i := 0 to 9 do if i  mod 2 = 0 then a[i] := TRUE else a[i] := FALSE;
end;
procedure P2; var i: integer;
begin for i := 0 to 9 do a[i] := not a[i];
end;
procedure P3(i: integer); var j: integer;
begin for j := 0 to 9 do if j = i then a[j] := TRUE else a[j] := FALSE;
end;
procedure P4; var i: integer;
begin for i := 0 to 9 do if i < 5 then a[i] := TRUE else a[i] := FALSE;
end;
procedure P5; var i: integer;
begin for i := 0 to 9 do if Random < 0.5 then a[i] := TRUE else a[i] := FALSE;
end;

constructor tHorloge.Create;
begin
inherited Create(_root, 'horloge', 12);
time := 0;
end;

var
Boules  : array[0..9] of tBoule;

procedure RedessineBoules;
var
i: integer;
begin
for i := 0 to 9 do if a[i] then
Boules[i].IsBomb(Orchid)
else
Boules[i].IsBomb(PersianBlue);
end;

procedure tHorloge.onEnterFrame;
begin
if time = 40 then time := 0;
case time div 10 of
0: begin
if time = 0 then P1;
P2;
end;
1: begin
P3(time mod 10);
end;
2: begin
if time = 20 then P4 else P2;
end;
3: begin
P5;
end;
end;
RedessineBoules;
Inc(time);
end;

{ --- tArbre ----------------------------------------------------------------- }

type
tArbre = class(MovieClip)
constructor Create(d: integer);
end;

constructor tArbre.Create(d: integer);
var
i: integer;
begin
inherited Create(_root, 'arbre', d);
lineStyle(2, DarkBrown);
moveTo(100-10, 355);
lineTo(100+10, 355);
{lineTo(100+10, 395);}
curveTo(100+5, 375, 100+10, 395);
lineTo(100-10, 395);
{lineTo(100-10, 355);}
curveTo(100-5, 375, 100-10, 355);
endFill();
lineStyle(2, DarkGreen);
for i := 0 to 4 do
begin
moveTo(100, 275-60*i);
beginFill(ForestGreen);
{lineTo(100+80, 355-60*i);
lineTo(100-80, 355-60*i);
lineTo(100, 275-60*i);}
curveTo(100+80-50, 355-60*i-30, 100+80, 355-60*i);
curveTo(100, 355-60*i+20, 100-80, 355-60*i);
curveTo(100-80+50, 355-60*i-30, 100, 275-60*i);
endFill();
end;
end;

{ --- Programme principal ---------------------------------------------------- }

var
Etoile: tEtoile;
Horloge: tHorloge;
Arbre: tArbre;

begin
Arbre := tArbre.Create(10);

Matrix := tMatrix.Create;

Boules[4] := tBoule.Create('b4', 020+10, 355+10, Violet, 0);
Boules[5] := tBoule.Create('b5', 180-10, 355+10, Violet, 1);
Boules[3] := tBoule.Create('b3', 020+10, 295+10, Violet, 2);
Boules[6] := tBoule.Create('b6', 180-10, 295+10, Violet, 3);
Boules[2] := tBoule.Create('b2', 020+10, 235+10, Violet, 4);
Boules[7] := tBoule.Create('b7', 180-10, 235+10, Violet, 5);
Boules[1] := tBoule.Create('b1', 020+10, 175+10, Violet, 6);
Boules[8] := tBoule.Create('b8', 180-10, 175+10, Violet, 7);
Boules[0] := tBoule.Create('b0', 020+10, 115+10, Violet, 8);
Boules[9] := tBoule.Create('b9', 180-10, 115+10, Violet, 9);

Etoile := tEtoile.Create(nil, '', 11);
Etoile._x := 100;
Etoile._y := 20;
Etoile.tracerUneEtoile(4, 14, 8, Tangerine, Yellow);

Horloge := tHorloge.Create;

stage.displayState := 'FullScreen';
end.

{ --- Fin du programme ------------------------------------------------------- }```

 Actualités F.A.Q PASCAL TUTORIELS EXERCICES SOURCES COMPILATEURS OUTILS LIVRES WIKI