#lang scheme/gui

(require "Clases-neuron-capa-red.rkt")

;;;;;;;;;;;;;;INSTANCIAS
;;;NEURONAS
(define n_1 (make-object neuron_entrada% 'n_1))
(define n_2 (make-object neuron_entrada% 'n_2))
(define n_3 (make-object neuron_entrada% 'n_3))
(define n_4 (make-object neuron_entrada% 'n_4))

(define n_5 
  (make-object neurona%  'n_5
    4 propagacion_lineal lineal escalon_1))
(define n_6 
  (make-object neurona%  'n_6
    3 propagacion_lineal lineal escalon_1))
;;;CAPAS
(define capa_1 
  (make-object capa_entrada% 'c_1
    (list n_1 n_2 n_3 n_4) ))
(define capa_2 
  (make-object capa% 'c_2
    (list n_5 n_6) (list (list 1 1 1 1) (list -1 1 1 1))))
;;;RED
(define perceptron (make-object red% (list capa_1 capa_2)))

;;; Procedimientos de dibujo
(define pinta-capa
  (lambda (capa-output hoffset)
    (let ((voffset (/ 100 (length capa-output)))
          (hoffset hoffset))
    (let go ((data capa-output)
             (x hoffset)
             (y (/ voffset 2)) )
      (cond
        ((null? data) )
        ((= (car data) 1)
         (send dc set-brush brocha-roja)
         (send dc draw-ellipse x y 10 10);
         (go (cdr data) x (+ y voffset)))
        (else
         (send dc set-brush brocha-blanca)
         (send dc draw-ellipse x y 10 10)
         (go (cdr data) x (+ y voffset))) ) )) ))

;;;;;;;;;;;;;;;;;;
(define titulo " ")

;;; LAS HERRAMIENTAS
(define lapiz-azul
  (make-object pen%
    "blue"
    10
    'solid))

(define lapiz-rojo
  (make-object pen%
    "red"
    10
    'solid))

(define brocha-roja
  (make-object brush%
    "red"
    'solid))

(define brocha-blanca
  (make-object brush%
    "white"
    'solid))

;;; La ventana
(define ventana
  (make-object frame% 
    titulo
    #f
    110 150
    100 0))

;;; El lienzo

(define lienzo
  (instantiate canvas%
    (ventana)
    (style '(border))
    ))

(define dc (send lienzo get-dc))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; LA RED CON MONITOR
(define red-monitorizada%
  (class red%
    (inherit-field lista-capas)
    
    (define/public procesar!
      (lambda (input)
        (let go ((input input)
                 (capas lista-capas)
                 (hoffset 10) )
          (cond
            ((null? capas) input)
            (else
             (display input) (display "-->")
             (set! input (send (car capas) proceso! input))
             (pinta-capa input hoffset)
             (go input (cdr capas) (+ hoffset 30)) ) )) ))
    (super-new) ))
;;;;
(define perceptron-monitorizado (make-object red-monitorizada% (list capa_1 capa_2)))

(display "Input      = Capa 1  -->Capa 2") (newline)
(send ventana show #t)
(send perceptron-monitorizado procesar! '(1 1 1 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 1 1 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 1 0 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 1 0 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 0 1 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 0 1 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 0 0 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(1 0 0 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 1 1 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 1 1 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 1 0 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 1 0 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 0 1 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 0 1 0))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 0 0 1))
(sleep/yield 2)
(send perceptron-monitorizado procesar! '(0 0 0 0))