From 8518c8b8036e2a29a08ada65456daee0d8adf7de Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 14 Feb 2016 21:24:06 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/canvas/2.own | 4 +- examples/canvas/animate_line.own | 15 +++--- examples/canvas/control_point.own | 8 ++-- examples/canvas/fractal_polygon.own | 17 +++---- examples/canvas/fractal_rect.own | 11 +++-- examples/common/bitwise.own | 8 ++-- examples/functions/factorial.own | 2 +- examples/game/agar.own | 10 ++-- examples/game/pipes.own | 68 ++++++++++++++-------------- examples/network/github_timeline.own | 5 +- examples/robot/paint_lines.own | 4 +- 11 files changed, 75 insertions(+), 77 deletions(-) diff --git a/examples/canvas/2.own b/examples/canvas/2.own index d08e25a..e9baaa8 100644 --- a/examples/canvas/2.own +++ b/examples/canvas/2.own @@ -8,10 +8,10 @@ frect(0, 0, w, h) step = rand(20) color(#0000ff) -for y = 0, y < h, y = y + step { +for y = 0, y < h, y += step { line(0, y, w, y) } -for x = 0, x < w, x = x + step { +for x = 0, x < w, x += step { line(x, 0, x, h) } repaint(); diff --git a/examples/canvas/animate_line.own b/examples/canvas/animate_line.own index b16d336..d5edc19 100644 --- a/examples/canvas/animate_line.own +++ b/examples/canvas/animate_line.own @@ -24,10 +24,10 @@ while run { if checkvert(y1) d1y = -d1y if checkvert(y2) d2y = -d2y - x1 = x1 + d1x x2 = x2 + d2x - y1 = y1 + d1y y2 = y2 + d2y + x1 += d1x x2 += d2x + y1 += d1y y2 += d2y - hue = hue + 0.0001 + hue += 0.0001 if (hue >= 1) hue = 0 sethsbcolor(hue) line(x1, y1, x2, y2) @@ -36,17 +36,16 @@ while run { if keypressed() == VK_ESCAPE run = 0 } -def checkhoriz(px) return (px >= w || px < 0) -def checkvert(py) return (py >= h || py < 0) +def checkhoriz(px) = (px >= w || px < 0) +def checkvert(py) = (py >= h || py < 0) -def floor(v) return v - v % 1 +def floor(v) = v - v % 1 def sethsbcolor(h1) { qr = h1 * 6 // временно для расчёта - hueindex = floor(qr) % 6 f = qr - floor(qr) - match hueindex { + match floor(qr) % 6 { case 0: color(255, f*255, 0) case 1: color(255 - f*255, 255, 0) case 2: color(0, 255, f*255) diff --git a/examples/canvas/control_point.own b/examples/canvas/control_point.own index 07f6b5e..d2d8161 100644 --- a/examples/canvas/control_point.own +++ b/examples/canvas/control_point.own @@ -9,10 +9,10 @@ x = rand(w) y = rand(h) run = 1 while run { key = keypressed() - if (key == VK_LEFT && x > 0) x = x - 1 - else if (key == VK_RIGHT && x < w) x = x + 1 - else if (key == VK_UP && y > 0) y = y - 1 - else if (key == VK_DOWN && y < h) y = y + 1 + if (key == VK_LEFT && x > 0) x-- + else if (key == VK_RIGHT && x < w) x++ + else if (key == VK_UP && y > 0) y-- + else if (key == VK_DOWN && y < h) y++ else if key == VK_ESCAPE run = 0 color(255,255,255) diff --git a/examples/canvas/fractal_polygon.own b/examples/canvas/fractal_polygon.own index 9504ec6..8f2cce1 100644 --- a/examples/canvas/fractal_polygon.own +++ b/examples/canvas/fractal_polygon.own @@ -20,27 +20,24 @@ repaint() def cpoly(cx, cy, size) { ox = cx oy = cy - size - i = 0 ang = 0 - while i < NUM_POINTS { - ang = ang + angle + for i = 0, i < NUM_POINTS, i++ { + ang += angle nx = cx - sin(ang)*size ny = cy - cos(ang)*size line(ox, oy, nx, ny) ox = nx oy = ny - i = i + 1 } } def fractal(cx, cy, size) { if size >= 3 { s2 = size / 2 + sD = size / DIVIDER color(0, 0, 255 - size * 255 / w/2) - cpoly(cx, cy, size / DIVIDER) - fractal(cx, cy - s2, size / DIVIDER) - n = 0 - while n < NUM_POINTS { - fractal(cx - sin(angle*n)*s2, cy - cos(angle*n)*s2, size / DIVIDER) - n = n + 1 + cpoly(cx, cy, sD) + fractal(cx, cy - s2, sD) + for n = 0, n < NUM_POINTS, n++ { + fractal(cx - sin(angle*n)*s2, cy - cos(angle*n)*s2, sD) } } } \ No newline at end of file diff --git a/examples/canvas/fractal_rect.own b/examples/canvas/fractal_rect.own index 7c704f4..fcb8854 100644 --- a/examples/canvas/fractal_rect.own +++ b/examples/canvas/fractal_rect.own @@ -14,11 +14,12 @@ def rect(x, y, w, h) { def fractal(cx, cy, size) { if size >= 2 { + s2 = size / 2 color(0, 0, 255 - size * 255 / w/2) - rect(cx-size/2, cy-size/2, size, size) - fractal(cx-size/2, cy-size/2, size / 2) - fractal(cx+size/2, cy-size/2, size / 2) - fractal(cx-size/2, cy+size/2, size / 2) - fractal(cx+size/2, cy+size/2, size / 2) + rect(cx-s2, cy-s2, size, size) + fractal(cx-s2, cy-s2, s2) + fractal(cx+s2, cy-s2, s2) + fractal(cx-s2, cy+s2, s2) + fractal(cx+s2, cy+s2, s2) } } \ No newline at end of file diff --git a/examples/common/bitwise.own b/examples/common/bitwise.own index 4aa1555..57cc487 100644 --- a/examples/common/bitwise.own +++ b/examples/common/bitwise.own @@ -6,12 +6,12 @@ echo(-8 >> 2) echo(-8 >>> 2) echo() -for a = 0, a <= 1, a = a + 1 { - for b = 0, b <= 1, b = b + 1 { +for a = 0, a <= 1, a++ { + for b = 0, b <= 1, b++ { echo(a, " | ", b, " ", a | b) echo(a, " & ", b, " ", a & b) echo(a, " ^ ", b, " ", a ^ b) } - echo(" ~", a, " ", ~a) - echo(" !", a, " ", !a) + echo(" ~", a, " ", ~a) + echo(" !", a, " ", !a) } \ No newline at end of file diff --git a/examples/functions/factorial.own b/examples/functions/factorial.own index 9a9e1ef..560aab4 100644 --- a/examples/functions/factorial.own +++ b/examples/functions/factorial.own @@ -17,7 +17,7 @@ def fibonacci(count) { return fib(count) } -for i = 0, i < 10, i = i + 1 +for i = 0, i < 10, i++ print " " + fibonacci(i) print "\n" diff --git a/examples/game/agar.own b/examples/game/agar.own index 3b96244..c75b731 100644 --- a/examples/game/agar.own +++ b/examples/game/agar.own @@ -16,7 +16,7 @@ fieldY = rand(fieldHeight) - h2 NUM_FOOD = 350 food = newarray(4, NUM_FOOD) -for i = 0, i < NUM_FOOD, i = i + 1 { +for i = 0, i < NUM_FOOD, i++ { food[0][i] = rand(fieldWidth) food[1][i] = rand(fieldHeight) food[2][i] = 6 + rand(2) @@ -31,8 +31,8 @@ run = 1 while run { mouse = mousehover() angle = atan2(mouse[1] - h2, mouse[0] - w2) - fieldX = fieldX + cos(angle) * 50/playerSize - fieldY = fieldY + sin(angle) * 50/playerSize + fieldX += cos(angle) * 50/playerSize + fieldY += sin(angle) * 50/playerSize if (fieldX < -w2) fieldX = -w2 else if (fieldX > fieldWidth - w2 - 1) fieldX = fieldWidth - w2 - 1 if (fieldY < -h2) fieldY = -h2 @@ -45,13 +45,13 @@ while run { color(#333333) rect(-fieldX, -fieldY, fieldWidth, fieldHeight) - for i = 0, i < NUM_FOOD, i = i + 1 { + for i = 0, i < NUM_FOOD, i++ { dx = food[0][i] - fieldX - w2 dy = food[1][i] - fieldY - h2 rad = food[2][i] + playerSize if ( (dx*dx + dy*dy) < (rad*rad) ) { // есть столкновение - playerSize = playerSize + 1 + playerSize++ food[0][i] = rand(w) food[1][i] = rand(h) food[2][i] = 6 + rand(2) diff --git a/examples/game/pipes.own b/examples/game/pipes.own index 0a54be6..efcd2c7 100644 --- a/examples/game/pipes.own +++ b/examples/game/pipes.own @@ -33,34 +33,36 @@ support = [ def draw(v, cellSize) { c2 = cellSize / 2 - if (v == HORIZONTAL) fillRect(0, c2 - 2, cellSize, 4) - else if (v == VERTICAL) fillRect(c2 - 2, 0, 4, cellSize) - else if (v == LEFT_TO_DOWN) { - fillRect(0, c2 - 2, c2, 4) - fillRect(c2 - 2, c2 - 2, 4, c2 + 2) - } - else if (v == LEFT_TO_UP) { - fillRect(0, c2 - 2, c2, 4) - fillRect(c2 - 2, c2 - 2, 4, c2 + 2) - } - else if (v == RIGHT_TO_UP) { - fillRect(c2 - 2, c2 - 2, c2 + 2, 4) - fillRect(c2 - 2, 0, 4, c2 + 2) - } - else if (v == RIGHT_TO_DOWN) { - fillRect(c2 - 2, c2 - 2, c2 + 2, 4) - fillRect(c2 - 2, c2 - 2, 4, c2 + 2) - } - else if (v == CROSS) { - fillRect(c2 - 2, 0, 4, cellSize) - fillRect(0, c2 - 2, cellSize, 4) + match v { + case HORIZONTAL : fillRect(0, c2 - 2, cellSize, 4) + case VERTICAL : fillRect(c2 - 2, 0, 4, cellSize) + case LEFT_TO_DOWN : { + fillRect(0, c2 - 2, c2, 4) + fillRect(c2 - 2, c2 - 2, 4, c2 + 2) + } + case LEFT_TO_UP : { + fillRect(0, c2 - 2, c2, 4) + fillRect(c2 - 2, c2 - 2, 4, c2 + 2) + } + case RIGHT_TO_UP : { + fillRect(c2 - 2, c2 - 2, c2 + 2, 4) + fillRect(c2 - 2, 0, 4, c2 + 2) + } + case RIGHT_TO_DOWN : { + fillRect(c2 - 2, c2 - 2, c2 + 2, 4) + fillRect(c2 - 2, c2 - 2, 4, c2 + 2) + } + case CROSS : { + fillRect(c2 - 2, 0, 4, cellSize) + fillRect(0, c2 - 2, cellSize, 4) + } } } -def supportLeft(v) return support[v][0] -def supportRight(v) return support[v][1] -def supportUp(v) return support[v][2] -def supportDown(v) return support[v][3] +def supportLeft(v) = support[v][0] +def supportRight(v) = support[v][1] +def supportUp(v) = support[v][2] +def supportDown(v) = support[v][3] ///------------------------------------- @@ -73,8 +75,8 @@ SIZE = 10 board = newarray(SIZE, SIZE) def createBoard() { - for i=0, i 0) curX = curX - 1 - else if (key == VK_RIGHT && curX < SIZE - 1) curX = curX + 1 - else if (key == VK_UP && curY > 0) curY = curY - 1 - else if (key == VK_DOWN && curY < SIZE - 1) curY = curY + 1 + if (key == VK_LEFT && curX > 0) curX-- + else if (key == VK_RIGHT && curX < SIZE - 1) curX++ + else if (key == VK_UP && curY > 0) curY-- + else if (key == VK_DOWN && curY < SIZE - 1) curY++ else if key == VK_FIRE switchCell(curX,curY) else if key == 48 run = 0 @@ -157,13 +159,13 @@ while run { // курсор color(#4444FF) frect(curX*cellSize, curY*cellSize, cellSize, cellSize) - for (i=0, i