6 Replies - 599 Views - Last Post: 25 January 2013 - 04:33 AM Rate Topic: -----

#1 Volta500  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-January 13

Printing a circle in Console for clock

Posted 24 January 2013 - 04:18 AM

Hey all,

I am attempting to make an ASCII console clock that consists of three circles: outer and middle circle consists of 60 chars (1-60) for seconds and minutes, inner consists of 12 or 24 chars for hours.

For starters, I want to create an ascii circle. If that works, I think I could make the rest. Problem is, is that whatever I try I cant get a circle. It does not have to be perfect, as long as it looks acceptable.
Once an attempt seemed to try and make a circle but be way out of proportion, but since I kept trying that code is lost :(.

Right now there is not much left, but here it is anyways.

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <conio.h>

/*
*/

#ifndef PI
#define PI 3.14159265358979323846
#endif

HANDLE hOut;

int seconds, minutes, hours;

int main(void){
    hOut=GetStdHandle(STD_OUTPUT_HANDLE);
    int r;
    COORD outCoord;
	for(r=0;r<60;r++){
		outCoord.X=cos(r*PI/180*6);
		outCoord.Y=sin(r*PI/180*6);

		SetConsoleCursorPosition(hOut, outCoord);
		printf ("%i", r);
	}
	return 0;
}



C++ is an option but I have more experience with C, Although learning C++ is on my list.

Any input is welcome!
Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Printing a circle in Console for clock

#2 Volta500  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-January 13

Re: Printing a circle in Console for clock

Posted 24 January 2013 - 04:24 AM

Can't find edit button, so ill use a reply.

                      ,,ggddY""""Ybbgg,,
                 ,agd""'              `""bg,
              ,gdP"                       "Ybg,
            ,dP"                             "Yb,
          ,dP"         _,,ddP"""Ybb,,_         "Yb,
         ,8"         ,dP"'         `"Yb,         "8,
        ,8'        ,d"                 "b,        `8,
       ,8'        d"                     "b        `8,
       d'        d'        ,gPPRg,        `b        `b
       8         8        dP'   `Yb        8         8
       8         8        8)     (8        8         8
       8         8        Yb     dP        8         8
       8         Y,        "8ggg8"        ,P         8
       Y,         Ya                     aP         ,P
       `8,         "Ya                 aP"         ,8'
        `8,          "Yb,_         _,dP"          ,8'
         `8a           `""YbbgggddP""'           a8'
          `Yba                                 adP'
            "Yba                             adY"
              `"Yba,                     ,adP"'
                 `"Y8ba,             ,ad8P"'
                      ``""YYbaaadPP""''


Bit of a graphical representation of how it could look like. Chars here replaced with the numbers of the time of course, whith the current time in different color.
But maybe its a good idea to start with just one circle.

the int second, minutes, hours; on top of code is a remnant of an other try, you can ignore that.
Was This Post Helpful? 0
  • +
  • -

#3 Volta500  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-January 13

Re: Printing a circle in Console for clock

Posted 24 January 2013 - 09:18 AM

I got the circle! It still needs a lot of work but it at least its on its way.
Main problem now is to get the 0 at the top, and modify the size so it is possible to add a inner or outer ring around it for the minutes and seconds.

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <conio.h>

/*
*/


HANDLE hOut;

int main(void){
    int i,x,y;
    COORD coord1;
    SetConsoleTitle("Console Clock");
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordWindow = {100, 100};
    SMALL_RECT rec = {0,0,0,0};
    SetConsoleScreenBufferSize(hOut, coordWindow);
    rec.Right = coord.X -1;
    rec.Bottom = coord.Y -1;
    SetConsoleWindowInfo(hOut,TRUE,&rec);
    CONSOLE_CURSOR_INFO cci;
    cci.dwSize = 50;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo(hout, &cci);
    HWND hWnd = FindWindow(NULL, "Console Clock");
    HDC hdc = GetDC(hWnd);
    for(i = 1;i <61;i++){
        coord1.X = (int)(30* cos(6.4*i/61)+40);
        coord1.Y = (int)(20* sin(6.4*i/61)+25);
        SetConsoleCursorPosition(hOut,coord1);
        SetConsoleTextAttribute(hOut,15);
        printf("%i", i-1);
    }
    while (1){
        ;
    }
	return 0;
}



This is just a test but it does work!
Some tips would be greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 Volta500  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-January 13

Re: Printing a circle in Console for clock

Posted 24 January 2013 - 09:25 AM

It is really starting to annoy that there isn't an edit button.
There was a typo in the code, wich is fixed now. Lesson learnt: always compile before posting on forum. Especially if forum does not have edit button.

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <conio.h>

/*
*/

int main(void){
    int i,x,y;
    COORD coord1;
    SetConsoleTitle("Console Clock");
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordWindow = {100, 100};
    SMALL_RECT rec = {0,0,0,0};
    SetConsoleScreenBufferSize(hOut, coordWindow);
    rec.Right = coordwindow.X -1;
    rec.Bottom = coordwindow.Y -1;
    SetConsoleWindowInfo(hOut,TRUE,&rec);
    CONSOLE_CURSOR_INFO cci;

    cci.dwSize = 50;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo(hOut, &cci);
    HWND hWnd = FindWindow(NULL, "Console Clock");
    HDC hdc = GetDC(hWnd);
    for(i = 1;i <61;i++){
        coord1.X = (int)(30* cos(6.4*i/61)+40);
        coord1.Y = (int)(20* sin(6.4*i/61)+25);
        SetConsoleCursorPosition(hOut,coord1);
        SetConsoleTextAttribute(hOut,15);
        printf("%i", i-1);
    }
    while (1){
        ;
    }
	return 0;
}



This should work.

This post has been edited by jimblumberg: 24 January 2013 - 09:29 AM
Reason for edit:: Removed Duplicate text

Was This Post Helpful? 1
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon


Reputation: 4140
  • View blog
  • Posts: 12,891
  • Joined: 25-December 09

Re: Printing a circle in Console for clock

Posted 24 January 2013 - 09:30 AM

Quote

It is really starting to annoy that there isn't an edit button.

After you get a few more posts you will be able to edit your posts. Until then you can PM a moderator and ask them to help make the corrections.

Jim
Was This Post Helpful? 0
  • +
  • -

#6 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Printing a circle in Console for clock

Posted 24 January 2013 - 01:05 PM

Congrats on your circles! I haven't seen console circles that were any better, for sure.
Was This Post Helpful? 0
  • +
  • -

#7 Volta500  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 24-January 13

Re: Printing a circle in Console for clock

Posted 25 January 2013 - 04:33 AM

Got it working! Still needs a few little tweaks in the circle equations but other than that is darn near perfect.
For anyone interested in the code, here it is.
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <math.h>

int seconds, minutes, hours;
HANDLE hOut;

void timeWorker(void){
    time_t timer;
    struct tm *tm_p;
    timer = time(NULL);
    tm_p = localtime(&timer);
    seconds=tm_p->tm_sec;
    minutes=tm_p->tm_min;
    hours  =tm_p->tm_hour;
}

void printCicrleClock(int l1, int l2, int c1, int c2, float mult, int div, int activeColor, int inactiveColor, int time){
    int i;
    COORD coord;
    for(i = l1;i <l2;i++){
        coord.X = (int)(c1* cos(mult*i/div)+40);
        coord.Y = (int)(c2* sin(mult*i/div)+25);
        SetConsoleCursorPosition(hOut,coord);
        if (i-l1 == time){
            SetConsoleTextAttribute(hOut,activeColor);
        } else{
            SetConsoleTextAttribute(hOut, inactiveColor);
        }

        printf("%i", i-l1);
    }
}

int main(void){
    // local vars for main
    timeWorker();
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    int secOld, minOld, hourOld;
    // window settings
    SetConsoleTitle("Console Clock");
    SMALL_RECT rec = {0,0,79,50};
    SetConsoleWindowInfo(hOut,TRUE, &rec);
    // Cursor settings
    CONSOLE_CURSOR_INFO cci;
    cci.dwSize = 50;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo(hOut, &cci);
    // main loop
    while (1){
        timeWorker();
        if (minutes != minOld){
            printCicrleClock(47, 107, 30, 20, 6.4, 61, 13, 4, minutes);
            minOld=minutes;
        }
        if (hours != hourOld){
            printCicrleClock(19, 43, 25, 17, 6.3, 24, 11, 9, hours);
            hourOld=hours;
            Beep(1000,1000);
        }
        if (seconds != secOld){
            printCicrleClock(47, 107, 36, 24, 6.4, 61, 14 ,6,  seconds);
            COORD coord = {38, 23};
            SetConsoleCursorPosition(hOut, coord);
            printf("        ");
            SetConsoleCursorPosition(hOut, coord);
            printf("%i:%i:%i", hours, minutes, seconds);
            secOld=seconds;
        }
        Sleep(100);
    }
	return 0;
}


Oops something went wrong with the code tag [
If a mod could change that, I still don't have edit ability.

This post has been edited by baavgai: 25 January 2013 - 05:05 AM
Reason for edit:: tag fix service

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1