;;methode directe:
(require (lib "draw.ss" "htdp"))
(require (lib "posn.ss" "lang"))


;;------------------------------------------------------------------------------

(define (toto x y) (+ x y))
(apply toto '( 1 2))
;;3


;;tableau statique!!
(define v (make-vector 3))
(vector-ref v 0)
(vector-set! v 0 1)
(vector-set! v 1 2)
(vector-set! v 2 3)
(vector-set! v 3 4)
;;vector-set!: index 3 out of range [0, 2] for vector: #3(1 2 3)

(define v3 (vector 1 2 3)) 


(define-struct toto (x y nomchamp))
(define t (make-toto 2 3 'abc))
(toto? t)
(toto-x t) 
(toto-y t) 
(toto-nomchamp t)
(set-toto-x! t 4) 
;t -> #(struct:toto 4 3 abc)


;;------------------------------------------------------------------------------
;; Exo 1: 
;;------------------------------------------------------------------------------


(define +xmin+ -4) (define +xmax+ 4)
(define +ymin+ -1.1) (define +ymax+ 8.5)
(define +largeur+ 500) (define +hauteur+ 500)


(define xrng (- +xmax+ +xmin+)) ; sera utile tout-à-l'heure.
(define yrng (- +ymax+ +ymin+))
;;     Ensuite, les dimensions de la fenêtre, et les fonctions de
;;     conversion :
(define xfact (/ +largeur+ xrng))  ; facteur de conversion
(define yfact (/ +hauteur+ yrng))
(define (xconv x)
  (* xfact (- x +xmin+))) ; Vérifiez que c'est correct
(define (yconv y)
  (* yfact (- +ymax+ y))) ; Y fenêtre va vers le bas


;;fonctions de conversion dont vous avez besoin: cours
(define (pconv x y)
  (make-posn (xconv x) (yconv y)))


;;hors cours
(define (posn-conv point)
  (let ((x (xconv (posn-x point)))
	(y (yconv (posn-y point))))
    (make-posn x y)))
	
;;fonction affichant un simple point
(define (posn-plot point)
  (draw-circle point 1))
		 
(start +largeur+ +hauteur+)

;;------------------------------------------------------------------------------

(define (intervalle a b n)
  (let ((h (/ (- b a) n)))
    (let echant ((x b) (tmp ()))
      (if (< x a) tmp
	  (echant (- x h) (cons x tmp))))))


(define (plot-cartesian-function3 nb-steps function-1)
  (let* ((xlist (intervalle +xmin+ +xmax+ nb-steps))
	 (ylist (map function-1 xlist))
	 (pointsvirtuels (map make-posn xlist ylist))
	 (pointsreels (map posn-conv pointsvirtuels)))
    (for-each posn-plot pointsreels)))
	 
(plot-cartesian-function3 50 (lambda (x) (* x x )))
  
;(segments: iteration,ou bien last/butlas
