Skip to content

Commit 8518c8b

Browse files
committed
Обновлены примеры
1 parent b2f7cc5 commit 8518c8b

File tree

11 files changed

+75
-77
lines changed

11 files changed

+75
-77
lines changed

examples/canvas/2.own

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ frect(0, 0, w, h)
88

99
step = rand(20)
1010
color(#0000ff)
11-
for y = 0, y < h, y = y + step {
11+
for y = 0, y < h, y += step {
1212
line(0, y, w, y)
1313
}
14-
for x = 0, x < w, x = x + step {
14+
for x = 0, x < w, x += step {
1515
line(x, 0, x, h)
1616
}
1717
repaint();

examples/canvas/animate_line.own

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ while run {
2424
if checkvert(y1) d1y = -d1y
2525
if checkvert(y2) d2y = -d2y
2626

27-
x1 = x1 + d1x x2 = x2 + d2x
28-
y1 = y1 + d1y y2 = y2 + d2y
27+
x1 += d1x x2 += d2x
28+
y1 += d1y y2 += d2y
2929

30-
hue = hue + 0.0001
30+
hue += 0.0001
3131
if (hue >= 1) hue = 0
3232
sethsbcolor(hue)
3333
line(x1, y1, x2, y2)
@@ -36,17 +36,16 @@ while run {
3636
if keypressed() == VK_ESCAPE run = 0
3737
}
3838

39-
def checkhoriz(px) return (px >= w || px < 0)
40-
def checkvert(py) return (py >= h || py < 0)
39+
def checkhoriz(px) = (px >= w || px < 0)
40+
def checkvert(py) = (py >= h || py < 0)
4141

42-
def floor(v) return v - v % 1
42+
def floor(v) = v - v % 1
4343

4444
def sethsbcolor(h1) {
4545
qr = h1 * 6 // временно для расчёта
46-
hueindex = floor(qr) % 6
4746
f = qr - floor(qr)
4847

49-
match hueindex {
48+
match floor(qr) % 6 {
5049
case 0: color(255, f*255, 0)
5150
case 1: color(255 - f*255, 255, 0)
5251
case 2: color(0, 255, f*255)

examples/canvas/control_point.own

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ x = rand(w) y = rand(h)
99
run = 1
1010
while run {
1111
key = keypressed()
12-
if (key == VK_LEFT && x > 0) x = x - 1
13-
else if (key == VK_RIGHT && x < w) x = x + 1
14-
else if (key == VK_UP && y > 0) y = y - 1
15-
else if (key == VK_DOWN && y < h) y = y + 1
12+
if (key == VK_LEFT && x > 0) x--
13+
else if (key == VK_RIGHT && x < w) x++
14+
else if (key == VK_UP && y > 0) y--
15+
else if (key == VK_DOWN && y < h) y++
1616
else if key == VK_ESCAPE run = 0
1717

1818
color(255,255,255)

examples/canvas/fractal_polygon.own

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,24 @@ repaint()
2020

2121
def cpoly(cx, cy, size) {
2222
ox = cx oy = cy - size
23-
i = 0
2423
ang = 0
25-
while i < NUM_POINTS {
26-
ang = ang + angle
24+
for i = 0, i < NUM_POINTS, i++ {
25+
ang += angle
2726
nx = cx - sin(ang)*size ny = cy - cos(ang)*size
2827
line(ox, oy, nx, ny)
2928
ox = nx oy = ny
30-
i = i + 1
3129
}
3230
}
3331

3432
def fractal(cx, cy, size) {
3533
if size >= 3 {
3634
s2 = size / 2
35+
sD = size / DIVIDER
3736
color(0, 0, 255 - size * 255 / w/2)
38-
cpoly(cx, cy, size / DIVIDER)
39-
fractal(cx, cy - s2, size / DIVIDER)
40-
n = 0
41-
while n < NUM_POINTS {
42-
fractal(cx - sin(angle*n)*s2, cy - cos(angle*n)*s2, size / DIVIDER)
43-
n = n + 1
37+
cpoly(cx, cy, sD)
38+
fractal(cx, cy - s2, sD)
39+
for n = 0, n < NUM_POINTS, n++ {
40+
fractal(cx - sin(angle*n)*s2, cy - cos(angle*n)*s2, sD)
4441
}
4542
}
4643
}

examples/canvas/fractal_rect.own

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ def rect(x, y, w, h) {
1414

1515
def fractal(cx, cy, size) {
1616
if size >= 2 {
17+
s2 = size / 2
1718
color(0, 0, 255 - size * 255 / w/2)
18-
rect(cx-size/2, cy-size/2, size, size)
19-
fractal(cx-size/2, cy-size/2, size / 2)
20-
fractal(cx+size/2, cy-size/2, size / 2)
21-
fractal(cx-size/2, cy+size/2, size / 2)
22-
fractal(cx+size/2, cy+size/2, size / 2)
19+
rect(cx-s2, cy-s2, size, size)
20+
fractal(cx-s2, cy-s2, s2)
21+
fractal(cx+s2, cy-s2, s2)
22+
fractal(cx-s2, cy+s2, s2)
23+
fractal(cx+s2, cy+s2, s2)
2324
}
2425
}

examples/common/bitwise.own

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ echo(-8 >> 2)
66
echo(-8 >>> 2)
77

88
echo()
9-
for a = 0, a <= 1, a = a + 1 {
10-
for b = 0, b <= 1, b = b + 1 {
9+
for a = 0, a <= 1, a++ {
10+
for b = 0, b <= 1, b++ {
1111
echo(a, " | ", b, " ", a | b)
1212
echo(a, " & ", b, " ", a & b)
1313
echo(a, " ^ ", b, " ", a ^ b)
1414
}
15-
echo(" ~", a, " ", ~a)
16-
echo(" !", a, " ", !a)
15+
echo(" ~", a, " ", ~a)
16+
echo(" !", a, " ", !a)
1717
}

examples/functions/factorial.own

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def fibonacci(count) {
1717
return fib(count)
1818
}
1919

20-
for i = 0, i < 10, i = i + 1
20+
for i = 0, i < 10, i++
2121
print " " + fibonacci(i)
2222
print "\n"
2323

examples/game/agar.own

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fieldY = rand(fieldHeight) - h2
1616
NUM_FOOD = 350
1717
food = newarray(4, NUM_FOOD)
1818

19-
for i = 0, i < NUM_FOOD, i = i + 1 {
19+
for i = 0, i < NUM_FOOD, i++ {
2020
food[0][i] = rand(fieldWidth)
2121
food[1][i] = rand(fieldHeight)
2222
food[2][i] = 6 + rand(2)
@@ -31,8 +31,8 @@ run = 1
3131
while run {
3232
mouse = mousehover()
3333
angle = atan2(mouse[1] - h2, mouse[0] - w2)
34-
fieldX = fieldX + cos(angle) * 50/playerSize
35-
fieldY = fieldY + sin(angle) * 50/playerSize
34+
fieldX += cos(angle) * 50/playerSize
35+
fieldY += sin(angle) * 50/playerSize
3636
if (fieldX < -w2) fieldX = -w2
3737
else if (fieldX > fieldWidth - w2 - 1) fieldX = fieldWidth - w2 - 1
3838
if (fieldY < -h2) fieldY = -h2
@@ -45,13 +45,13 @@ while run {
4545
color(#333333)
4646
rect(-fieldX, -fieldY, fieldWidth, fieldHeight)
4747

48-
for i = 0, i < NUM_FOOD, i = i + 1 {
48+
for i = 0, i < NUM_FOOD, i++ {
4949
dx = food[0][i] - fieldX - w2
5050
dy = food[1][i] - fieldY - h2
5151
rad = food[2][i] + playerSize
5252
if ( (dx*dx + dy*dy) < (rad*rad) ) {
5353
// есть столкновение
54-
playerSize = playerSize + 1
54+
playerSize++
5555
food[0][i] = rand(w)
5656
food[1][i] = rand(h)
5757
food[2][i] = 6 + rand(2)

examples/game/pipes.own

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,36 @@ support = [
3333

3434
def draw(v, cellSize) {
3535
c2 = cellSize / 2
36-
if (v == HORIZONTAL) fillRect(0, c2 - 2, cellSize, 4)
37-
else if (v == VERTICAL) fillRect(c2 - 2, 0, 4, cellSize)
38-
else if (v == LEFT_TO_DOWN) {
39-
fillRect(0, c2 - 2, c2, 4)
40-
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
41-
}
42-
else if (v == LEFT_TO_UP) {
43-
fillRect(0, c2 - 2, c2, 4)
44-
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
45-
}
46-
else if (v == RIGHT_TO_UP) {
47-
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
48-
fillRect(c2 - 2, 0, 4, c2 + 2)
49-
}
50-
else if (v == RIGHT_TO_DOWN) {
51-
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
52-
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
53-
}
54-
else if (v == CROSS) {
55-
fillRect(c2 - 2, 0, 4, cellSize)
56-
fillRect(0, c2 - 2, cellSize, 4)
36+
match v {
37+
case HORIZONTAL : fillRect(0, c2 - 2, cellSize, 4)
38+
case VERTICAL : fillRect(c2 - 2, 0, 4, cellSize)
39+
case LEFT_TO_DOWN : {
40+
fillRect(0, c2 - 2, c2, 4)
41+
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
42+
}
43+
case LEFT_TO_UP : {
44+
fillRect(0, c2 - 2, c2, 4)
45+
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
46+
}
47+
case RIGHT_TO_UP : {
48+
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
49+
fillRect(c2 - 2, 0, 4, c2 + 2)
50+
}
51+
case RIGHT_TO_DOWN : {
52+
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
53+
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
54+
}
55+
case CROSS : {
56+
fillRect(c2 - 2, 0, 4, cellSize)
57+
fillRect(0, c2 - 2, cellSize, 4)
58+
}
5759
}
5860
}
5961

60-
def supportLeft(v) return support[v][0]
61-
def supportRight(v) return support[v][1]
62-
def supportUp(v) return support[v][2]
63-
def supportDown(v) return support[v][3]
62+
def supportLeft(v) = support[v][0]
63+
def supportRight(v) = support[v][1]
64+
def supportUp(v) = support[v][2]
65+
def supportDown(v) = support[v][3]
6466
///-------------------------------------
6567

6668

@@ -73,8 +75,8 @@ SIZE = 10
7375
board = newarray(SIZE, SIZE)
7476

7577
def createBoard() {
76-
for i=0, i<SIZE, i=i+1
77-
for j=0, j<SIZE, j=j+1
78+
for i=0, i<SIZE, i++
79+
for j=0, j<SIZE, j++
7880
board[i][j] = rand(CELL_LAST)
7981
}
8082

@@ -144,10 +146,10 @@ run = 1
144146
while run {
145147
//key = gameaction(keypressed())
146148
key = keypressed()
147-
if (key == VK_LEFT && curX > 0) curX = curX - 1
148-
else if (key == VK_RIGHT && curX < SIZE - 1) curX = curX + 1
149-
else if (key == VK_UP && curY > 0) curY = curY - 1
150-
else if (key == VK_DOWN && curY < SIZE - 1) curY = curY + 1
149+
if (key == VK_LEFT && curX > 0) curX--
150+
else if (key == VK_RIGHT && curX < SIZE - 1) curX++
151+
else if (key == VK_UP && curY > 0) curY--
152+
else if (key == VK_DOWN && curY < SIZE - 1) curY++
151153
else if key == VK_FIRE switchCell(curX,curY)
152154
else if key == 48 run = 0
153155

@@ -157,13 +159,13 @@ while run {
157159
// курсор
158160
color(#4444FF)
159161
frect(curX*cellSize, curY*cellSize, cellSize, cellSize)
160-
for (i=0, i<SIZE, i=i+1) {
162+
for (i=0, i<SIZE, i++) {
161163
color(0)
162164
ic = i*cellSize
163165
line(0, ic, cellSize*SIZE, ic)
164166
line(ic, 0, ic, cellSize*SIZE)
165167
color(#FF0000)
166-
for j=0, j<SIZE, j=j+1 {
168+
for j=0, j<SIZE, j++ {
167169
translateX = ic
168170
translateY = j*cellSize
169171
draw(board[i][j], cellSize)

examples/network/github_timeline.own

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ thread(::http, "https://api.github.com/events", def(r) {
2020

2121
def show_github_events(event) {
2222
println event.created_at
23-
actor = event.actor
24-
println "User: https://github.com/" + actor.login
23+
println "User: https://github.com/" + event.actor.login
2524
println github_event_type(event)
2625
println "-" * 50
2726
}
@@ -32,7 +31,7 @@ def github_event_type(event) {
3231
return match event.type {
3332
case "CommitCommentEvent": "commented commit in " + repo + "\n" + payload.comment.body
3433
case "CreateEvent": "created " + payload.ref_type + " on " + repo
35-
case "DeleteEvent": "deleted " + payload.ref_type + " on " + repo
34+
case "DeleteEvent": "deleted " + payload.ref_type + " on " + repo
3635
case "ForkEvent": "forked repository " + repo
3736
case "IssueCommentEvent": "commented issue " + payload.issue.title + " on " + repo + "\n" + payload.comment.body
3837
case "IssuesEvent": payload.action + " issue '" + payload.issue.title + "' on " + repo

0 commit comments

Comments
 (0)