[BB] Create Analog Clock

Started by Filax, March 09, 2025, 21:28:42

Previous topic - Next topic

Filax

; ----------------------------------------
; Name : Create Analog Clock
; Date : (C)2025
; Site : https://github.com/BlackCreepyCat
; ----------------------------------------

Graphics 800,600,0,2 ; Définit la fenêtre graphique
SetBuffer BackBuffer() ; Utilise le double buffering

; Définition du Type Horloge
Type Horloge
    Field x#, y#        ; Position du centre
    Field rayon#        ; Rayon de l'horloge
End Type

; Création d'une instance d'horloge
Global monHorloge.Horloge = New Horloge
monHorloge\x# = 400
monHorloge\y# = 300
monHorloge\rayon# = 200

; Boucle principale
While Not KeyHit(1) ; Jusqu'à ce que ESC soit pressé
    Cls ; Efface l'écran
    DessinerHorloge(monHorloge) ; Dessine l'horloge
    Flip ; Affiche le rendu
Wend
End

Function DessinerHorloge(h.Horloge)
    ; Variables pour l'heure actuelle
    Local heures# = Float(Hour())
    Local minutes# = Float(Minute())
    Local secondes# = Float(Second())
   
    ; Dessiner le cercle de l'horloge
    Color 255,255,255 ; Blanc
    Oval h\x#-h\rayon#, h\y#-h\rayon#, h\rayon#*2, h\rayon#*2, 0 ; Cercle vide
   
    ; Dessiner les marques des heures (12 principales)
    For i = 0 To 11
        Local angle# = i * 30 - 90 ; 30° par heure, -90° pour commencer à 12h
        Local x1# = h\x# + Cos(angle#) * (h\rayon# * 0.9) ; Point intérieur
        Local y1# = h\y# + Sin(angle#) * (h\rayon# * 0.9)
        Local x2# = h\x# + Cos(angle#) * h\rayon# ; Point extérieur
        Local y2# = h\y# + Sin(angle#) * h\rayon#
        Line x1#, y1#, x2#, y2#
    Next
   
    ; Aiguille des heures (plus courte)
    Color 255,0,0 ; Rouge
    Local angleHeures# = (heures + minutes/60.0) * 30 - 90
    Local longueurHeures# = h\rayon# * 0.5
    Line h\x#, h\y#, h\x# + Cos(angleHeures#) * longueurHeures#, h\y# + Sin(angleHeures#) * longueurHeures#
   
    ; Aiguille des minutes (moyenne)
    Color 0,255,0 ; Vert
    Local angleMinutes# = (minutes + secondes/60.0) * 6 - 90
    Local longueurMinutes# = h\rayon# * 0.8
    Line h\x#, h\y#, h\x# + Cos(angleMinutes#) * longueurMinutes#, h\y# + Sin(angleMinutes#) * longueurMinutes#
   
    ; Aiguille des secondes (fine et longue)
    Color 0,0,255 ; Bleu
    Local angleSecondes# = secondes * 6 - 90
    Local longueurSecondes# = h\rayon# * 0.9
    Line h\x#, h\y#, h\x# + Cos(angleSecondes#) * longueurSecondes#, h\y# + Sin(angleSecondes#) * longueurSecondes#
   
    ; Centre de l'horloge
    Color 255,255,255
    Oval h\x#-5, h\y#-5, 10, 10, 1 ; Petit cercle plein
End Function

; Fonctions système Blitz3D pour obtenir l'heure
Function Hour%()
    Local time$ = CurrentTime$()
    Return Int(Mid$(time$, 1, 2)) ; Extrait les 2 premiers chiffres (heures)
End Function

Function Minute%()
    Local time$ = CurrentTime$()
    Return Int(Mid$(time$, 4, 2)) ; Extrait les chiffres 4-5 (minutes)
End Function

Function Second%()
    Local time$ = CurrentTime$()
    Return Int(Mid$(time$, 7, 2)) ; Extrait les chiffres 7-8 (secondes)
End Function

PixelOutlaw

You might take a screenshot, upload it to something like imgur then paste that so people who can't run your source can see the effect. :)
One DEFUN to rule them all, One DEFUN to find them, One DEFUN to RETURN them all, and in the darkness MULTIPLE-VALUE-BIND them.

Filax

Quote from: PixelOutlaw on March 10, 2025, 02:29:35You might take a screenshot, upload it to something like imgur then paste that so people who can't run your source can see the effect. :)

Yeah i know, but the screenshot import from github do not work on the forum. The image diseapear after few hours. You say that imgur is ok ?

PixelOutlaw

#3
Hmmm some of the forums images show up, others they don't. Very odd.
You can just provide the raw link like so I guess.
https://imgur.com/a/7FJbIgU

I was able to post an image in this (somewhat of a necropost) oddly enough. Wonder if it's just this forum.
https://www.syntaxbomb.com/others/maze-in-lisp/msg347064519/#msg347064519
One DEFUN to rule them all, One DEFUN to find them, One DEFUN to RETURN them all, and in the darkness MULTIPLE-VALUE-BIND them.

Midimaster

#4
It is easy to add images or screenshots to your posts here in the Syntaxbomb forum
Example: your image:

AddImageToSyntaxB.png
These are the steps:

1.
Do not use the (already open) text box "Quick Reply", but use the Button "REPLY". You will now get a text input field, that shows the text "Click or drag files here to attach them".

2.
If your image is an online image, first save it now local on your computer. Or make a screenshot and save this local on your computer

3.
Click on the sentence "Click or drag files here to attach them" .

4.
Now search for the image on your computer and add it as attachment to your post.

5.
Move the cursor to the text line where you want to display the image.

6.
In the attachment you now see a thumbnail of your image. Click on the little arrow (right top corner)

Here is an example image:

AddImageToSyntax.png

7.
in the popup box click on the button INSERT. No need to adjust width or height

...back from North Pole.

Filax

Oh! Thanks for the information, i don't take attention to the text line... It's the problem when you have 54 years! You become blind :) :)