#property strict //— width and height of the canvas (used for drawing) #define IMG_WIDTH 200 #define IMG_HEIGHT 200 //— display the parameter window before launching the script #property script_show_inputs //— enable to set color format input ENUM_COLOR_FORMAT clr_format=COLOR_FORMAT_XRGB_NOALPHA; //— drawing array (buffer) uint ExtImg[IMG_WIDTH*IMG_HEIGHT]; //+——————————————————————+ //| Script program start function | //+——————————————————————+ void OnStart() { //— create OBJ_BITMAP_LABEL object for drawing ObjectCreate(0,“CLOCK”,OBJ_BITMAP_LABEL,0,0,0); //— specify the name of the graphical resource for writing in CLOCK object ObjectSetString(0,“CLOCK”,OBJPROP_BMPFILE,“::IMG”); //— auxiliary variables double a; // arrow corner uint nm=2700; // minute corner uint nh=2700*12; // hour counter uint w,h; // variables for receiving text string sizes int x,y; // variables for calculation of the current coordinates of text string anchor points //— rotate clock hands in an infinite loop, till the script is stopped while(!IsStopped()) { //— clear the clock drawing buffer array ArrayFill(ExtImg,0,IMG_WIDTH*IMG_HEIGHT,0); //— set the font for drawing digits for the clock-face TextSetFont(“Arial”,-200,FW_EXTRABOLD,0); //— draw the clock-face for(int i=1;i<=12;i++) { //— receive the size of the current hour on the clock-face TextGetSize(string(i),w,h); //— calculate the coordinates of the current hour on the clock-face a=-((i*300)%3600*M_PI)/1800.0; x=IMG_WIDTH/2-int(sin(a)*80+0.5+w/2); y=IMG_HEIGHT/2-int(cos(a)*80+0.5+h/2); //— output the hour on the clock-face to ExtImg[] buffer TextOut(string(i),x,y,TA_LEFT|TA_TOP,ExtImg,IMG_WIDTH,IMG_HEIGHT,0xFFFFFFFF,clr_format); } //— now, specify the font for drawing the minute hand TextSetFont(“Arial”,-200,FW_EXTRABOLD,-int(nm%3600)); //— receive the size of the minute hand TextGetSize(“—–>”,w,h); //— calculate the coordinates of the minute hand on the clock-face a=-(nm%3600*M_PI)/1800.0; x=IMG_WIDTH/2-int(sin(a)*h/2+0.5); y=IMG_HEIGHT/2-int(cos(a)*h/2+0.5); //— output of the minute hand to the clock-face in ExtImg[]buffer TextOut(“—–>”,x,y,TA_LEFT|TA_TOP,ExtImg,IMG_WIDTH,IMG_HEIGHT,0xFFFFFFFF,clr_format); //— now, set the font for drawing the minute hand TextSetFont(“Arial”,-200,FW_EXTRABOLD,-int(nh/12%3600)); TextGetSize(“==>”,w,h); //— calculate the coordinates of the hour hand on the clock-face a=-(nh/12%3600*M_PI)/1800.0; x=IMG_WIDTH/2-int(sin(a)*h/2+0.5); y=IMG_HEIGHT/2-int(cos(a)*h/2+0.5); //— output of the hour hand on the clock-face to ExtImg[] buffer TextOut(“==>”,x,y,TA_LEFT|TA_TOP,ExtImg,IMG_WIDTH,IMG_HEIGHT,0xFFFFFFFF,clr_format); //— update the graphical resource ResourceCreate(“::IMG”,ExtImg,IMG_WIDTH,IMG_HEIGHT,0,0,IMG_WIDTH,clr_format); //— forced chart update ChartRedraw(); //— increase hour and minute counters nm+=60; nh+=60; //— keeping a short pause between the frames Sleep(10); } //— delete CLOCK object when completing the script’s operation ObjectDelete(0,“CLOCK”); //— } |