Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EJ 2)
- (define (dist-origen n) (sqrt (+ (expt (posn-x n) 2) (expt (posn-y n) 2) )) )
- EJ 3)
- (define ANCHO 400)
- (define ALTO 200)
- (define RADIO 20)
- (define DELTA 10)
- (define INICIAL (make-posn (/ ANCHO 2) (/ ALTO 2) ) )
- (define (pantalla n) (place-image (circle RADIO "solid" "magenta") (posn-x n) (posn-y n) (empty-scene ANCHO ALTO)) )
- (define (mover n tecla) (cond
- [(and (key=? tecla "up") (>= (posn-y n) (+ RADIO DELTA)) ) (make-posn (posn-x n) (- (posn-y n) DELTA) )]
- [(and (key=? tecla "down") (<= (posn-y n) (- ALTO (+ RADIO DELTA))) ) (make-posn (posn-x n) (+ (posn-y n) DELTA) )]
- [(and (key=? tecla "left") (>= (posn-x n) (+ RADIO DELTA)) ) (make-posn (- (posn-x n) DELTA) (posn-y n))]
- [(and (key=? tecla "right") (<= (posn-x n) (- ANCHO (+ RADIO DELTA))) ) (make-posn (+ (posn-x n) DELTA) (posn-y n))]
- [(key=? tecla " ") INICIAL]
- [else n]))
- (define (mouse-handler n x y event) (cond [(string=? event "button-down") (make-posn x y)]
- [else n]))
- (big-bang INICIAL
- [to-draw pantalla]
- [on-key mover]
- [on-mouse mouse-handler]
- )
- EJ 4)
- (define ANCHO 700)
- (define ALTO 350)
- (define MOSCA .)
- (define TEXTO (text "MOSCA ATRAPADA" 60 "red") )
- (define ALTO_MOSCA (/ (image-height MOSCA) 2))
- (define ANCHO_MOSCA (/ (image-width MOSCA) 2))
- (define DELTA 20)
- (define GAMMA 50)
- (define INICIAL (make-posn (/ ANCHO 2) (/ ALTO 2) ) )
- (define FINAL (make-posn -1 -1) )
- (define (elegir-random a b) (if (= (random 2) 1) a b))
- (define (distancia_click n click) (sqrt (+ (expt (- (posn-x n) (posn-x click)) 2) (expt (- (posn-y n) (posn-y click) ) 2) )))
- (define (pantalla n) (if (= (posn-x n) -1) (place-image TEXTO (/ ANCHO 2) (/ ALTO 2) (empty-scene ANCHO ALTO)) (place-image MOSCA (posn-x n) (posn-y n) (empty-scene ANCHO ALTO)) ))
- (define (LIMITAR_X x) (cond [(< x ANCHO_MOSCA) ANCHO_MOSCA]
- [(> x (- ANCHO ANCHO_MOSCA)) (- ANCHO ANCHO_MOSCA)]
- [else x]) )
- (define (LIMITAR_Y y) (cond [(< y ALTO_MOSCA) ALTO_MOSCA]
- [(> y (- ALTO ALTO_MOSCA)) (- ALTO ALTO_MOSCA)]
- [else y]) )
- (define (MOVERSE_EN_X n) (if (string=? (elegir-random "Izquierda" "Derecha") "Izquierda") (LIMITAR_X (- (posn-x n) DELTA)) (LIMITAR_X (+ (posn-x n) DELTA)) ) )
- (define (MOVERSE_EN_Y n) (if (string=? (elegir-random "Arriba" "Abajo") "Arriba") (LIMITAR_Y (- (posn-y n) DELTA)) (LIMITAR_Y (+ (posn-y n) DELTA)) ) )
- (define (moverse n) (let ([EleccionX (elegir-random "Quedarse" "Moverse")]
- [EleccionY (elegir-random "Quedarse" "Moverse")])
- (cond
- [(and (string=? EleccionX "Moverse") (string=? EleccionY "Moverse") ) (make-posn (MOVERSE_EN_X n) (MOVERSE_EN_Y n))]
- [(and (string=? EleccionX "Moverse") (string=? EleccionY "Quedarse") ) (make-posn (MOVERSE_EN_X n) (posn-y n))]
- [(and (string=? EleccionX "Quedarse") (string=? EleccionY "Moverse") ) (make-posn (posn-x n) (MOVERSE_EN_Y n))]
- [else n]
- ) ) )
- (define (clickear n x y event) (if (and (string=? event "button-down") (<= (distancia_click n (make-posn x y)) GAMMA )) FINAL n))
- (define (terminar n) (if (= (posn-x n) -1) #t #f))
- (big-bang INICIAL
- [to-draw pantalla]
- [on-mouse clickear]
- [on-tick moverse]
- [stop-when terminar]
- )
- EJ 5)
- (define AUTO .);Puntito porque Pastebin es choto
- (define LARGO_AUTO (/ (image-width AUTO) 2))
- (define DIST_MIN (+ LARGO_AUTO 5) )
- (define VEL_INICIAL 3)
- (define-struct auto [hpos vel])
- (define INICIAL (make-auto DIST_MIN VEL_INICIAL))
- (define LARGO 600)
- (define ALTO 100)
- (define ESCENA_BLANCA (empty-scene LARGO ALTO))
- (define (pantalla n) (place-image AUTO (auto-hpos n) (/ ALTO 2) ESCENA_BLANCA) )
- (define (incrementar n) (if(<= (auto-hpos n) (- LARGO DIST_MIN (auto-vel n) )) (make-auto (+ (auto-hpos n) (auto-vel n)) (auto-vel n) ) n ) )
- (define (teclado n tecla) (cond [(key=? tecla " ") INICIAL]
- [(and (key=? tecla "right") (< (auto-hpos n) (- LARGO DIST_MIN)) ) (make-auto (+ (auto-hpos n) 20) (auto-vel n) ) ]
- [(and (key=? tecla "left") (> (auto-hpos n) (+ 20 DIST_MIN)) ) (make-auto (- (auto-hpos n) 20) (auto-vel n) )]
- [(key=? tecla "up") (make-auto (auto-hpos n) (+ (auto-vel n) 1) )]
- [(and (key=? tecla "down") (> (auto-vel n) 0)) (make-auto (auto-hpos n) (- (auto-vel n) 1) )]
- [else n] ) )
- (define (clickear n x y evento) (cond [(and (string=? evento "button-down") (> x DIST_MIN) (< x (- LARGO DIST_MIN) ) ) (make-auto x (auto-vel n))]
- [else n]))
- (big-bang INICIAL
- [to-draw pantalla]
- [on-tick incrementar]
- [on-key teclado]
- [on-mouse clickear]
- )
- EJ 6)
- (define ANCHO 800)
- (define ALTO 60)
- (define FONDO (empty-scene ANCHO ALTO) )
- (define-struct texto [s color tam])
- (define COLOR1 "indigo")
- (define COLOR2 "blue")
- (define COLOR3 "red")
- (define COLOR4 "green")
- (define COLOR5 "orange")
- (define COLOR6 "black")
- (define TAM_INICIAL 20)
- (define INICIAL (make-texto "" COLOR1 TAM_INICIAL) )
- (define (mostrar_texto n) (place-image/align (text (texto-s n) (texto-tam n) (texto-color n)) 0 0 "left" "top" FONDO ) )
- (define (Agregar n tecla) (make-texto (string-append (texto-s n) tecla) (texto-color n) (texto-tam n) ))
- (define (Quitar_Uno n) (make-texto (substring (texto-s n) 0 (- (string-length (texto-s n)) 1) ) (texto-color n) (texto-tam n)) )
- (define (Cambiar_Color n color) (make-texto (texto-s n) color (texto-tam n) ) )
- (define (Agrandar n) (make-texto (texto-s n) (texto-color n) (+ (texto-tam n) 1) ) )
- (define (Achicar n) (make-texto (texto-s n) (texto-color n) (- (texto-tam n) 1) ) )
- (define (agregar_caracter n tecla) (cond
- [(key=? tecla " ") (Agregar n tecla)]
- [(and (char-alphabetic? (string-ref tecla 0)) (= (string-length tecla) 1)) (Agregar n tecla)]
- [(and (char-numeric? (string-ref tecla 0)) (= (string-length tecla) 1)) (Agregar n tecla)]
- [(and (key=? tecla "\b") (> (string-length (texto-s n)) 0) ) (Quitar_Uno n) ]
- [(key=? tecla "f1") (Cambiar_Color n COLOR1)]
- [(key=? tecla "f2") (Cambiar_Color n COLOR2)]
- [(key=? tecla "f3") (Cambiar_Color n COLOR3)]
- [(key=? tecla "f4") (Cambiar_Color n COLOR4)]
- [(key=? tecla "f5") (Cambiar_Color n COLOR5)]
- [(key=? tecla "f6") (Cambiar_Color n COLOR6)]
- [(and (key=? tecla "up") (< (texto-tam n) 60 ) ) (Agrandar n)]
- [(and (key=? tecla "down") (> (texto-tam n) 1 ) ) (Achicar n)]
- [else n]) )
- (big-bang INICIAL
- [to-draw mostrar_texto]
- [on-key agregar_caracter]
- )
- ; #YouCantSeeMe #MyTimeIsNow
Add Comment
Please, Sign In to add comment