R o t a t i n g   G r a p h i c s   O b j e c t s 
 
 F o r   t h e   H P   P r i m e 
 
 E r w i n   R i e d 
 
 2 0 1 6 - 1 0 - 3 1 
 
 
 
 T o   r o t a t e   s o m e t h i n g ,   s i m p l e s t   w a y   i s   t o   u s e   a   t r a n s l a t i o n   m a t r i x   ( i . e .   w i t h   
 
 x y z   v e c t o r s ) .   O f   c o u r s e   y o u   c a n   u s e   a   s i m p l e r   f o r m   i f   y o u   d o n ' t   c o n s i d e r   t h e   
 
 a x i s   o f   t h e   r o t a t i o n   ( m a k e   i t   0 )   a n d   r e m o v e   z : 
 
 C o d e : 
 
 l o c a l   m a t : = [ [ c o s ( a n g l e ) , s i n ( a n g l e ) ] , [ - s i n ( a n g l e ) , c o s ( a n g l e ) ] ] ; 
 
 
 
 T h e   n e w   p o s i t i o n   o f   e v e r y   r o t a t e d   p i x e l   w i l l   b e   e q u a l   t o : 
 
 C o d e : 
 
 n e w p o s : = m a t * [ [ s o u r c e X ] , [ s o u r c e Y ] ] ; 
 
 
 
 W o r k i n g   c o d e : 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 R o t a t e G ( s o u r c e , d e s t i n a t i o n , a n g l e ) 
 
 B E G I N 
 
 D I M G R O B ( d e s t i n a t i o n , 3 2 0 , 2 4 0 ) ; 
 
 
 
 / /   R o t a t e   m a t r i x 
 
 l o c a l   t m p ; l o c a l   m a t : = [ [ c o s ( a n g l e ) , s i n ( a n g l e ) ] , [ - s i n ( a n g l e ) , c o s ( a n g l e ) ] ] ; 
 
 
 
 F O R   X   F R O M   0   T O   g r o b h ( s o u r c e )   D O 
 
 F O R   Y   F R O M   0   T O   g r o b w ( s o u r c e )   D O 
 
 t m p : = m a t * [ [ X ] , [ Y ] ] ; 
 
 P I X O N _ P ( d e s t i n a t i o n , X , Y , G E T P I X _ P ( s o u r c e , t m p ( 1 , 1 ) , t m p ( 2 , 1 ) ) ) ; 
 
 e n d ; 
 
 e n d ; 
 
 
 
 E N D ; 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 D e m o   o f   h o w   t o   u s e   c o d e : 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 E X P O R T   A b o u t E S P ( ) 
 
 B E G I N 
 
 R E C T ( ) ; 
 
 D I M G R O B _ P ( G 1 , 3 2 0 , 2 4 0 ) ; 
 
 R E C T _ P ( G 1 , R G B ( 2 5 5 , 2 5 5 , 2 5 5 ) ) ; 
 
 L I N E _ P ( G 1 , 0 , 1 9 7 , 3 2 0 , 5 0 , R G B ( 0 , 0 , 0 ) ) ; 
 
 L I N E _ P ( G 1 , 5 2 , 1 5 3 , 2 6 5 , 5 5 , R G B ( 4 0 , 2 2 0 , 1 7 0 ) ) ; 
 
 L I N E _ P ( G 1 , 5 7 , 1 6 5 , 4 4 , 1 3 7 , R G B ( 0 , 0 , 0 ) ) ; 
 
 L I N E _ P ( G 1 , 2 7 0 , 6 8 , 2 6 0 , 4 1 , R G B ( 0 , 0 , 0 ) ) ; 
 
 R E C T _ P ( G 1 , 0 , 0 , 3 2 0 , 2 6 , R G B ( 0 , 1 6 0 , 1 2 8 ) ) ; 
 
 T E X T O U T _ P ( " F i n d i n g   t h e   d i s t a n c e   b e t w e e n   2   p o i n t s . " , G 1 , 2 5 , 2 , 4 , R G B ( 2 5 5 , 2 5 5 , 2 5 5 ) ) ; 
 
 T E X T O U T _ P ( " ( S t r a i g h t   L i n e   K i t ) " , G 1 , 9 5 , 3 0 , 4 , R G B ( 2 5 5 , 2 5 5 , 2 5 5 ) ) ; 
 
 
 
 T E X T O U T _ P ( " ( x 1 , y 1 ) " , G 1 , 5 5 , 1 7 5 , 2 , R G B ( 0 , 0 , 0 ) ) ; 
 
 T E X T O U T _ P ( " ( x 2 , y 2 ) " , G 1 , 2 7 0 , 7 9 , 2 , R G B ( 0 , 0 , 0 ) ) ; 
 
 T E X T O U T _ P ( " %" , G 1 , 5 6 , 1 6 2 , 3 , R G B ( 2 5 5 , 0 , 0 ) ) ; 
 
 T E X T O U T _ P ( " %" , G 1 , 2 6 8 , 6 5 , 3 , R G B ( 2 5 5 , 0 , 0 ) ) ; 
 
 
 
 / /   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 D I M G R O B ( G 3 , 3 2 0 , 2 4 0 ) ;   / /   t e m p o r a l 
 
 T E X T O U T _ P ( " d i s t a n c e = ? " , G 3 , 6 0 , 1 3 0 , 5 , R G B ( 2 5 5 , 0 , 0 ) ) ; / / t h i s   o n e   I   n e e d   t o   r o t a t e . 
 
 R o t a t e G ( G 3 , G 2 , - 0 . 4 ) ;   / /   R o t a t e   0 . 4   r a d i a n s 
 
 B L I T _ P ( G 1 , G 2 , R G B ( 2 5 5 , 2 5 5 , 2 5 5 ) ) ;   / /   T r a n s p a r e n c y 
 
 / /   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 T R I A N G L E _ P ( G 1 , 2 5 5 , 5 7 , 2 5 7 , 6 1 , 2 6 6 , 5 4 , R G B ( 0 , 0 , 0 ) ) ; 
 
 T R I A N G L E _ P ( G 1 , 6 2 , 1 5 1 , 5 1 , 1 5 4 , 6 0 , 1 4 6 , R G B ( 0 , 0 , 0 ) ) ; 
 
 
 
 B L I T _ P ( G 0 , G 1 ) ; 
 
 F R E E Z E ; 
 
 E N D ; 
 
 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 O f   c o u r s e   t h i s   c o d e   i s   n o t   v e r y   e f f i c i e n t ,   y o u   m a y   c r o p   t h e   s o u r c e   t o   s i z e ,   
 
 a d d   t h e   " a x i s "   f o r   t h e   r o t a t i o n ,   e t c . . . 
 
 