Coder Social home page Coder Social logo

magicclock's Introduction

MagicClock

A simple, yet powerfull and easy modifiable analog clock for you website, made with pure Javascript

Magic-clock-showcase

class content:

constructor(PositionX, PositionY, width, theme = null)

parameters:

  • PositionX: x-coordinate of the left upper corner of the clock rectangle.

  • PositionY: y-coordinate of the left upper corner of the clock rectangle.

  • width: width(and height) of the clock rectangle.

  • theme(optional parameter): the theme object used to load the styling information of the clock. when left empty a default theme will be loaded automatically.

Example of use:

let theme={"secondHandColor" : "Blue" ,
 "minuteHandColor":"Green",
 "hourHandColor":"Red",
 "backgroundColor":"Yellow",
 "borderColor":"Yellow", 
 "timePointMarkerColor":"Green" ,
 "centralPointColor":"Blue" 
 };
 let myClock = new MagicClock( 0, 250 , 250, theme );
 

The styling system:

there are two styling options:

1. extrinsic styling system:

This styling system makes use of vector art in order to give our clock the desired look.

theme object structure:

extrinsicThemeObject = {
 "secondHandSrc" : [path to second hand image] ,
 "minuteHandSrc": [path to minute hand image],
 "hourHandSrc":  [path to hour hand image],
 "backgroundSrc":[path to background image],
 "handPivotHX": [float 0-1],
 "handPivotHY": [float 0-1],
 "handPivotMX": [float 0-1],
 "handPivotMY": [float 0-1],
 "handPivotSX": [float 0-1],
 "handPivotSY": [float 0-1]
 };

principle:

The main principle is, that there's a pivot point in the clock hand images. This pivot point must be mapped directly over the central point of the clock background. To achieve this we must know beforehand the relative position of this point within the image of the clock hand. For example, the image was 50px in width and 200px in height and the coordinates of the pivot was (25,100), i.e in the exact center of the image, then the relative pivot point in the theme settings will be (0.5, 0.5). If this hand was the second hand then the associated values will be handPivotSX and handPivotSY and thier values will be like this:

{
......
"handPivotSX": 0.5,
 "handPivotSY": 0.5
{

Values:

  • handPivotSY: a value that represents the ratio of the distance between the pivot point and the upper border of the second hand image to the total height of the second hand image.

  • handPivotSX: a value that represents the ratio of the distance between the pivot point and the left border of the second hand image to the total width of the second hand image.

  • handPivotMY: a value that represents the ratio of the distance between the pivot point and the upper border of the minute hand image to the total height of the minute hand image.

  • handPivotMX: a value that represents the ratio of the distance between the pivot point and the left border of the minute hand image to the total width of the minute hand image.

  • handPivotHY: a value that represents the ratio of the distance between the pivot point and the upper border of the hour hand image to the total height of the hour hand image.

  • handPivotHX: a value that represents the ratio of the distance between the pivot point and the left border of the hour hand image to the total width of the hour hand image.

here is a visual presentation of the extrinsic styling system:

2. intrinsic styling system:

intrinsic system is much simpler.

the theme structure of this system looks like this:

 theme={
 "secondHandColor" : [color value] ,
 "minuteHandColor":[color value],
 "hourHandColor": [color value],
 "backgroundColor": [color value],
 "borderColor": [color value], 
 "timePointMarkerColor": [color value] ,
 "centralPointColor": [color value] 
 }

magicclock's People

Contributors

alikifah avatar

Stargazers

 avatar

Watchers

 avatar

magicclock's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.