1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
-
|
|
|
!
| #include "d3m.hsp"
#module
#defcfunc spline var x, var y, array mx, array my, double t, int n
if(t<0 || t>=n+1) { return 1 }
x=0.0 : y=0.0
j=-2
repeat
if(j > n+1) { break }
tt=absf(t-j-1)
if(tt < 2.0) { a=0.25*(cos(1.570796*tt)+1.0) }
else { a=0.0 }
i=limit(j, 0, n-1)
x+=a*mx(i)
y+=a*my(i)
j++
loop
return 0
#global
#const CAM_DISTANCE 500.0
#const GRID_SPAN 50
#const ANG_SPEED 0.05
n = 3
ddim x, n : ddim y, n
x = -200.0, 0.0, 200.0
y = -200.0, 200.0, 0.0
theta = 1.0
title "カーソルキー左右でカメラの回転"
gosub *set_camera
need_to_redraw = 1
repeat
stick keys, 15
gosub *move_camera
gosub *draw
await 10
loop
*move_camera
if keys & 0b101 {
theta += ANG_SPEED * ((keys >> 2 & 1) - (keys & 1))
gosub *set_camera
need_to_redraw = 1
}
return
*set_camera
d3setcam cos(theta)*CAM_DISTANCE, sin(theta)*CAM_DISTANCE, 0, 0, 0, 0
return
*draw
if need_to_redraw == 0 : return
redraw 0
color 255, 255, 255 : boxf
color 192,192,192
repeat 11, -5
d3line -GRID_SPAN * 5, 0, GRID_SPAN * cnt, GRID_SPAN * 5, 0, GRID_SPAN * cnt
d3line GRID_SPAN * cnt, 0, -GRID_SPAN * 5, GRID_SPAN * cnt, 0, GRID_SPAN * 5
loop
color
t=0.0
repeat
if(spline(_x, _y, x, y, t, n)) :break
t+=0.01
d3pset _x, 0, _y
loop
color ,255
repeat n
d3circle x(cnt), 0, y(cnt), 10
loop
d3pos x(0), 0, y(0) : mes "始点"
d3pos x(1), 0, y(1) : mes "オンカーブ点"
d3pos x(2), 0, y(2) : mes "終点"
redraw
need_to_redraw = 0
return
|