• Home
  • About
  • Contact
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
e electronic hub
  • Home
  • Electrical Work
  • Assignments
  • Programing
  • _C Language Programs
  • _ Assembly Programing
  • Projects
  • _Pic Microcontrollers
  • _Ic's Based Projects
  • _Arduino Projects
  • _Proteus Projects
  • Courses
  • _Machine

Categories

  • a single dimensional array (1)
  • Analog Clock Using Python (1)
  • Arduino Projects (3)
  • arduinoproject (1)
  • Assembly language programing (3)
  • Assignment (1)
  • Basic electronic project (1)
  • BCD to seven segment (1)
  • C language programing (2)
  • Clock (1)
  • Electrical Works (5)
  • First undertaking is about the utilization of LEDs use in PIC microcontroller utilizing C language Program. (1)
  • How to Create Analog Clock (1)
  • Ic 74LS47D Project (2)
  • Ic's Based Projects (3)
  • Implement the stack (1)
  • Implement the stack concept in a single dimensional array by executing C programs (1)
  • Interfacing LEDs with PIC microcontroller using MpLab and Proteus (1)
  • Interfacing LEDs with PIC microcontroller using PIC18F458 (1)
  • Investigation of Construction and Working of Elementary Generator (AC and DC) (1)
  • Machine (2)
  • mini project (1)
  • PIC Microcontrollers (1)
  • Programing (2)
  • project (1)
  • Projects (2)
  • Proteus Projects (2)
  • python based project (1)
  • python code (1)
  • python projects (1)
  • seven segment display (1)
  • To Analyze BCD to seven segment display decoder (1)
  • Top 50+ Basic Projects for Electrical and Electronic Engineering Students (1)
  • Working of Elementary Generator (AC and DC) (1)

About us

Welcome to e-Electronic Hub, your number one resource for everything Electrical Work, Software, E-Books, Solutions Manuals and Projects etc. We are dedicated to providing you the best electrical work, Software, E-books, solution Manuals And Projects, etc with an emphasis on awareness / lessons on the subject of electronics. Established in 2021 by R.H., e-Electronic Hub has come a long way in Pakistan since its inception. When R.H first started, His passion for electronics forced him to start his own business. We hope you enjoy our services as much as we enjoy offering them to you. If you have any questions or comments, please do not hesitate to contact us.

Total Pageviews

  • 20241
  • 20232
  • 20228
HomeAnalog Clock Using PythonHow to Create Analog Clock || Analog Clock Using Python

How to Create Analog Clock || Analog Clock Using Python

E Electronic Hub by R.H January 04, 2024

 

How to Create Analog Clock || Analog Clock Using Python


Code :

import pygame
from math import pi, cos, sin
import datetime
WIDTH, HEIGHT = 1120, 800
center = (WIDTH / 2, HEIGHT / 2)
clock_radius = 400
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Analog Clock")
clock = pygame.time.Clock()
FPS = 60
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)
def numbers(number, size, position):
  font = pygame.font.SysFont("Arial", size, True, False)
  text = font.render(number, True, BLACK)
  text_rect = text.get_rect(center=(position))
  screen.blit(text, text_rect)
def polar_to_cartesian(r, theta):
  x = r * sin(pi * theta / 180)
  y = r * cos(pi * theta / 180)
  return x + WIDTH / 2, -(y - HEIGHT / 2)
def main():
  run = True
  while run:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        run = False
    current_time = datetime.datetime.now()
    second = current_time.second
    minute = current_time.minute
    hour = current_time.hour
    name = 'Analog Clock With Date'
    name1 = 'Sub My Channel'
    name2 = 'Technical Rafi'
    day = current_time.day
    month = current_time.month
    year = current_time.year
    weekday = current_time.today().isoweekday()
    calendar = current_time.today().isocalendar()
    weekdays_abbr = {
        1: "Mo",
        2: "Tu",
        3: "We",
        4: "Th",
        5: "Fr",
        6: "Sa",
        7: "Su"
    }
    weekday_abbr = weekdays_abbr.get(weekday)
    months_abbr = {
        1: "JAN",
        2: "FEB",
        3: "MAR",
        4: "APR",
        5: "MAY",
        6: "JUN",
        7: "JUL",
        8: "AUG",
        9: "SEP",
        10: "OCT",
        11: "NOV",
        12: "DEC"
    }
    month_abbr = months_abbr.get(month)

    if day < 10:
      day = "0" + str(day)
    screen.fill(WHITE)
    pygame.draw.circle(screen, GREEN, center, clock_radius - 13, 13)
    pygame.draw.circle(screen, RED, center, clock_radius - 10, 10)
    pygame.draw.circle(screen, BLACK, center, 18)
    pygame.draw.circle(screen, RED, center, 12)
    pygame.draw.rect(screen, GREEN,
                     [WIDTH / 2 - 260, HEIGHT / 2 - 100, 80, 60], 5)
    pygame.draw.rect(screen, GREEN,
                     [WIDTH / 2 - 180, HEIGHT / 2 - 100, 80, 60], 5)
    pygame.draw.rect(screen, GREEN,
                     [WIDTH / 2 + 100, HEIGHT / 2 - 100, 80, 60], 5)
    pygame.draw.rect(screen, GREEN,
                     [WIDTH / 2 + 180, HEIGHT / 2 - 100, 80, 60], 5)
    pygame.draw.rect(screen, GREEN,
                     [WIDTH / 2 - 55, HEIGHT / 2 - 260 + 160, 110, 60], 5)
    pygame.draw.rect(screen, YELLOW,
                     [WIDTH / 2 - 185, HEIGHT / 2 - 70 + 160, 370, 120], 5)
    pygame.draw.rect(screen, RED,
                     [WIDTH / 2 - 270, HEIGHT / 2 - 130 + 160, 540, 60], 5)
    pygame.draw.rect(screen, RED,
                     [WIDTH / 2 - 270, HEIGHT / 2 - 270 + 160, 540, 80], 5)
    pygame.draw.rect(screen, YELLOW,
                     [WIDTH / 2 - 265, HEIGHT / 2 - 265 + 157, 530, 75], 5)

    numbers(str(weekday_abbr), 40, (WIDTH / 2 - 220, HEIGHT / 2 - 70))
    numbers(str(calendar[1]), 40, (WIDTH / 2 - 140, HEIGHT / 2 - 70))
    numbers(str(month_abbr), 40, (WIDTH / 2 + 140, HEIGHT / 2 - 70))
    numbers(str(day), 40, (WIDTH / 2 + 220, HEIGHT / 2 - 70))
    numbers(str(year), 40, (WIDTH / 2, HEIGHT / 2 - 230 + 160))
    numbers(str(name), 40, (WIDTH / 2, HEIGHT / 2 + 60))
    numbers(str(name1), 40, (WIDTH / 2, HEIGHT / 2 + 120))
    numbers(str(name2), 40, (WIDTH / 2, HEIGHT / 2 + 170))

    for number in range(1, 13):
      numbers(str(number), 80,
              polar_to_cartesian(clock_radius - 80, number * 30))

    for number in range(0, 360, 6):
      if number % 5:
        pygame.draw.line(screen, BLACK,
                         polar_to_cartesian(clock_radius - 15, number),
                         polar_to_cartesian(clock_radius - 30, number), 4)
      else:
        pygame.draw.line(screen, BLUE,
                         polar_to_cartesian(clock_radius - 15, number),
                         polar_to_cartesian(clock_radius - 35, number), 8)

    # Hour
    r = 250
    theta = (hour + minute / 60 + second / 3600) * (360 / 12)
    pygame.draw.line(screen, BLUE, center, polar_to_cartesian(r, theta), 14)

    # Minute
    r = 300
    theta = (minute + second / 60) * (360 / 60)
    pygame.draw.line(screen, BLACK, center, polar_to_cartesian(r, theta), 10)

    # Second
    r = 340
    theta = second * (360 / 60)
    pygame.draw.line(screen, RED, center, polar_to_cartesian(r, theta), 6)

    pygame.display.update()

    clock.tick(FPS)

  pygame.quit()

main()

Output :


WATCH NOW 

Analog Clock Using Python Arduino Projects arduinoproject Clock How to Create Analog Clock Programing project Projects python based project python code python projects
  • Newer

    How to Create Analog Clock || Analog Clock Using Python

  • Older

E Electronic Hub by R.H

Posted by E Electronic Hub by R.H

My name is R.H.I am from Pakistan.

You may like these posts

Post a Comment

0 Comments

Social Plugin

Translate

Popular Posts

Labels

  • a single dimensional array
  • Analog Clock Using Python
  • Arduino Projects
  • arduinoproject
  • Assembly language programing
  • Assignment
  • Basic electronic project
  • BCD to seven segment
  • C language programing
  • Clock
  • Electrical Works
  • First undertaking is about the utilization of LEDs use in PIC microcontroller utilizing C language Program.
  • How to Create Analog Clock
  • Ic 74LS47D Project
  • Ic's Based Projects
  • Implement the stack
  • Implement the stack concept in a single dimensional array by executing C programs
  • Interfacing LEDs with PIC microcontroller using MpLab and Proteus
  • Interfacing LEDs with PIC microcontroller using PIC18F458
  • Investigation of Construction and Working of Elementary Generator (AC and DC)
  • Machine
  • mini project
  • PIC Microcontrollers
  • Programing
  • project
  • Projects
  • Proteus Projects
  • python based project
  • python code
  • python projects
  • seven segment display
  • To Analyze BCD to seven segment display decoder
  • Top 50+ Basic Projects for Electrical and Electronic Engineering Students
  • Working of Elementary Generator (AC and DC)

Contact Form

Name

Email *

Message *

Labels

  • Arduino Projects (3)
  • Assembly language programing (3)
  • Assignment (1)
  • C language programing (2)
  • Electrical Works (5)
  • Ic's Based Projects (3)
  • PIC Microcontrollers (1)
  • Programing (2)
  • Projects (2)
  • Proteus Projects (2)

Most Recent

Tags

  • Arduino Projects (3)
  • Assembly language programing (3)
  • Assignment (1)
  • C language programing (2)
  • Electrical Works (5)
  • Ic's Based Projects (3)
  • PIC Microcontrollers (1)
  • Programing (2)
  • Projects (2)
  • Proteus Projects (2)

Categories

  • Arduino Projects (3)
  • Assembly language programing (3)
  • Assignment (1)
  • C language programing (2)
  • Electrical Works (5)
  • Ic's Based Projects (3)
  • PIC Microcontrollers (1)
  • Programing (2)
  • Projects (2)
  • Proteus Projects (2)

Most Popular

Footer Menu Widget

  • Home
  • About
  • Contact Us
Created By Blogspot Theme | Distributed By Gooyaabi Templates
Close Menu