Qbasicnews.com

Full Version: More circle trouble
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i am trying to make a program that keeps the time for a day and looks like a clock i have the clock but the counter that displays the time is not working so well here is my program:

'clock
cls
screen 12
paint (xscale, yscale), 15

line (200,0)-(200,400), 12 'y-axis
line (0,200)-(400,200), 12 'x-axis

for xpixel = 0 to 400 step 13 + (1/3)
xscale=(xpixel/20)-10
yscale = sqr(100-(xscale^2))
ypixel=20* (10-yscale)
circle (xpixel, ypixel),20,12
sleep 1
circle (xpixel,ypixel),20,15
timecount=0
if xscale <0 or xscale >0 then
timecount = timcount +1
end if
print timecount
next xpixel

this is then repeated so that it will go reverse
400 to 0 -13-(1/3) and ypixel=20* (10 + yscale)

the timer problem is that it only prints 1 everytime and doesnt hold count for every time the circle moves and if i put it outside the moving circle equation it only registers the last time the circle moved. If you could help me with that problem it would be great. Thanks
I had some trouble following what your code does.

If I were making a clock, I'd do this (pseudocode):

Code:
(draw a clock without hands on the screen)
DO
  (erase the hands)
  currenttime$ = TIME$
  (get hours% from currenttime$)
  (get minutes% from currenttime$)
  (get seconds% from currenttime$)
  (calculate how far around the circle the two hands should be)
  (draw the hands)
  SLEEP 1
LOOP UNTIL (they hit a key to exit)

You could also do this with TIMER instead of TIME$

Sorry. This probably doesn't answer your question at all.

*peace*

Meg.
Not exactly what you want, but this may be helpful. [syntax="QBASIC"]DEFINT A-Z
SCREEN 12
CONST Pi! = 3.141593

'Draw clock
WINDOW (-4, -3)-(4, 3) 'set coordinates system
CIRCLE (0, 0), 2.1, 7
FOR i! = 0 TO 2 * Pi! STEP (2 * Pi!) / 12
PointX! = SIN(i!) * 2.1
PointY! = COS(i!) * 2.1
CIRCLE (PointX!, PointY!), .05, 4
PAINT (PointX!, PointY!), 1, 4
NEXT

DO
IF TIME$ <> Oldtime$ THEN
WINDOW (-4, -3)-(4, 3) 'set coordinate system
Oldtime$ = TIME$
OldH = H%: OldM = M%: OldS = S%
H% = VAL(LEFT$(Oldtime$, 2))

M% = VAL(MID$(Oldtime$, 4, 2))
S% = VAL(RIGHT$(Oldtime$, 2))

'Delete old cursors
Angle! = (2 * Pi!) / 60 * (OldS%)
PointX! = SIN(Angle!) * 2
PointY! = COS(Angle!) * 2
LINE (0, 0)-(PointX!, PointY!), 0
Angle! = (2 * Pi!) / 60 * (S%)
PointX! = SIN(Angle!) * 2
PointY! = COS(Angle!) * 2
LINE (0, 0)-(PointX!, PointY!), 3
IF OldH% <> H% THEN
Angle! = (2 * Pi!) / 12 * (OldH%)
PointX! = SIN(Angle!) * 1.5
PointY! = COS(Angle!) * 1.5
LINE (0, 0)-(PointX!, PointY!), 0
END IF
IF OldM% <> M% THEN
'Draw Minute
Angle! = (2 * Pi!) / 60 * (OldM%)
PointX! = SIN(Angle!) * 2
PointY! = COS(Angle!) * 2
LINE (0, 0)-(PointX!, PointY!), 0
END IF
Angle! = (2 * Pi!) / 60 * (M%)
PointX! = SIN(Angle!) * 2
PointY! = COS(Angle!) * 2
LINE (0, 0)-(PointX!, PointY!), 2
Angle! = (2 * Pi!) / 12 * (H%)
PointX! = SIN(Angle!) * 1.5
PointY! = COS(Angle!) * 1.5
LINE (0, 0)-(PointX!, PointY!), 4
WINDOW 'reset coordinate system to normal
END IF

LOOP UNTIL INKEY$ > ""
[/syntax] I made this clock program a while ago. But what's important: In qbasic one fulle circle syscle is 2 * PI (6.28...) so this line should be helpful [syntax="QBASIC"]Angle! = (2 * Pi!) / 60 * (M%)[/syntax] Number 60 shows into how many equal parts to divide the circle and *(m%) shopws ont wich of these 60 part to go.

Well hope this will be of some help...
Thanks for trying but what i was trying to do was have it count everytime the smaller circle moves around a bigger invisible circle. this is sortof an independent project and my teacher told me to look into the "put" command to have it count all the ones i get together

to make this simple: i get 1,1,1,1,1,1,1...etc for every second i instead want 1,2,3,4,5,6,7...etc got it :???:
alright, here's code that spins a small circle around a big, invisible circle. each revolution gets counted.

This does NOT keep time. That part is up to you :) Let me know if this is helpful, and if you run into more problems.

Code:
SCREEN 12                'graphics mode: 640x480
CLS                      'clear the screen

counter& = 0             'counts the number of rotations
radius.center% = 100     'the radius of the "invisible" circle
radius.circle% = 10      'the radius of the spinning circle
color.circle% = 10       'the color to draw the circle

DO

'cycle through the 360 degrees of angles
FOR degree.angle% = 0 TO 359

     'convert angle from degrees to radians
     radian.angle! = degree.angle% * (3.14159# / 180)

     'calculate coordinates of circle
     circle.x% = 320 + radius.center% * SIN(radian.angle!)
     circle.y% = 240 - radius.center% * COS(radian.angle!)

     'draw the circle
     CIRCLE (circle.x%, circle.y%), radius.circle%, color.circle%

     'pause a moment
     FOR t& = 1 TO 10000: NEXT t&

     'erase the circle
     CIRCLE (circle.x%, circle.y%), radius.circle%, 0

NEXT degree.angle%

'increment the counter and display it
counter& = counter& + 1
LOCATE 1, 1: PRINT counter&;

'quit program when a key is hit
LOOP UNTIL INKEY$ <> ""

SYSTEM

*peace*

Meg.
Thank you very very much meg Big Grin Big Grin Big Grin