Simple clock

For finished programs
Post Reply
udo
Posts: 6
Joined: Mon Sep 30, 2019 8:55 am

Simple clock

Post by udo » Mon Sep 30, 2019 5:34 pm

A version of a simple clock in BestBasic...

Code: Select all

' Clock
' U. Rabe, 2019
' Done with BestBasic
' It's public domain

' define some constants
scr size 600,600 	' def size of graphic screen
xm ym = 300,300		' center of screen	
r0 r1 r2 = 250,220,170	' radius: clock, large finger, small finger
m1 = -1 ' reminder for minutes
draw manual
draw size 15

do	'run clock
h m s = now|3
if m <> m1	
	m1 = m		
	draw clear 1,1,1	
	gosub print_clock_face	
	gosub draw_fingers			
	draw update
endif
redo

print_clock_face
' minutes dots
for i=0 to 60
	w = i*6 * PI/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc ym+x,ym+y,5
next i
' hours dots
for i=0 to 12
	w = i*30 * PI/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc ym+x,ym+y,10
next i
' central dot
draw fcirc xm,ym,20
return

draw_fingers
' hours
w = ((h+m/60)*30) * PI/180
x = r2 * sin(w)
y = r2 * cos(w)
draw line xm,ym,xm+x,ym-y
' minutes
w = (m*6) * PI/180
x = r1 * sin(w)
y = r1 * cos(w)
draw line xm,ym,xm+x,ym-y
return


User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Simple clock

Post by kibernetik » Mon Sep 30, 2019 5:42 pm

Cute and stylish clock!

Currently this program consumes 100% of CPU. I will add a function to minimize CPU consumption in such 'slow' applications.

udo
Posts: 6
Joined: Mon Sep 30, 2019 8:55 am

Re: Simple clock

Post by udo » Mon Sep 30, 2019 5:54 pm

That would be nice.
BestBasic is a really nice interpreter.
It remembers me of working with a WANG 2200 at about 1975!
https://en.wikipedia.org/wiki/Wang_2200

Regards

Udo

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Simple clock

Post by kibernetik » Mon Sep 30, 2019 5:58 pm

Thank you for your comment! :)

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Simple clock

Post by kibernetik » Tue Oct 01, 2019 3:58 am

Ok, this function is called CPU RELAX. It can be used like this:

Code: Select all

...
endif
cpu relax
goto run_clock
...

udo
Posts: 6
Joined: Mon Sep 30, 2019 8:55 am

Re: Simple clock

Post by udo » Tue Oct 01, 2019 6:45 am

And it works...

Code: Select all

do	'run clock
h m s = now|3
if m <> m1	
	m1 = m		
	draw clear 1,1,1	
	gosub print_clock_face	
	gosub draw_fingers			
	draw update
endif
cpu relax
redo

User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Simple clock

Post by Dutchman » Tue Oct 01, 2019 12:43 pm

With seconds, showing more activity:

Code: Select all

' Clock
' U. Rabe, 2019
' Done with BestBasic
' It's public domain
' seconds added by Ton Nillesen

' define some constants
scr size 600,600 	' def size of graphic screen
xm ym = 300,300		' center of screen	
r0 r1 r2 = 250,220,170	' radius: clock, large finger, small finger
m1 = -1 ' reminder for minutes
draw manual
draw size 15

do	'run clock
h m s = now|3
if s <> s1	
	s1 = s	
	draw clear 1,1,1	
	gosub print_clock_face	
	gosub draw_fingers			
	draw update
endif
'CPU RELAX ' not in versio 1.2
redo

print_clock_face
' minutes dots
for i=0 to 60
	w = i*6 * PI/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc ym+x,ym+y,5
next i
' hours dots
for i=0 to 12
	w = i*30 * PI/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc ym+x,ym+y,10
next i
' central dot
draw fcirc xm,ym,20
return

draw_fingers
' hours
w = ((h+m/60)*30) * PI/180
x = r2 * sin(w)
y = r2 * cos(w)
draw line xm,ym,xm+x,ym-y
' minutes
w = (m*6) * PI/180
x = r1 * sin(w)
y = r1 * cos(w)
draw line xm,ym,xm+x,ym-y
' seconds
DRAW COLOR 1,0,0
DRAW SIZE 4
w = (s*6) * PI/180
x = r0 * sin(w)
y = r0 * cos(w)
draw line xm-x/8,ym+y/8,xm+x,ym-y
DRAW FCIRC xm,ym,8
DRAW COLOR 0,0,0
DRAW SIZE 15
return
.
with seconds.JPG
with seconds.JPG (22.35 KiB) Viewed 314 times
It is still a long way to go

udo
Posts: 6
Joined: Mon Sep 30, 2019 8:55 am

Re: Simple clock

Post by udo » Tue Oct 01, 2019 7:05 pm

Nice! Thank You!

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: Simple clock

Post by kibernetik » Wed Oct 02, 2019 1:56 am

Smooth minute hand movement, minor adjustments.

Code: Select all

' Clock
' U. Rabe, 2019
' Done with BestBasic
' It's public domain
' seconds added by Ton Nillesen

' define some constants
scr size 600,600       ' def size of graphic screen
xm ym = 300,300        ' center of screen
r0 r1 r2 = 250,220,170 ' radius: clock, large finger, small finger
d1 d2 = 5,10           ' radius: minute dots, hour dots
draw manual

do	'run clock
h m s = now|3
if s<>s1
	s1 = s	
	draw clear 1,1,1	
	gosub print_clock_face	
	gosub draw_fingers			
	draw update
endif
cpu relax
redo

print_clock_face
draw color 0,0,0
' hours dots
for i=1 to 12
	w = i*30 * PI/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc ym+x,ym+y,d2
next i
' minutes dots
for i=1 to 60
	w = i*6 * PI/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc ym+x,ym+y,d1
next i
' central dot
draw fcirc xm,ym,20
return

draw_fingers
draw color 0,0,0
draw size 15
' hours
w = ((h+m/60)*30) * PI/180
x = r2 * sin(w)
y = r2 * cos(w)
draw line xm,ym,xm+x,ym-y
' minutes
w = (m*6+s/10) * PI/180
x = r1 * sin(w)
y = r1 * cos(w)
draw line xm,ym,xm+x,ym-y
' seconds
draw color 1,0,0
draw size 4
w = (s*6) * PI/180
x = (r0-d2*2) * sin(w)
y = (r0-d2*2) * cos(w)
draw line xm-x/8,ym+y/8,xm+x,ym-y
' central seconds dot
draw fcirc xm,ym,8
return
Без названия.jpg
Без названия.jpg (34.09 KiB) Viewed 308 times

udo
Posts: 6
Joined: Mon Sep 30, 2019 8:55 am

Re: Simple clock

Post by udo » Wed Oct 02, 2019 12:53 pm

This is version 2 with changes...

Code: Select all

' Clock
' version 2.0
' U. Rabe, 2019
' Done with BestBasic
' It's public domain
' seconds added by Ton Nillesen
' adde some proposals by kibernetik
' some optical changes, U. Rabe

' define some constants
scr size 600,600 	' def size of graphic screen
xm ym = 300,300		' center of screen	
r0 r1 r2 = 250,220,170	' radius: clock, large finger, small finger
d1 d2 = 5,10 	' diameter face dots
s1 = -1 ' reminder for seconds
draw manual

do	'run clock
h m s = now|3
if s <> s1	
	s1 = s	
	draw clear 0.9,0.9,0.9	
	gosub print_clock_face	
	gosub draw_fingers	
	draw update
endif
cpu relax
redo

print_clock_face
draw size 1
draw color 0.6,0.6,0.6
' minutes dots
for i=0 to 60
	w = i*6 * pi/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc xm+x,ym+y,d1
next i
draw color 0.3,0.3,0.3
' hours dots
for i=0 to 12
	w = i*30 * pi/180
	x = r0 * sin(w)
	y = r0 * cos(w)
	draw fcirc xm+x,ym+y,d2
next i
return

draw_fingers
draw color 0,0,0
' central dot
draw fcirc xm,ym,20
draw size 12
' hours
w = ((h+m/60)*30) * pi/180
x = r2 * sin(w)
y = r2 * cos(w)
draw line xm,ym,xm+x,ym-y
' minutes
w = ((m+s/60)*6) * pi/180
x = r1 * sin(w)
y = r1 * cos(w)
draw line xm,ym,xm+x,ym-y
' seconds
draw size 4
w = (s*6) * pi/180
x = (r0-d2*2) * sin(w)
y = (r0-d2*2) * cos(w)
draw color 1,0,0
draw line xm-x/8,ym+y/8,xm+x,ym-y
draw fcirc xm,ym,8
return
clock.png
clock.png (33.54 KiB) Viewed 300 times

Post Reply