Commit 48262cd3 authored by Nicaudie Charlotte's avatar Nicaudie Charlotte

Practical session of the 06/04

parent f2892642
......@@ -76,5 +76,6 @@ rule get_token = parse
(* Note : comments cannot be interlocked in Turtle *)
and comment = parse
| "*)" { get_token lexbuf }
| '\n' { newline lexbuf ; comment lexbuf}
| _ { comment lexbuf }
| eof { raise (Lexing_error ("unterminated comment")) }
\ No newline at end of file
......@@ -47,22 +47,23 @@ let () =
try
(* Parsing: la fonction Parser.prog transforme le tampon lexical en un
arbre de syntaxe abstraite si aucune erreur (lexicale ou syntaxique)
n'est détectée.
La fonction Lexer.token est utilisée par Parser.prog pour obtenir
le prochain token. *)
arbre de syntaxe abstraite si aucune erreur (lexicale ou syntaxique)
n'est détectée.
La fonction Lexer.token est utilisée par Parser.prog pour obtenir
le prochain token. *)
(*let p = Parser.prog Lexer.token buf in*)
Print_tokens.print stdout buf;
close_in f;
exit 0;
let p = Parser.program Lexer.get_token buf in
(*Print_tokens.print stdout buf;*)
close_in f;
(* On s'arrête ici si on ne veut faire que le parsing *)
if !parse_only then exit 0;
(*Interp.prog p*)
() (* = void *)
(* () = void *)
exit 0
with
| Lexer.Lexing_error c ->
(* Erreur lexicale. On récupère sa position absolue et
......
......@@ -58,9 +58,9 @@ stmt:
{ Translation (x, y) }
| ROTATION LPAREN x = FLOAT COMMA y = FLOAT COMMA theta = FLOAT RPAREN SEMICOLON
{ Rotation (x, y, theta) }
| s1 = stmt OR s2 = stmt weight = FLOAT
| BEGIN s1 = stmt OR LPAREN weight = FLOAT RPAREN s2 = stmt END
{ Or (s1, s2, weight) }
| ITER LPAREN it1 = INT COMMA it2 = INT RPAREN s = stmt
| ITER LPAREN it1 = INT COMMA it2 = INT RPAREN BEGIN s = stmt END
{ Iter (s, it1, it2) }
| BEGIN stmtList = stmt* END
{ StmtList stmtList }
......
(*
Sample code provided by Pascalou the Mr. Cooder
Thank you Pascalou <3
Sample code provided by Pascal the Mr. Cooder
Thank you Pascal <3
*)
init(0,1,0,1) # Starting position (x,y) in [0,1]*[0,1]
iter(10,100) {
{
translation(1, 0);
}
or
{
rotation(0.5, 0.5);
translation(1, 0);
or(0.5)
rotation(0.05, 0.5, 0.5);
}
}
\ No newline at end of file
......@@ -21,12 +21,14 @@ let MAX_SIZE = 20; // TODO rendre ceci paramétrable avec un %f
let MIN_SPEED = -7; // TODO rendre ceci paramétrable avec un %f
let MAX_SPEED = 7; // TODO rendre ceci paramétrable avec un %f
let ORIENTATION_X = 0;
let ORIENTATION_Y = 0;
// Ball constuctor
function Ball(x, y, velX, velY, color, size) {
this.x = x;
this.y = y;
this.velX = velX;
this.velY = velY;
function Ball(xPosition, yPosition, xOrientation, yOrientation, xVelocity, yVelocity, color, size) {
this.position = [xPosition, yPosition];
this.orientation = [xOrientation, yOrientation];
this.velocity = [xVelocity, yVelocity];
this.color = color;
this.size = size;
}
......@@ -35,27 +37,57 @@ function Ball(x, y, velX, velY, color, size) {
Ball.prototype.draw = function () {
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.arc(this.x, this.y, this.size, 0, 2*Math.PI);
ctx.arc(this.position[0], this.position[1], this.size, 0, 2*Math.PI);
ctx.fill();
}
Ball.prototype.update = function () {
if((this.x + this.size) >= width){
this.velX = -(this.velX);
if((this.position[0] + this.size) >= width){
this.velocity[0] = -(this.velocity[0]);
}
if((this.y + this.size) >= height){
this.velY = -(this.velY);
if((this.position[1] + this.size) >= height){
this.velocity[1] = -(this.velocity[1]);
}
if((this.x - this.size) <= 0){
this.velX = -(this.velX);
if((this.position[0] - this.size) <= 0){
this.velocity[0] = -(this.velocity[0]);
}
if((this.position[1] - this.size) <= 0){
this.velocity[1] = -(this.velocity[1]);
}
if((this.y - this.size) <= 0){
this.velY = -(this.velY);
this.position[0] += this.velocity[0];
this.position[1] += this.velocity[1];
}
Ball.prototype.translate = function (dx, dy) {
// TODO : Voir s'il faut faire une incrémentation
// progressive pour mieux observer le tracé de la ligne
this.position[0] += dx;
this.position[1] += dy;
if (this.position[0] > width) {
this.position[0] = width;
}
else if (this.position[0] < 0) {
this.position[0] = 0;
}
else if (this.position[1] > height) {
this.position[1] = height;
}
else if (this.position[1] < 0) {
this.position[1] = 0;
}
}
Ball.prototype.rotate = function (angle) {
let angleRadians = angle * Mathis.PI / 180;
let rotationMatrix = [[Math.cos(angleRadians), -Math.sin(angleRadians)],
[Math.sin(angleRadians), Math.cos(angleRadians)]];
this.x += this.velX;
this.y += this.velY;
//this.orientation[0] =
}
// Ball creation
......@@ -66,6 +98,8 @@ let ball = new Ball(
// random(0 + size, height - size),
STARTING_POSITION_X,
STARTING_POSITION_Y,
ORIENTATION_X,
ORIENTATION_Y,
random(MIN_SPEED,MAX_SPEED),
random(MIN_SPEED,MAX_SPEED),
'rgb(' + random(0,255) + ',' + random(0,255) + ',' + random(0,255) + ')',
......@@ -83,7 +117,40 @@ function loop() {
requestAnimationFrame(loop);
}
loop();
// Iter
function iter(minIter, maxIter) {
let nbIterations = random(minIter, maxIter);
for (let i = 0 ; i < nbIterations ; i++) {
// %a sur la stmt qui est dans Iter
}
}
// Or
function Or()
{
let orProbability = 0.5; // TODO : mettre % (this is the left-member's random weightening)a
let randomNb = random(0, 1);
if (randomNb < orProbability)
{
// Apply stmt1
}
else
{
// Apply stmt2
}
}
ctx.fillStyle = 'rgba(0,0,0,'+alpha+')';
ctx.fillRect(0,0,width, height);
ball.draw();
ball.update();
requestAnimationFrame(loop);
loop();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment