September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
21
Task/Draw-a-clock/BASIC/draw-a-clock-2.basic
Normal file
21
Task/Draw-a-clock/BASIC/draw-a-clock-2.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
100 PROGRAM "Clock.bas"
|
||||
110 OPTION ANGLE DEGREES
|
||||
120 LET CH=1:LET CH2=2
|
||||
130 SET VIDEO MODE 1:SET VIDEO COLOR 1:SET VIDEO X 26:SET VIDEO Y 25
|
||||
140 OPEN #1:"video:"
|
||||
150 OPEN #2:"video:"
|
||||
160 DO
|
||||
170 LET H=VAL(TIME$(1:2)):LET M=VAL(TIME$(4:5)):LET S=VAL(TIME$(7:))
|
||||
180 SET #CH:INK 3:PLOT #CH:420,420,ANGLE 90-30*H-M/2;FORWARD 200
|
||||
190 PLOT #CH:420,420,ANGLE 90-6*M;FORWARD 350
|
||||
200 SET #CH:INK 2:PLOT #CH:420,420,ANGLE 90-6*S;FORWARD 300
|
||||
210 SET #CH:INK 1:PLOT #CH:420,420,ELLIPSE 12,12,ELLIPSE 400,400
|
||||
230 PLOT #CH:394,812,:PRINT #CH:"12":PLOT #CH:784,434,:PRINT #CH:"3"
|
||||
240 PLOT #CH:406,58,:PRINT #CH:"6":PLOT #CH:28,434,:PRINT #CH:"9"
|
||||
250 DISPLAY #CH:AT 1 FROM 1 TO 25
|
||||
260 CLEAR #CH2
|
||||
270 LET T=CH:LET CH=CH2:LET CH2=T
|
||||
280 LOOP UNTIL INKEY$=CHR$(27)
|
||||
290 CLOSE #2
|
||||
300 CLOSE #1
|
||||
310 TEXT
|
||||
64
Task/Draw-a-clock/Forth/draw-a-clock.fth
Normal file
64
Task/Draw-a-clock/Forth/draw-a-clock.fth
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
HEX
|
||||
8379 CONSTANT TICKER \ address of 1/60 second counter
|
||||
|
||||
CREATE PDT ( -- addr) \ bit pattern descriptors for 0..9 and colon
|
||||
0038 , 444C , 5464 , 4438 , ( 0)
|
||||
0010 , 3010 , 1010 , 1038 , ( 1)
|
||||
0038 , 4404 , 1820 , 407C , ( 2)
|
||||
007C , 0810 , 0804 , 4438 , ( 3)
|
||||
0008 , 1828 , 487C , 0808 , ( 4)
|
||||
007C , 4078 , 0404 , 4438 , ( 5)
|
||||
0038 , 4040 , 7844 , 4438 , ( 6)
|
||||
007C , 0408 , 1020 , 2020 , ( 7)
|
||||
0038 , 4444 , 3844 , 4438 , ( 8)
|
||||
0038 , 4444 , 3C04 , 0438 , ( 9)
|
||||
0000 , 3030 , 0030 , 3000 , ( :)
|
||||
|
||||
: ]PDT ( 0..9 -- addr) [CHAR] 0 - 8 * PDT + ;
|
||||
|
||||
: BIG.TYPE ( caddr len -- )
|
||||
8 0
|
||||
DO
|
||||
CR
|
||||
2DUP BOUNDS
|
||||
?DO
|
||||
I C@ ]PDT J + C@ \ PDT char, byte# J
|
||||
2 7 DO \ from bit# 7 to 2
|
||||
DUP 1 I LSHIFT AND \ mask out each bit
|
||||
IF [char] * EMIT \ if true emit a character
|
||||
ELSE SPACE \ else print space
|
||||
THEN
|
||||
-1 +LOOP DROP
|
||||
LOOP
|
||||
LOOP
|
||||
2DROP ;
|
||||
|
||||
DECIMAL
|
||||
|
||||
CREATE SECONDS 0 , 0 , \ 2 CELLS, holds a double integer
|
||||
|
||||
: SECONDS++ ( -- ) SECONDS 2@ 1 M+ SECONDS 2! ;
|
||||
|
||||
\ subtract old value from new value until ticker changes.
|
||||
: 1/60 ( -- )
|
||||
TICKER DUP @ ( -- addr value)
|
||||
BEGIN
|
||||
PAUSE \ *Gives time to other Forth processes while we wait
|
||||
OVER @ \ read ticker addr
|
||||
OVER - \ subtract from old value
|
||||
UNTIL
|
||||
2DROP ;
|
||||
|
||||
: SEXTAL ( -- ) 6 BASE ! ;
|
||||
: 1SEC ( -- ) 60 0 DO 1/60 LOOP SECONDS++ ;
|
||||
: ##: ( -- ) # SEXTAL # DECIMAL [CHAR] : HOLD ;
|
||||
: .TIME ( d --) <# ##: ##: # # #> BIG.TYPE ;
|
||||
|
||||
: CLOCK ( -- )
|
||||
DECIMAL \ set task's local radix
|
||||
BEGIN
|
||||
1SEC
|
||||
0 0 AT-XY SECONDS 2@ .TIME
|
||||
?TERMINAL
|
||||
UNTIL
|
||||
2DROP ;
|
||||
83
Task/Draw-a-clock/Julia/draw-a-clock.julia
Normal file
83
Task/Draw-a-clock/Julia/draw-a-clock.julia
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using Gtk, Colors, Graphics, Dates
|
||||
|
||||
const radius = 300
|
||||
const win = GtkWindow("Clock", radius, radius)
|
||||
const can = GtkCanvas()
|
||||
push!(win, can)
|
||||
|
||||
global drawcontext = []
|
||||
|
||||
function drawline(ctx, l, color)
|
||||
isempty(l) && return
|
||||
p = first(l)
|
||||
move_to(ctx, p.x, p.y)
|
||||
set_source(ctx, color)
|
||||
for i = 2:length(l)
|
||||
p = l[i]
|
||||
line_to(ctx, p.x, p.y)
|
||||
end
|
||||
stroke(ctx)
|
||||
end
|
||||
|
||||
function clockbody(ctx)
|
||||
set_coordinates(ctx, BoundingBox(0, 100, 0, 100))
|
||||
rectangle(ctx, 0, 0, 100, 100)
|
||||
set_source(ctx, colorant"yellow")
|
||||
fill(ctx)
|
||||
set_source(ctx, colorant"blue")
|
||||
arc(ctx, 50, 50, 45, 45, 360)
|
||||
stroke(ctx)
|
||||
for hr in 1:12
|
||||
radians = hr * pi / 6.0
|
||||
drawline(ctx, [Point(50 + 0.95 * 45 * sin(radians),
|
||||
50 - 0.95 * 45 * cos(radians)),
|
||||
Point(50 + 1.0 * 45 * sin(radians),
|
||||
50 - 1.0 * 45 * cos(radians))], colorant"blue")
|
||||
end
|
||||
end
|
||||
|
||||
Gtk.draw(can) do widget
|
||||
ctx = getgc(can)
|
||||
if length(drawcontext) < 1
|
||||
push!(drawcontext, ctx)
|
||||
else
|
||||
drawcontext[1] = ctx
|
||||
end
|
||||
clockbody(ctx)
|
||||
end
|
||||
|
||||
function update(can)
|
||||
dtim = now()
|
||||
hr = hour(dtim)
|
||||
mi = minute(dtim)
|
||||
sec = second(dtim)
|
||||
if length(drawcontext) < 1
|
||||
return
|
||||
end
|
||||
ctx = drawcontext[1]
|
||||
clockbody(ctx)
|
||||
rad = (hr % 12) * pi / 6.0 + mi * pi / 360.0
|
||||
drawline(ctx, [Point(50, 50),
|
||||
Point(50 + 45 * 0.5 * sin(rad), 50 - 45 * 0.5 * cos(rad))], colorant"black")
|
||||
stroke(ctx)
|
||||
rad = mi * pi / 30.0 + sec * pi / 1800.0
|
||||
drawline(ctx, [Point(50, 50),
|
||||
Point(50 + 0.7 * 45 * sin(rad), 50 - 0.7 * 45 * cos(rad))], colorant"darkgreen")
|
||||
stroke(ctx)
|
||||
rad = sec * pi / 30.0
|
||||
drawline(ctx, [Point(50, 50),
|
||||
Point(50 + 0.9 * 45 * sin(rad), 50 - 0.9 * 45 * cos(rad))], colorant"red")
|
||||
stroke(ctx)
|
||||
reveal(can)
|
||||
end
|
||||
|
||||
Gtk.showall(win)
|
||||
sloc = Base.Threads.SpinLock()
|
||||
lock(sloc)
|
||||
signal_connect(win, :destroy) do widget
|
||||
unlock(sloc)
|
||||
end
|
||||
while !trylock(sloc)
|
||||
update(win)
|
||||
sleep(1.0)
|
||||
end
|
||||
|
|
@ -3,26 +3,26 @@ import java.time.LocalTime
|
|||
import scala.math._
|
||||
|
||||
object Clock extends App {
|
||||
private val (width, heigth) = (80, 35)
|
||||
private val (width, height) = (80, 35)
|
||||
|
||||
def getGrid(localTime: LocalTime): Array[Array[Char]] = {
|
||||
val (minute, second) = (localTime.getMinute, localTime.getSecond())
|
||||
val grid = Array.fill[Char](heigth, width)(' ')
|
||||
val grid = Array.fill[Char](height, width)(' ')
|
||||
|
||||
def toGridCoord(x: Double, y: Double): (Int, Int) =
|
||||
(floor((y + 1.0) / 2.0 * heigth).toInt, floor((x + 1.0) / 2.0 * width).toInt)
|
||||
(floor((y + 1.0) / 2.0 * height).toInt, floor((x + 1.0) / 2.0 * width).toInt)
|
||||
|
||||
def makeText(grid: Array[Array[Char]], r: Double, theta: Double, str: String) {
|
||||
val (row, col) = toGridCoord(r * cos(theta), r * sin(theta))
|
||||
(0 until str.length).foreach(i =>
|
||||
if (row >= 0 && row < heigth && col + i >= 0 && col + i < width) grid(row)(col + i) = str(i))
|
||||
if (row >= 0 && row < height && col + i >= 0 && col + i < width) grid(row)(col + i) = str(i))
|
||||
}
|
||||
|
||||
def makeCircle(grid: Array[Array[Char]], r: Double, c: Char) {
|
||||
var theta = 0.0
|
||||
while (theta < 2 * Pi) {
|
||||
val (row, col) = toGridCoord(r * cos(theta), r * sin(theta))
|
||||
if (row >= 0 && row < heigth && col >= 0 && col < width) grid(row)(col) = c
|
||||
if (row >= 0 && row < height && col >= 0 && col < width) grid(row)(col) = c
|
||||
theta = theta + 0.01
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ object Clock extends App {
|
|||
var r = 0.0
|
||||
while (r < maxR) {
|
||||
val (row, col) = toGridCoord(r * cos(theta), r * sin(theta))
|
||||
if (row >= 0 && row < heigth && col >= 0 && col < width) grid(row)(col) = c
|
||||
if (row >= 0 && row < height && col >= 0 && col < width) grid(row)(col) = c
|
||||
r = r + 0.01
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
Task/Draw-a-clock/ZX-Spectrum-Basic/draw-a-clock.zx
Normal file
14
Task/Draw-a-clock/ZX-Spectrum-Basic/draw-a-clock.zx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 REM First we draw the clock face
|
||||
20 FOR n=1 TO 12
|
||||
30 PRINT AT 10-10*COS (n/6*PI),16+10*SIN (n/6*PI);n
|
||||
40 NEXT n
|
||||
50 DEF FN t()=INT (65536*PEEK 23674+256*PEEK 23673+PEEK 23672)/50: REM number of seconds since start
|
||||
100 REM Now we start the clock
|
||||
110 LET t1=FN t()
|
||||
120 LET a=t1/30*PI: REM a is the angle of the second hand in radians
|
||||
130 LET sx=72*SIN a: LET sy=72*COS a
|
||||
140 PLOT 131,91: DRAW OVER 1;sx,sy: REM draw hand
|
||||
200 LET t=FN t()
|
||||
210 IF INT t<=INT t1 THEN GO TO 200: REM wait for time for next hand; the INTs were not in the original but force it to wait for the next second
|
||||
220 PLOT 131,91: DRAW OVER 1;sx,sy: REM rub out old hand
|
||||
230 LET t1=t: GO TO 120
|
||||
Loading…
Add table
Add a link
Reference in a new issue