From 4ec0c64ce7030fefa4304c33ed5a4d48ac78ef60 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Tue, 3 Apr 2018 05:36:11 +0000 Subject: net: Add loco.rkt. * net/ricketyspace/ror/five/loco.rkt: New file. * net/ricketyspace/ror/five/resources/caroille.png: New file. * net/ricketyspace/ror/five/resources/caroille.svg: New file. --- net/ricketyspace/ror/five/loco.rkt | 59 +++++++++++ net/ricketyspace/ror/five/resources/caroille.png | Bin 0 -> 886 bytes net/ricketyspace/ror/five/resources/caroille.svg | 125 +++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 net/ricketyspace/ror/five/loco.rkt create mode 100644 net/ricketyspace/ror/five/resources/caroille.png create mode 100644 net/ricketyspace/ror/five/resources/caroille.svg (limited to 'net/ricketyspace') diff --git a/net/ricketyspace/ror/five/loco.rkt b/net/ricketyspace/ror/five/loco.rkt new file mode 100644 index 0000000..977c976 --- /dev/null +++ b/net/ricketyspace/ror/five/loco.rkt @@ -0,0 +1,59 @@ +#lang racket +(require 2htdp/universe 2htdp/image) + +(define WIDTH 300) +(define HEIGHT 300) +(define CAROILLE (bitmap/file "resources/caroille.png")) +(define CAROILLE-WIDTH (image-width CAROILLE)) + +;;; +;;; If the car is placed at X = 1/2 its width, its back will be +;;; touching the left edge of the World. +;;; +;;; If the car is place at X = - 1/2 its width, its front will be touching +;;; the left edge of the World. +;;; +(define CAROILLE-WIDTH-HALF (/ CAROILLE-WIDTH 2.0)) + +;;; Structure to represent the X position of two cars in animation. +(struct cars (one two)) + +(define (caroille-past-right-edge? pos) + (> pos (- WIDTH CAROILLE-WIDTH-HALF))) + +(define (caroille-fully-past-right-edge? pos) + (>= pos (+ WIDTH CAROILLE-WIDTH-HALF))) + +(define (caroille-fully-past-left-edge? pos) + (>= pos CAROILLE-WIDTH-HALF)) + +(define (caroille-fully-inside? pos) + (and (caroille-fully-past-left-edge? pos) + (not (caroille-past-right-edge? pos)))) + +(define (move caroilles) + (let ((caroille-one (cars-one caroilles)) + (caroille-two (cars-two caroilles))) + (cond + ;; Case set I - one of the cars is fully inside. + ((caroille-fully-inside? caroille-one) + (cars (+ 1 caroille-one) caroille-two)) + ((caroille-fully-inside? caroille-two) + (cars caroille-one (+ 1 caroille-two))) + ;; Case set II - one of the cars disappeared into the right edge. + ((caroille-fully-past-right-edge? caroille-one) + (cars (- CAROILLE-WIDTH-HALF) (+ 1 caroille-two))) + ((caroille-fully-past-right-edge? caroille-two) + (cars (+ 1 caroille-one) (- CAROILLE-WIDTH-HALF))) + ;; Case else - Both cars are partially out. + (else (cars (+ 1 caroille-one) (+ 1 caroille-two)))))) + +(define (draw-cars caroilles) + (place-image CAROILLE (cars-one caroilles) (/ HEIGHT 2) + (place-image CAROILLE (cars-two caroilles) (/ HEIGHT 2) + (empty-scene WIDTH HEIGHT)))) + +(define (start) + (big-bang (cars CAROILLE-WIDTH-HALF (- CAROILLE-WIDTH-HALF)) + (on-tick move) + (to-draw draw-cars))) diff --git a/net/ricketyspace/ror/five/resources/caroille.png b/net/ricketyspace/ror/five/resources/caroille.png new file mode 100644 index 0000000..052cc58 Binary files /dev/null and b/net/ricketyspace/ror/five/resources/caroille.png differ diff --git a/net/ricketyspace/ror/five/resources/caroille.svg b/net/ricketyspace/ror/five/resources/caroille.svg new file mode 100644 index 0000000..eb4db63 --- /dev/null +++ b/net/ricketyspace/ror/five/resources/caroille.svg @@ -0,0 +1,125 @@ + + + + + caroille + + + + + + + + image/svg+xml + + caroille + + 2018-04-02 + + + rsiddharth <s@ricketyspace.net> + + + + + car + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3