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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
-
|
-
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
|
|
!
-
|
|
|
|
|
!
-
|
|
!
-
|
|
!
-
|
|
!
|
#module
#deffunc DrwArrow int x1, int y1, int x2, int y2
line x1, y1, x2, y2
x = x1 - x2
y = y1 - y2
x3 = (x - y) / 7 + x2
y3 = (y + x) / 7 + y2
line x2, y2, x3, y3
x3 = (x + y) / 7 + x2
y3 = (y - x) / 7 + y2
line x2, y2, x3, y3
return
#global
#define BALL_SIZE 6
#define G 1.0
#define M 1.0
#define MU 1.0
#define CD 0.005
#define hanekaeri 0.8
#define GROUND 400.0
#define WALL 500.0
title "飛ぶボール"
px = WALL/2
py = GROUND
vx = 0.0 : vy = 0.0
ax = 0.0 : ay = 0.0
juryoku = 1
gosub *makeObject
goto *main
*makeObject
objsize ginfo_winx - WALL - 20, 30
pos WALL + 10, 10
syscolor 18
mes "オプション"
pos WALL + 20
chkbox "重力", juryoku
chkbox "非完全弾性衝突", hikanzen
chkbox "床との動摩擦", doumasatsu
chkbox "空中での空気抵抗", kuukiteikou
chkbox "ベクトルの表示", vector
return
*main
redraw 0
gosub *inkey
onGround = (py >= GROUND)
if juryoku {
ax = 0.0 : ay = G
} else {
ax = 0.0 : ay = 0.0
}
if kuukiteikou : gosub *airResistance
if doumasatsu & onGround : gosub *friction
gosub *move
gosub *draw
redraw 1
await 17
goto *main
*inkey
stick key, 5
getkey key_Z, 'Z'
if key&128 : end
if key_Z & onGround & (vy == 0.0) : vy = -20.0
if key&1 : vx -= 2.0
if key&4 : vx += 2.0
return
*airResistance
hvx = (0.0 < vx) - (vx < 0.0)
hvy = (0.0 < vy) - (vy < 0.0)
teikoux = -vx * vx * CD / 2 / M * hvx
teikouy = -vy * vy * CD / 2 / M * hvy
ax += teikoux
ay += teikouy
return
*friction
hvx = (0.0 < vx) - (vx < 0.0)
masatsu = -ay * MU * hvx
ax = masatsu
if (vx < 0)&(vx + ax > 0) : ax = -vx
if (vx > 0)&(vx + ax < 0) : ax = -vx
return
*move
vx += ax : vy += ay
px += vx : py += vy
if px < 0.0 {
vx = sqrt(vx * vx - ax * px * 2)
px = 0.0
if hikanzen : vx *= hanekaeri
}
if WALL < px {
vx = -sqrt(vx * vx - ax * (px - WALL) * 2)
px = double(WALL)
if hikanzen : vx *= hanekaeri
}
if py > GROUND {
tmp = vy * vy - ay * (py - GROUND) * 2
if tmp < 0 : tmp = 0.0
vy = -sqrt(tmp)
if hikanzen : vy *= hanekaeri
py = double(GROUND)
}
if py < 0.0 {
tmp = vy * vy - ay * py * 2
if tmp < 0 : tmp = 0.0
vy = sqrt(tmp)
if hikanzen : vy *= hanekaeri
py = 0.0
}
return
*draw
color 255, 255, 255 : boxf
color 0, 0, 0 : pos 0, 0
mes "座標( "+px+", "+py+" )"
mes "速度 v = " + sqrt(vx * vx + vy * vy)
if onGround & (vy == 0.0) : mes "Zキーを押してください。"
syscolor 15
boxf ginfo_winx, ginfo_winy, 0, GROUND
boxf ginfo_winx, GROUND, WALL, 0
pos WALL + 10, 10
syscolor 18
mes "オプション"
color 0, 0, 0
circle px - BALL_SIZE, py - BALL_SIZE, px + BALL_SIZE, py + BALL_SIZE
if vector : gosub *drawVect
return
*drawVect
color 255,0,0
DrwArrow px, py, vx * 5 + px, vy * 5 + py
if juryoku {
color 128, 64
DrwArrow px, py, px, py + G * M * 50
}
if onGround & doumasatsu {
color 0, 0, 255
DrwArrow px, py, masatsu * 50 + px, py
}
if kuukiteikou {
color 0, 255
DrwArrow px, py, teikoux*M * 50 + px, teikouy*M * 50 + py
}
return
|