GDI+ Swiss Railway Clock v1.30 build 2024-01-25 [Windows only!]

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by srvaldez »

@dodicat
your clock compiles and runs ok on my Mac :-)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by dodicat »

All this clock topic.
I have been using a mobile phone for a few years as a timepiece.
So If I am out walking the dogs say, I have to pull out my phone, which I keep in a little protective cover, press the clear button, and read off the time.
So I decided to dig out an old watch.
Tissot Seastar Seven.
Automatic with a real spring and escapement, and it ticks.
It still works perfectly, (it should, it had a good long rest).
And see the price of this model on ebay today.
https://www.ebay.co.uk/itm/Used-Vintage ... SwDZlajwhN
But is much more aesthetically pleasing to use than a mobile phone.
And look at the way the mouse magnifies an image on Ebay.
Perhaps another freebasic challenge, to do this with a bitmap.
rough idea:

Code: Select all



function Clock as any ptr
    static as any ptr im
    static as integer blink
    Static As string LastTime
    dim as string t=time
    if LastTime<>t then'every second
        'do all this stuff only once per second:
        blink+=1
        LastTime=t
       if im then imagedestroy im:im=0
       im= imagecreate(210,210)
    #define map(a,b,x,c,d) ((d)-(c))*((x)-(a))/((b)-(a))+(c)
    #macro mod12(n,m)
    m= n Mod 12
    If m=0 Then m=12 
    #endmacro
    #macro lineto(x1,y1,x2,y2,d,col,flag)
   if flag then Line im,(x1,y1)-(x1+(x2-x1)*d,y1+(y2-y1)*d ),col
    catchx=x1+(x2-x1)*d:catchy=y1+(y2-y1)*d
    #endmacro
    #macro drawline(x,y,ang,length,col,x2,y2,flag)
    ang2=ang:ang2=ang2*.0174532925199433
    x2=(x)+length*Cos(ang2)
    y2=(y)-length*Sin(ang2)
    If flag Then Line im,(x,y)-(x2,y2),col
    #endmacro
    
    Dim As Integer m2,catchx,catchy
    Dim As Single b1,b2,tmp1,tmp2,ang2
    'Dim As String t=_time
    Dim As Integer hm=Valint(Left(t,2)),mm=Valint(Mid(t,4,2)),sm=Valint(Right(t,2))
    mod12(hm,m2)
    Dim As Single h=map(0,12,m2,360,0)
    Dim As Single m=map(0,60,mm,360,0)
    Dim As Single s=map(0,60,sm,360,0)
    For z As Integer=0 To 360 Step 6
        drawline((105),(105),z,100,15,b1,b2,0)
        'spots
        If z Mod 30=0 Then 
            lineto(b1,b2,(105),(105),.1,Rgb(200,0,0),1)  
            Circle im,(b1,b2),3,Rgb(100,100,255),,,,f 
        Else
            lineto(b1,b2,105,105,.05,Rgb(0,0,200),1)
            Circle im,(b1,b2),1,Rgb(0,0,100),,,,f 
        End If
        drawline(105,105,z,85,Rgb(0,0,0),b1,b2,0)
        Dim As Single n=map(360,0,(z-90),0,12)
        'numbers
        If z Mod 30=0 Then 
            mod12(n,m2)
            lineto(105,105,b1,b2,.9,0,0)
            Draw String im,(catchx-3,catchy-4),Str(m2),Rgb(0,200,0) 
        End If
    Next z
   if blink mod 2 then Draw String im,(105-20,105-45),"SMITHS",Rgb(255,100,0):blink=-1
    drawline(105,105,(h+90)-5*(360-m)/60,60,Rgb(100,0,100),tmp1,tmp2,1)'hour 
    drawline(105,105,(m+90)-(360-s)/60,85,Rgb(100,0,100),tmp1,tmp2,1)  'minute 
    drawline(105,105,(s+90),95,Rgb(100,100,100),tmp1,tmp2,1)             'second 
    Circle im,(105,105),3,Rgb(100,100,100),,,,f                  'centre 
end if'every second

 return im
End function


function resizeimage(im As Any Ptr,Wdth As Single,Hght as single,dx as long=0,dy as long=0) as any ptr
     #define putpixel(_x,_y,colour)    *cptr(ulong ptr,rowS+ (_y)*pitchS+ (_x) shl 2)  =(colour)
     #define _getpixel(_x,_y)           *cptr(ulong ptr,row + (_y)*pitch + (_x) shl 2)
     #define map(a,b,x,c,d) ((d)-(c))*((x)-(a))\((b)-(a))+(c)
    static As Integer pitch,pitchs
    static As Any Ptr row,rowS
    static As Ulong Ptr pixel,pixels
    static As Integer ddx,ddy,resultx,resulty
    Imageinfo im,ddx,ddy,,pitch,row
    dim as any ptr im2=imagecreate(Wdth-dx,Hght-dy)
    imageinfo im2,,,,pitchS,rowS
    For y As long=0+dy To Hght-1 -dy
         resulty=map(0,Hght,y,0,ddy)
        For x As long=0+dx To Wdth-1 -dx
            resultx=map(0,Wdth,x,0,ddx)
            putpixel(x,y,_getpixel(resultx,resulty))
        Next x
    Next y
    return im2
End function

screenres 1024,768,32
dim as any ptr i=imagecreate(300,300,rgb(255,255,255))

dim as long mx,my
do
    dim as any ptr i2=imagecreate(101,101)
    getmouse mx,my
    screenlock
    cls
    put(0,0),i
    var i3=clock
    put(50,50),i3,trans
    if mx>0 and mx<300 and my>0 and my<300 then
    if mx<50 then mx=50
    if my<50 then my=50
    if mx>250 then mx=250
    if my>250 then my=250
    get(mx-50,my-50)-(mx+50,my+50),i2
      i2=resizeimage(i2,600,600)
  put(330,0),i2
  end if
    screenunlock
    sleep 1,1
    imagedestroy i2
    loop until len(inkey)

Sleep
  
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by srvaldez »

very nice dodicat, everything works on my Mac.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by MrSwiss »

UEZ wrote:... x64 mode with all these API calls makes no real differences in speed.
Well, maybe not the run-speed, but certainly the start-up-speed (no need, to load *WOW first).
Therefore, I consider it to be, a rather lame excuse ...

*WOW = Windows 32 bit emulator (on x64 Windows)
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by UEZ »

MrSwiss wrote:
UEZ wrote:... x64 mode with all these API calls makes no real differences in speed.
Well, maybe not the run-speed, but certainly the start-up-speed (no need, to load *WOW first).
Therefore, I consider it to be, a rather lame excuse ...

*WOW = Windows 32 bit emulator (on x64 Windows)
You tell me that you will compile in x64 mode only to startup faster? Let's say to save some milliseconds, knowingly that you will not have a benefit in speed?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by MrSwiss »

UEZ wrote:You tell me that you will compile in x64 mode only to startup faster?
This isn't the main issue, it's the matter of staying current, with the mostly used OS's,
nowadays (future: probably 128 bit, without any longer 32 bit support) ...

Except for legacy purposes, all my stuff is nowadays by default, x64.
As 16 bits went out the Window (pun intended), 32 bits will (in time).

Call it a matter of principle ...
we don't any longer have HW restrictions, which may have necessitated 32 bits only.
The opposite is fact: 32 bit OS's restricting the use of availlable HW resources!
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by jj2007 »

MrSwiss wrote:*WOW = Windows 32 bit emulator (on x64 Windows)
It's not an emulator, it's a compatibility layer that translates 32-bit requests to the OS.
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: GDI+ Swiss Railway Clock v1.05 build 2018-03-01 [Windows only!]

Post by UEZ »

Little update: changed GUI to widget style. Just move the clock to a corner and watch from time to time the clock...

See post#1 for the code.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: GDI+ Swiss Railway Clock v1.05 build 2018-03-01 [Windows only!]

Post by deltarho[1859] »

You graphics guys astound me. I had a look under the bonnet. There is some awesome code there UEZ. Well done!
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: GDI+ Swiss Railway Clock v1.2 build 2018-03-04 [Windows only!]

Post by UEZ »

Last update for now. Windows size and position will be saved to an ini file.

See post#1 for the code.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: GDI+ Swiss Railway Clock v1.2 build 2018-03-04 [Windows only!]

Post by dodicat »

My bleeding Tissot Sea Star Seven watch stopped.
I am back to the mobile phone.
Thanks for the update.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by coderJeff »

UEZ, nice Swiss Railway Clock emulator. Though I admit, never saw one until now. Very nice animations.

Sorry, off-topic, but I want to respond to this:
jj2007 wrote:
MrSwiss wrote:*WOW = Windows 32 bit emulator (on x64 Windows)
It's not an emulator, it's a compatibility layer that translates 32-bit requests to the OS.
Take a look here:
https://msdn.microsoft.com/en-us/librar ... 84249.aspx
https://msdn.microsoft.com/en-us/librar ... 84274.aspx
Compatibility Layer = Emulation
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: GDI+ Swiss Railway Clock v1.0 build 2018-02-25 [Windows only!]

Post by jj2007 »

coderJeff wrote:Compatibility Layer = Emulation
Sorry that you feel obliged to respond. It is the kind of argument that can easily degenerate, so bear with me if I try to differentiate:

With WOW64, 32-bit applications run on their native cpu. There is no "emulation", it is the real thing, the bare metal. The only difference to a 64-bit application is that whenever the 32-bit application requires a service from the OS, i.e. calls a WinAPI, the call is being intercepted by the OS, and passed on to the respective 64-bit dll with slightly modified arguments.

An emulator is software that looks at each machine code instruction, and decides what to do with it. Examples are Steem, which makes an application believe that it runs on a 68000 cpu. Steem is roughly a factor 100 slower than the original, which is no problem because the original ran at 8 MegaHertz, and the modern host cpu runs at 2.x GigaHertz - go figure.

In contrast, my 32-bit software routinely beats 64-bit software running on the same identical hardware. It can do that because Wow64 is only a thin wrapper that redirects calls to the OS, an act that costs a few cycles only.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: GDI+ Swiss Railway Clock v1.2 build 2018-03-04 [Windows only!]

Post by MrSwiss »

@jj2007,

you are just hairsplitting, simply because:
  • whether it is SW only
  • or SW + HW
it stays, a emulation layer = EMULATOR

BTW: I prefer to rely on MS-Documentation rather than Wikipedia, at any time,
when it concerns a Microsoft operating system!
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: GDI+ Swiss Railway Clock v1.24 build 2018-04-03 [Windows only!]

Post by UEZ »

I made some small updates! If you are interested open post#1 and check it out.
Post Reply