Coder Social home page Coder Social logo

math_clock's Introduction

math_clock

An engaging clock face that shows math terms instead of the numbers themselves.
This project participates in the Flutter Clock challenge.

How to use

  • Clone the Flutter Clock GitHub repo. It contains several folders, including one named flutter_clock_helper.
  • In the root folder of the flutter clock repo, clone this repo into a folder named math_clock.
  • Now, you can run this Flutter project just like any other one.

How it works

Generating terms

Instead of numbers, this clock displays math terms with the operations + (Add), - (Subtract), * (Multiply), / (Divide), % (Modulo), ² (Squared), ³ (Cubed), (Root) and ! (Factorial).

Math terms are represented by a tree.

To turn the hour and minute numbers into math terms, we construct a tree consisting only of a number node. Then, it's made more complicated multiple times, each time choosing a random number node and complicating it.

For example, here's how a 2 might be turned into a more complicated math term:

2 │ 66 % 4 │ 66 % 2² │ (22 * 3) % 2²
  │        │         │ 
2 │   %    │   %     │     %
  │  / \   │  / \    │    / \
  │ 66  4  │ 66  ²   │   *   ²
  │        │     |   │  / \  |
  │        │     2   │ 22  3 2

See the math folder for more details.

Rendering terms

There's a TermWidget that can render a math term. It does so by expanding every math node into multiple widgets. By checking the types of the child nodes, it also inserts parenthesis where necessary.

Here's how the term tree from above is translated into widgets. For legibility, widgets created from the same math node are grouped together:

            ┌──────────────────────┐
            │      TermWidget      │
            │    (22 * 3) % 2²     │
            │                      │
            │     ModuloWidget     │
            │    (22 * 3) % 2²     │
            │                      │
            │_BinaryOperationWidget│
            │    (22 * 3) % 2²     │
            │                      │
            │  ParenthesisWidget   │
            │        22 * 3        │
            └──────────────────────┘
                 |             |
┌──────────────────────┐ ┌───────────────────────┐
│      TermWidget      │ │      TermWidget       │
│        22 * 3        │ │           2²          │
│                      │ │                       │
│    MultiplyWidget    │ │    MultiplyWidget     │
│        22 * 3        │ │           2²          │
│                      │ │                       │
│_BinaryOperationWidget│ │_PostfixOperationWidget│
│        22 * 3        │ │           2²          │
└──────────────────────┘ └───────────────────────┘
      |            |                 |
┌────────────┐ ┌────────────┐  ┌────────────┐
│ TermWidget │ │ TermWidget │  │ TermWidget │
│     22     │ │     3      │  │     2      │
│            │ │            │  │            │
│NumberWidget│ │NumberWidget│  │NumberWidget│
│     22     │ │     3      │  │     2      │
│            │ │            │  │            │
│ TightText  │ │ TightText  │  │ TightText  │
│     22     │ │     3      │  │     2      │
└────────────┘ └────────────┘  └────────────┘

math_clock's People

Contributors

marcelgarus avatar maryx avatar hixie avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

math_clock'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.