Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Procedure RotateImage(lImage,lImageTarget,lAngle.f);
  2.   Dim ImgArray(ImageWidth(lImage),ImageHeight(lImage));
  3.   Dim ImgWritten(ImageWidth(lImage),ImageHeight(lImage));
  4.  
  5.   ;Save first image to array
  6.   StartDrawing(ImageOutput(lImage));
  7.     DrawingMode(#PB_2DDrawing_AlphaChannel  );
  8.     For y=0 To ImageHeight(lImage)-1;
  9.       For x=0 To ImageWidth(lImage)-1;
  10.         ImgArray(x,y) = Point(x,y);
  11.       Next x;
  12.     Next y;
  13.   StopDrawing();
  14.  
  15.  
  16.   ; Initialisations
  17.   lTau.f = 6.28318531;
  18.   lAngle = lAngle*10;
  19.   s.f=Sin(lTau/3600*lAngle);
  20.   c.f=Cos(lTau/3600*lAngle);
  21.   mx=ImageWidth(lImage)/2;
  22.   my=ImageHeight(lImage)/2;
  23.   radius.f=Sqr(mx*mx + my*my)+1;
  24.  
  25.   ; Create target image if it doesn't exist
  26.   If ImageWidth(lImageTarget)=0;
  27.     CreateImage(lImageTarget,ImageWidth(lImage),ImageHeight(lImage),32);
  28.   EndIf;
  29.  
  30.   max=ImageWidth(lImageTarget);
  31.   may=ImageHeight(lImageTarget);
  32.  
  33.  
  34.   ; Draw to target image
  35.   StartDrawing(ImageOutput(lImageTarget));
  36.   DrawingMode(#PB_2DDrawing_AlphaChannel  );
  37.   Box(0,0,ImageWidth(lImage),ImageHeight(lImage),RGB(91,92,90));
  38.  
  39.   DrawingMode(#PB_2DDrawing_AlphaBlend );
  40.     For y=0 To ImageHeight(lImageTarget)-1;
  41.       For x=0 To ImageWidth(lImageTarget)-1;
  42.         RotateX.l = ((x - mx) * c - (y - my) * s) + mx;
  43.         RotateY.l = ((x - mx) * s + (y - my) * c) + my;
  44.        
  45.         If RotateX>0 And RotateX<max-1 And RotateY>0 And RotateY<may-1;
  46.           ImgWritten(RotateX,RotateY)=1;
  47.           color=ImgArray(x,y);
  48.          
  49.  
  50.           Plot(RotateX,RotateY,color);
  51.           If lAngle<>0 And lAngle<>90 And lAngle<>1800 And lAngle<>2700 And lAngle<>3600;
  52.             Plot(RotateX+1,RotateY,color);
  53.             Plot(RotateX,RotateY+1,color);
  54.           EndIf;
  55.         EndIf;
  56.       Next x;
  57.     Next y;
  58.    
  59.     lUndrawn = 0;
  60.     For y=1 To ImageHeight(lImage)-1;
  61.       For x=0 To ImageWidth(lImage)-1;
  62.         If ImgWritten(x,y) <> 1;
  63.           lUndrawn+1;
  64.           ImgWritten(x,y)=1;
  65.           ;Plot(x,y,Point(x,y-1));
  66.         EndIf;
  67.       Next x;
  68.     Next y;
  69.     Debug lUndrawn;
  70.   StopDrawing();
  71.  
  72.   ; Memory freeing
  73.   FreeArray(ImgArray());
  74.   FreeArray(ImgWritten());
  75. EndProcedure
  76.  
  77.  
  78. ; Drawing Procedures
  79. Procedure DrawClock();
  80.   lHour.l = Hour(lDate);
  81.   lMinute.l = Minute(lDate);
  82.  
  83.   lHour - 12;
  84.  
  85.   sTime.s = Str(lHour)+":"+Str(lMinute);
  86.  
  87.   lImageHour = CopyImage(#imgClockHour,#PB_Any);
  88.     RotateImage(#imgClockHour,lImageHour,180);
  89.   lImageMinute = CopyImage(#imgClockMinute,#PB_Any);
  90.     RotateImage(#imgClockMinute,lImageMinute,lMinute*6);
  91.  
  92.   CreateImage(#imgSkin,ImageWidth(#imgClockBackground),ImageHeight(#imgClockBackground),32);
  93.   StartDrawing(ImageOutput(#imgSkin));
  94.  
  95.       ; Set the background to be transparent
  96.       DrawingMode(#PB_2DDrawing_AlphaChannel );
  97.         Box(0,0,ImageWidth(#imgClockBackground),ImageHeight(#imgClockBackground)+35,RGBA(91,92,90,0));
  98.      
  99.       ; Start drawing
  100.       DrawingMode(#PB_2DDrawing_AlphaBlend );
  101.         ;DrawAlphaImage(ImageID(#imgClockBackground),0,0);
  102.         ;DrawAlphaImage(ImageID(lImageHour),0,0);
  103.         DrawAlphaImage(ImageID(lImageMinute),0,0);
  104.  
  105.      
  106.  
  107.     StopDrawing();
  108. EndProcedure;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement