Programming a second hand piece of cheese

Anything QL Software or Programming Related.
User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Programming a second hand piece of cheese

Post by Mr_Navigator »

Yeh, I know the title is a little misleading, but what I want to do in the QL is similar to the countdown clock when you have 30 seconds to make the longest word from 9 characters.

A bit like this below but without the red arrow.

Image

So if anyone could point me in the direction of some simple SBASIC trigonometry in drawing the arced pie, or even just a second hand, then that would be helpful.


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: Programming a second hand piece of cheese

Post by Mr_Navigator »

So I found a basic routine that I have adapted to SuperBASIC and after much tinkering I have got this to work after a fashion as a clock with seconds minutes and hours displaying correctly. However all the pointers start at a quater past (3 o'clock) and I believe it is something to rotation starting at that point sine waves etc. My engineering days are long gone so I cannot remember nor fathom out how to correct this.
  • I need to start at 12 for all pointers is one,
    I would like to fix it to the system clock via DATE as a secondary pursuit.
    Then I can start to fiddle with the fill command
Can anyone help with the first point

Code: Select all

1000 CLS
1010 MODE 4 : WTV
1020 SCALE 275,-50,-40
1030 SECONDHAND = 80
1040 MINHAND = 65
1050 HOURHAND = 50
1060 OX = 100 : REMark CENTER OF THE CLOCK
1070 OY = 100
1080 RADIUS = 100
1090  REPeat LOOP
1100    FOR HourLoop= 6.2784 TO .10464 STEP -.5232   :REMark in radians
1110     FOR M = 6.2784 TO .10464 STEP -.10464
1120      FOR Sec = 6.2784 TO .10464 STEP -.10464
1130       FOR H2 = 0 TO 5.7552 STEP .5232           :REMark marks all
1140         S4X = OX + ((SECONDHAND + 10) * COS(H2)):REMark face
1150         S4Y = OY + ((SECONDHAND + 10) * SIN(H2)):REMark clock
1160         S5X = OX + ((SECONDHAND + 15) * COS(H2))
1170         S5Y = OY + ((SECONDHAND + 15) * SIN(H2))
1180         LINE S5X, S5Y TO S4X, S4Y
1190       NEXT H2
1200       FOR S2 = .10464 TO 6.2784 STEP .10464
1210        S2X = OX + ((SECONDHAND + 20) * COS(S2))
1220        S2Y = OY + ((SECONDHAND + 20) * SIN(S2))
1230        S3X = OX + ((SECONDHAND + 15) * COS(S2))
1240        S3Y = OY + ((SECONDHAND + 15) * SIN(S2))
1250        LINE S3X, S3Y TO S2X, S2Y
1260        CIRCLE OX, OY, 95
1270       NEXT S2
1280        SecX = OX + (SECONDHAND * COS(Sec))
1290        SecY = OY + (SECONDHAND * SIN(Sec))
1300        MinX = OX + (MINHAND * COS(M))
1310        MinY = OY + (MINHAND * SIN(M))
1320        HourX = OX + (HOURHAND * COS(HourLoop))
1330        HourY = OY + (HOURHAND * SIN(HourLoop))
1340        INK 4
1350        LINE OX, OY TO SecX, SecY      :REMark Second hand
1360        INK 7
1370        LINE OX, OY TO MinX, MinY  :REMark MINUTE hand
1380        CIRCLE MinX, MinY,5
1390        LINE OX, OY TO HourX, HourY    :REMark HOUR hand
1400        CIRCLE HourX, HourY, 5
1410        CIRCLE OX, OY, RADIUS
1420        CIRCLE OX, OY, RADIUS + 10
1430        INK 4
1440        CIRCLE OX, OY, 5
1450        REMark BEEP 50,200
1460        REMark PAUSE 10
1470        REMark CLS
1480        OVER -1
1490       NEXT Sec
1500      NEXT M
1510     NEXT HourLoop
1520   END REPeat LOOP
1530 :
1540 :
1550 DEFine PROCedure S
1560  SAVE flp5_Countdown_BAS
1570 END DEFine
1580 :
1590 :

Untitled-1.png
Untitled-1.png (9.29 KiB) Viewed 3997 times


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
User avatar
vanpeebles
Commissario Pebbli
Posts: 2821
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Programming a second hand piece of cheese

Post by vanpeebles »

Will you be having a super basic version of Rachel Riley too? :mrgreen:


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Programming a second hand piece of cheese

Post by RWAP »

Have a look at:
http://math.rice.edu/~pcmi/sphere/degrad.gif

The problem is that 12 o'clock is pi/2 - 3 o'clock on the clock face is 0 or pi*2

Because we are talking circles, you can use code such as the following:

Code: Select all

1000 CLS
1010 MODE 4 : WTV
1020 SCALE 275,-50,-40
1030 SECONDHAND = 80
1040 MINHAND = 65
1050 HOURHAND = 50
1060 OX = 100 : REMark CENTER OF THE CLOCK
1070 OY = 100
1080 RADIUS = 100
1090  REPeat LOOP
1100    FOR HourLoop= 6.2784 TO .10464 STEP -.5232   :REMark in radians
1110     FOR M = 6.2784 TO .10464 STEP -.10464
1120      FOR Sec = 6.2784 TO .10464 STEP -.10464
1125 realHourLoop = HourLoop+PI/2
1127 realM=M+PI/2
1128 realSec=Sec+PI/2
1130       FOR H2 = 0 TO 5.7552 STEP .5232           :REMark marks all
1140         S4X = OX + ((SECONDHAND + 10) * COS(H2)):REMark face
1150         S4Y = OY + ((SECONDHAND + 10) * SIN(H2)):REMark clock
1160         S5X = OX + ((SECONDHAND + 15) * COS(H2))
1170         S5Y = OY + ((SECONDHAND + 15) * SIN(H2))
1180         LINE S5X, S5Y TO S4X, S4Y
1190       NEXT H2
1200       FOR S2 = .10464 TO 6.2784 STEP .10464
1210        S2X = OX + ((SECONDHAND + 20) * COS(S2))
1220        S2Y = OY + ((SECONDHAND + 20) * SIN(S2))
1230        S3X = OX + ((SECONDHAND + 15) * COS(S2))
1240        S3Y = OY + ((SECONDHAND + 15) * SIN(S2))
1250        LINE S3X, S3Y TO S2X, S2Y
1260        CIRCLE OX, OY, 95
1270       NEXT S2
1280        SecX = OX + (SECONDHAND * COS(realSec))
1290        SecY = OY + (SECONDHAND * SIN(realSec))
1300        MinX = OX + (MINHAND * COS(realM))
1310        MinY = OY + (MINHAND * SIN(realM))
1320        HourX = OX + (HOURHAND * COS(realHourLoop))
1330        HourY = OY + (HOURHAND * SIN(realHourLoop))
1340        INK 4
1350        LINE OX, OY TO SecX, SecY      :REMark Second hand
1360        INK 7
1370        LINE OX, OY TO MinX, MinY  :REMark MINUTE hand
1380        CIRCLE MinX, MinY,5
1390        LINE OX, OY TO HourX, HourY    :REMark HOUR hand
1400        CIRCLE HourX, HourY, 5
1410        CIRCLE OX, OY, RADIUS
1420        CIRCLE OX, OY, RADIUS + 10
1430        INK 4
1440        CIRCLE OX, OY, 5
1450        REMark BEEP 50,200
1460        REMark PAUSE 10
1470        REMark CLS
1480        OVER -1
1490       NEXT Sec
1500      NEXT M
1510     NEXT HourLoop
1520   END REPeat LOOP
1530 :
1540 :
1550 DEFine PROCedure S
1560  SAVE flp5_Countdown_BAS
1570 END DEFine 
1580 :



RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Programming a second hand piece of cheese

Post by RWAP »

I also added:

Code: Select all

1085 clockDrawn = 0
1129 IF clockDrawn: GO TO 1280
1275 clockDrawn = 1
As thsi avoids redrawing the clock face every time!


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Programming a second hand piece of cheese

Post by RWAP »

WIthout a proper machine code paint routine having a complete circle that reduces is not easy (FILL won't work on certain shapes) - but if you run the routine once to draw the seconds on screen and then allow them to be removed on the next pass, that will give a good indication of time reducing...


User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: Programming a second hand piece of cheese

Post by Mr_Navigator »

RWAP wrote:WIthout a proper machine code paint routine having a complete circle that reduces is not easy (FILL won't work on certain shapes) - but if you run the routine once to draw the seconds on screen and then allow them to be removed on the next pass, that will give a good indication of time reducing...

Thanks, I have improved it thus and still working on it a bit at a time, visually it looks like this.
002.png
002.png (7.02 KiB) Viewed 3906 times
The next stage is the fill and I wont to achieve this without any screen refresh so I take on board your comments Rich.

Peebs, you're bad :lol:


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
Ralf R.

Re: Programming a second hand piece of cheese

Post by Ralf R. »

RWAP wrote:WIthout a proper machine code paint routine having a complete circle that reduces is not easy (FILL won't work on certain shapes) - but if you run the routine once to draw the seconds on screen and then allow them to be removed on the next pass, that will give a good indication of time reducing...
There are quite a few Toolkits, which have a separate "Paint" keyword. Perhaps this helps.


User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: Programming a second hand piece of cheese

Post by Mr_Navigator »

Well I have finished it and it works quite well in both modes with the standard Fill command as seen below.

003.png
003.png (3.57 KiB) Viewed 3887 times
Many thanks for the help guys, the final code is here feel free to use it in your own programs. You will need to adjust the speed by changing the pause statement in the for/end for loop depending on your QL/Emulator speed. It includes a little bit of sound too which does affect the timing a little.

Code: Select all

1000 CLS
1010 MODE 4
1020 SCALE 275,-50,-40
1030 SECONDHAND = 80
1040 OX = 100 : REMark CENTER OF THE CLOCK
1050 OY = 100
1060 RADIUS = 80
1065 INK 2
1070 :
1080 :
1090       FOR S2 = .10464 TO 6.2784 STEP .10464
1100         S2X = OX + ((SECONDHAND + 11) * COS(S2))
1110         S2Y = OY + ((SECONDHAND + 11) * SIN(S2))
1120         S3X = OX + ((SECONDHAND + 4) * COS(S2))
1130         S3Y = OY + ((SECONDHAND + 4) * SIN(S2))
1140         LINE S3X, S3Y TO S2X, S2Y
1150         CIRCLE OX, OY, RADIUS+10
1160       NEXT S2
1170 :
1180      INK 4
1190      REMark CIRCLE OX, OY, RADIUS
1200      INK 2
1210      CIRCLE OX, OY, RADIUS
1230 :
1250      FOR Sec = 1.5696 TO -1.5696 STEP -.10464
1252        PAUSE 40
1260        SecX = OX + (SECONDHAND * COS(Sec))
1270        SecY = OY + (SECONDHAND * SIN(Sec))
1280        LINE OX, OY TO SecX, SecY
1290        BEEP 20,5
1300         IF Sec< 1.5 THEN
1305          FILL 1
1310          LINE OX, OY TO SecX, SecY TO OldSecX, OldSecY TO OX, OY
1315          FILL 0
1320         END IF
1340        OldSecX = SecX : OldSecY = SecY
1350      END FOR Sec
1360      BEEP 10000,25,150,400,5,0,0
1370 :
1380 :
1390 DEFine PROCedure S
1400  SAVE flp5_Countdown_BAS
1410 END DEFine
1420 :
1430 :


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: Programming a second hand piece of cheese

Post by RWAP »

On q-emulator (at least) there are some oddities (blank pixels) around 20 seconds.

You cheated on the FILL command - you used just the first 30 seconds.... :lol: How about showing it for a minute?


Post Reply