[ create a new paste ] login | about

Link: http://codepad.org/G648FyNP    [ raw code | fork ]

hurracane - Scheme, pasted on Jul 5:
;orig is the origin of the vector
;rotate-orig is the origin around which the rotation should happen
;alpha should be converted to radians first, because degrees are so much better but radians are expected
;returns the new position of the vector after rotation
(define (rotateVec alpha orig rotate-orig)
  (let ((old-x (getX orig))
        (old-y (getY orig))
        (rotate-x (getX rotate-orig))
        (rotate-y (getY rotate-orig))
        (radians (degrees->radians alpha)))
    (makeVec (+ (- (* (- old-x rotate-x) (cos radians))
                   (* (- old-y rotate-y) (sin radians)))
                rotate-x)
             (+ (+ (* (- old-x rotate-x) (sin radians))
                   (* (- old-y rotate-y) (cos radians)))
                rotate-y))))

(define (fill-rectangle-rotated! x y width height angle rotate-x rotate-y colour)
  (let* ((angle (- angle))
         (pos1 (makeVec x y))
         (pos2 (makeVec (+ x width) y))
         (pos3 (makeVec x (+ y height)))
         (pos4 (makeVec (+ x width) (+ y height)))
         (rotateOrig (makeVec rotate-x rotate-y))
         (pos1-rotated (rotateVec angle pos1 rotateOrig))
         (pos2-rotated (rotateVec angle pos2 rotateOrig))
         (pos3-rotated (rotateVec angle pos3 rotateOrig))
         (pos4-rotated (rotateVec angle pos4 rotateOrig)))
    
    ;the positions need to be fixed for the y-axis, because it's different with my-make-posn
    ((draw-solid-polygon MainWindow)
     (list (my-make-posn (getX pos3-rotated)
                         (- Pixels-y (getY pos3-rotated)))
           (my-make-posn (getX pos4-rotated)
                         (- Pixels-y (getY pos4-rotated)))
           (my-make-posn (getX pos2-rotated)
                         (- Pixels-y (getY pos2-rotated)))
           (my-make-posn (getX pos1-rotated)
                         (- Pixels-y (getY pos1-rotated))))
     (my-make-posn 0 0)
     (12bitColor2rgb colour))))


Output:
No errors or program output.


Create a new paste based on this one


Comments: