OCaml > Rotate Ocaml

TitreRotate Ocaml
Postée le30-01-2008
Affichée1076
Mini-lien
Description

Rotation en Ocaml d'une image SDL

EtatInconnu. Inconnu.
Code d'insertion
Options
Afficher les numéros de lignes  Mettre la source en plein ecran  Selectionner la source  Partager sur Facebook 
Téléchargement Telecharger en format txt  Telecharger en format pdf
Plein ecran
let rotate src dst alpha =
 let (w,h,_) = Sdlvideo.surface_dims pic
  let halfWidth = w / 2 in
   let halfHeight = h / 2 in
    let cosv = int_to_float(cos( -(alpha) / ((180 / 3.14159265)))) in
     let sinv = int_to_float(sin( -(alpha) / ((180 / 3.14159265)))) in
      let x = ref 1 in
           let y = ref 1 in
            while !x < w do
                (while !y < h do
                 let xOr = ((x-halfWidth) * int_to_float(Maths.cos alpha) + ((y - halfHeight) * sinv + halfWidth)) in
                  let yOr = int_to_float((x-halfWidth) * (Maths.cos alpha) + ((y - halfHeight) * sinv + halfWidth)) in
               if (xOr >= 0 && yOr >= 0 && xOr < dst.Width && yOr < dst.Height)
            Sdlvideo.put_pixel_color dst !x !y (Sqlvideo.get_pixel_color src xOr yOr)
                   y := !y+1
                  done;
                  x := !x+1;)
                done;
   dst