mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Обновлены примеры
This commit is contained in:
parent
b2f7cc52ed
commit
8518c8b803
@ -8,10 +8,10 @@ frect(0, 0, w, h)
|
|||||||
|
|
||||||
step = rand(20)
|
step = rand(20)
|
||||||
color(#0000ff)
|
color(#0000ff)
|
||||||
for y = 0, y < h, y = y + step {
|
for y = 0, y < h, y += step {
|
||||||
line(0, y, w, y)
|
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)
|
line(x, 0, x, h)
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -24,10 +24,10 @@ while run {
|
|||||||
if checkvert(y1) d1y = -d1y
|
if checkvert(y1) d1y = -d1y
|
||||||
if checkvert(y2) d2y = -d2y
|
if checkvert(y2) d2y = -d2y
|
||||||
|
|
||||||
x1 = x1 + d1x x2 = x2 + d2x
|
x1 += d1x x2 += d2x
|
||||||
y1 = y1 + d1y y2 = y2 + d2y
|
y1 += d1y y2 += d2y
|
||||||
|
|
||||||
hue = hue + 0.0001
|
hue += 0.0001
|
||||||
if (hue >= 1) hue = 0
|
if (hue >= 1) hue = 0
|
||||||
sethsbcolor(hue)
|
sethsbcolor(hue)
|
||||||
line(x1, y1, x2, y2)
|
line(x1, y1, x2, y2)
|
||||||
@ -36,17 +36,16 @@ while run {
|
|||||||
if keypressed() == VK_ESCAPE run = 0
|
if keypressed() == VK_ESCAPE run = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkhoriz(px) return (px >= w || px < 0)
|
def checkhoriz(px) = (px >= w || px < 0)
|
||||||
def checkvert(py) return (py >= h || py < 0)
|
def checkvert(py) = (py >= h || py < 0)
|
||||||
|
|
||||||
def floor(v) return v - v % 1
|
def floor(v) = v - v % 1
|
||||||
|
|
||||||
def sethsbcolor(h1) {
|
def sethsbcolor(h1) {
|
||||||
qr = h1 * 6 // временно для расчёта
|
qr = h1 * 6 // временно для расчёта
|
||||||
hueindex = floor(qr) % 6
|
|
||||||
f = qr - floor(qr)
|
f = qr - floor(qr)
|
||||||
|
|
||||||
match hueindex {
|
match floor(qr) % 6 {
|
||||||
case 0: color(255, f*255, 0)
|
case 0: color(255, f*255, 0)
|
||||||
case 1: color(255 - f*255, 255, 0)
|
case 1: color(255 - f*255, 255, 0)
|
||||||
case 2: color(0, 255, f*255)
|
case 2: color(0, 255, f*255)
|
||||||
|
@ -9,10 +9,10 @@ x = rand(w) y = rand(h)
|
|||||||
run = 1
|
run = 1
|
||||||
while run {
|
while run {
|
||||||
key = keypressed()
|
key = keypressed()
|
||||||
if (key == VK_LEFT && x > 0) x = x - 1
|
if (key == VK_LEFT && x > 0) x--
|
||||||
else if (key == VK_RIGHT && x < w) x = x + 1
|
else if (key == VK_RIGHT && x < w) x++
|
||||||
else if (key == VK_UP && y > 0) y = y - 1
|
else if (key == VK_UP && y > 0) y--
|
||||||
else if (key == VK_DOWN && y < h) y = y + 1
|
else if (key == VK_DOWN && y < h) y++
|
||||||
else if key == VK_ESCAPE run = 0
|
else if key == VK_ESCAPE run = 0
|
||||||
|
|
||||||
color(255,255,255)
|
color(255,255,255)
|
||||||
|
@ -20,27 +20,24 @@ repaint()
|
|||||||
|
|
||||||
def cpoly(cx, cy, size) {
|
def cpoly(cx, cy, size) {
|
||||||
ox = cx oy = cy - size
|
ox = cx oy = cy - size
|
||||||
i = 0
|
|
||||||
ang = 0
|
ang = 0
|
||||||
while i < NUM_POINTS {
|
for i = 0, i < NUM_POINTS, i++ {
|
||||||
ang = ang + angle
|
ang += angle
|
||||||
nx = cx - sin(ang)*size ny = cy - cos(ang)*size
|
nx = cx - sin(ang)*size ny = cy - cos(ang)*size
|
||||||
line(ox, oy, nx, ny)
|
line(ox, oy, nx, ny)
|
||||||
ox = nx oy = ny
|
ox = nx oy = ny
|
||||||
i = i + 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def fractal(cx, cy, size) {
|
def fractal(cx, cy, size) {
|
||||||
if size >= 3 {
|
if size >= 3 {
|
||||||
s2 = size / 2
|
s2 = size / 2
|
||||||
|
sD = size / DIVIDER
|
||||||
color(0, 0, 255 - size * 255 / w/2)
|
color(0, 0, 255 - size * 255 / w/2)
|
||||||
cpoly(cx, cy, size / DIVIDER)
|
cpoly(cx, cy, sD)
|
||||||
fractal(cx, cy - s2, size / DIVIDER)
|
fractal(cx, cy - s2, sD)
|
||||||
n = 0
|
for n = 0, n < NUM_POINTS, n++ {
|
||||||
while n < NUM_POINTS {
|
fractal(cx - sin(angle*n)*s2, cy - cos(angle*n)*s2, sD)
|
||||||
fractal(cx - sin(angle*n)*s2, cy - cos(angle*n)*s2, size / DIVIDER)
|
|
||||||
n = n + 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,11 +14,12 @@ def rect(x, y, w, h) {
|
|||||||
|
|
||||||
def fractal(cx, cy, size) {
|
def fractal(cx, cy, size) {
|
||||||
if size >= 2 {
|
if size >= 2 {
|
||||||
|
s2 = size / 2
|
||||||
color(0, 0, 255 - size * 255 / w/2)
|
color(0, 0, 255 - size * 255 / w/2)
|
||||||
rect(cx-size/2, cy-size/2, size, size)
|
rect(cx-s2, cy-s2, size, size)
|
||||||
fractal(cx-size/2, cy-size/2, size / 2)
|
fractal(cx-s2, cy-s2, s2)
|
||||||
fractal(cx+size/2, cy-size/2, size / 2)
|
fractal(cx+s2, cy-s2, s2)
|
||||||
fractal(cx-size/2, cy+size/2, size / 2)
|
fractal(cx-s2, cy+s2, s2)
|
||||||
fractal(cx+size/2, cy+size/2, size / 2)
|
fractal(cx+s2, cy+s2, s2)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,8 @@ echo(-8 >> 2)
|
|||||||
echo(-8 >>> 2)
|
echo(-8 >>> 2)
|
||||||
|
|
||||||
echo()
|
echo()
|
||||||
for a = 0, a <= 1, a = a + 1 {
|
for a = 0, a <= 1, a++ {
|
||||||
for b = 0, b <= 1, b = b + 1 {
|
for b = 0, b <= 1, b++ {
|
||||||
echo(a, " | ", b, " ", a | b)
|
echo(a, " | ", b, " ", a | b)
|
||||||
echo(a, " & ", b, " ", a & b)
|
echo(a, " & ", b, " ", a & b)
|
||||||
echo(a, " ^ ", b, " ", a ^ b)
|
echo(a, " ^ ", b, " ", a ^ b)
|
||||||
|
@ -17,7 +17,7 @@ def fibonacci(count) {
|
|||||||
return fib(count)
|
return fib(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 0, i < 10, i = i + 1
|
for i = 0, i < 10, i++
|
||||||
print " " + fibonacci(i)
|
print " " + fibonacci(i)
|
||||||
print "\n"
|
print "\n"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ fieldY = rand(fieldHeight) - h2
|
|||||||
NUM_FOOD = 350
|
NUM_FOOD = 350
|
||||||
food = newarray(4, NUM_FOOD)
|
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[0][i] = rand(fieldWidth)
|
||||||
food[1][i] = rand(fieldHeight)
|
food[1][i] = rand(fieldHeight)
|
||||||
food[2][i] = 6 + rand(2)
|
food[2][i] = 6 + rand(2)
|
||||||
@ -31,8 +31,8 @@ run = 1
|
|||||||
while run {
|
while run {
|
||||||
mouse = mousehover()
|
mouse = mousehover()
|
||||||
angle = atan2(mouse[1] - h2, mouse[0] - w2)
|
angle = atan2(mouse[1] - h2, mouse[0] - w2)
|
||||||
fieldX = fieldX + cos(angle) * 50/playerSize
|
fieldX += cos(angle) * 50/playerSize
|
||||||
fieldY = fieldY + sin(angle) * 50/playerSize
|
fieldY += sin(angle) * 50/playerSize
|
||||||
if (fieldX < -w2) fieldX = -w2
|
if (fieldX < -w2) fieldX = -w2
|
||||||
else if (fieldX > fieldWidth - w2 - 1) fieldX = fieldWidth - w2 - 1
|
else if (fieldX > fieldWidth - w2 - 1) fieldX = fieldWidth - w2 - 1
|
||||||
if (fieldY < -h2) fieldY = -h2
|
if (fieldY < -h2) fieldY = -h2
|
||||||
@ -45,13 +45,13 @@ while run {
|
|||||||
color(#333333)
|
color(#333333)
|
||||||
rect(-fieldX, -fieldY, fieldWidth, fieldHeight)
|
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
|
dx = food[0][i] - fieldX - w2
|
||||||
dy = food[1][i] - fieldY - h2
|
dy = food[1][i] - fieldY - h2
|
||||||
rad = food[2][i] + playerSize
|
rad = food[2][i] + playerSize
|
||||||
if ( (dx*dx + dy*dy) < (rad*rad) ) {
|
if ( (dx*dx + dy*dy) < (rad*rad) ) {
|
||||||
// есть столкновение
|
// есть столкновение
|
||||||
playerSize = playerSize + 1
|
playerSize++
|
||||||
food[0][i] = rand(w)
|
food[0][i] = rand(w)
|
||||||
food[1][i] = rand(h)
|
food[1][i] = rand(h)
|
||||||
food[2][i] = 6 + rand(2)
|
food[2][i] = 6 + rand(2)
|
||||||
|
@ -33,34 +33,36 @@ support = [
|
|||||||
|
|
||||||
def draw(v, cellSize) {
|
def draw(v, cellSize) {
|
||||||
c2 = cellSize / 2
|
c2 = cellSize / 2
|
||||||
if (v == HORIZONTAL) fillRect(0, c2 - 2, cellSize, 4)
|
match v {
|
||||||
else if (v == VERTICAL) fillRect(c2 - 2, 0, 4, cellSize)
|
case HORIZONTAL : fillRect(0, c2 - 2, cellSize, 4)
|
||||||
else if (v == LEFT_TO_DOWN) {
|
case VERTICAL : fillRect(c2 - 2, 0, 4, cellSize)
|
||||||
|
case LEFT_TO_DOWN : {
|
||||||
fillRect(0, c2 - 2, c2, 4)
|
fillRect(0, c2 - 2, c2, 4)
|
||||||
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
|
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
|
||||||
}
|
}
|
||||||
else if (v == LEFT_TO_UP) {
|
case LEFT_TO_UP : {
|
||||||
fillRect(0, c2 - 2, c2, 4)
|
fillRect(0, c2 - 2, c2, 4)
|
||||||
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
|
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
|
||||||
}
|
}
|
||||||
else if (v == RIGHT_TO_UP) {
|
case RIGHT_TO_UP : {
|
||||||
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
|
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
|
||||||
fillRect(c2 - 2, 0, 4, c2 + 2)
|
fillRect(c2 - 2, 0, 4, c2 + 2)
|
||||||
}
|
}
|
||||||
else if (v == RIGHT_TO_DOWN) {
|
case RIGHT_TO_DOWN : {
|
||||||
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
|
fillRect(c2 - 2, c2 - 2, c2 + 2, 4)
|
||||||
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
|
fillRect(c2 - 2, c2 - 2, 4, c2 + 2)
|
||||||
}
|
}
|
||||||
else if (v == CROSS) {
|
case CROSS : {
|
||||||
fillRect(c2 - 2, 0, 4, cellSize)
|
fillRect(c2 - 2, 0, 4, cellSize)
|
||||||
fillRect(0, c2 - 2, cellSize, 4)
|
fillRect(0, c2 - 2, cellSize, 4)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def supportLeft(v) return support[v][0]
|
def supportLeft(v) = support[v][0]
|
||||||
def supportRight(v) return support[v][1]
|
def supportRight(v) = support[v][1]
|
||||||
def supportUp(v) return support[v][2]
|
def supportUp(v) = support[v][2]
|
||||||
def supportDown(v) return support[v][3]
|
def supportDown(v) = support[v][3]
|
||||||
///-------------------------------------
|
///-------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@ -73,8 +75,8 @@ SIZE = 10
|
|||||||
board = newarray(SIZE, SIZE)
|
board = newarray(SIZE, SIZE)
|
||||||
|
|
||||||
def createBoard() {
|
def createBoard() {
|
||||||
for i=0, i<SIZE, i=i+1
|
for i=0, i<SIZE, i++
|
||||||
for j=0, j<SIZE, j=j+1
|
for j=0, j<SIZE, j++
|
||||||
board[i][j] = rand(CELL_LAST)
|
board[i][j] = rand(CELL_LAST)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +146,10 @@ run = 1
|
|||||||
while run {
|
while run {
|
||||||
//key = gameaction(keypressed())
|
//key = gameaction(keypressed())
|
||||||
key = keypressed()
|
key = keypressed()
|
||||||
if (key == VK_LEFT && curX > 0) curX = curX - 1
|
if (key == VK_LEFT && curX > 0) curX--
|
||||||
else if (key == VK_RIGHT && curX < SIZE - 1) curX = curX + 1
|
else if (key == VK_RIGHT && curX < SIZE - 1) curX++
|
||||||
else if (key == VK_UP && curY > 0) curY = curY - 1
|
else if (key == VK_UP && curY > 0) curY--
|
||||||
else if (key == VK_DOWN && curY < SIZE - 1) curY = curY + 1
|
else if (key == VK_DOWN && curY < SIZE - 1) curY++
|
||||||
else if key == VK_FIRE switchCell(curX,curY)
|
else if key == VK_FIRE switchCell(curX,curY)
|
||||||
else if key == 48 run = 0
|
else if key == 48 run = 0
|
||||||
|
|
||||||
@ -157,13 +159,13 @@ while run {
|
|||||||
// курсор
|
// курсор
|
||||||
color(#4444FF)
|
color(#4444FF)
|
||||||
frect(curX*cellSize, curY*cellSize, cellSize, cellSize)
|
frect(curX*cellSize, curY*cellSize, cellSize, cellSize)
|
||||||
for (i=0, i<SIZE, i=i+1) {
|
for (i=0, i<SIZE, i++) {
|
||||||
color(0)
|
color(0)
|
||||||
ic = i*cellSize
|
ic = i*cellSize
|
||||||
line(0, ic, cellSize*SIZE, ic)
|
line(0, ic, cellSize*SIZE, ic)
|
||||||
line(ic, 0, ic, cellSize*SIZE)
|
line(ic, 0, ic, cellSize*SIZE)
|
||||||
color(#FF0000)
|
color(#FF0000)
|
||||||
for j=0, j<SIZE, j=j+1 {
|
for j=0, j<SIZE, j++ {
|
||||||
translateX = ic
|
translateX = ic
|
||||||
translateY = j*cellSize
|
translateY = j*cellSize
|
||||||
draw(board[i][j], cellSize)
|
draw(board[i][j], cellSize)
|
||||||
|
@ -20,8 +20,7 @@ thread(::http, "https://api.github.com/events", def(r) {
|
|||||||
|
|
||||||
def show_github_events(event) {
|
def show_github_events(event) {
|
||||||
println event.created_at
|
println event.created_at
|
||||||
actor = event.actor
|
println "User: https://github.com/" + event.actor.login
|
||||||
println "User: https://github.com/" + actor.login
|
|
||||||
println github_event_type(event)
|
println github_event_type(event)
|
||||||
println "-" * 50
|
println "-" * 50
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ xstep = 50 ystep = 5
|
|||||||
startx = 50
|
startx = 50
|
||||||
starty = 400 + ystep / 2
|
starty = 400 + ystep / 2
|
||||||
|
|
||||||
for (y = 0, y < 300, y = y + ystep) {
|
for (y = 0, y < 300, y += ystep) {
|
||||||
|
|
||||||
mouseMove(startx, (starty+y))
|
mouseMove(startx, (starty+y))
|
||||||
mousePress(BUTTON1)
|
mousePress(BUTTON1)
|
||||||
for (i = 0, i < 600, i = i + xstep) {
|
for (i = 0, i < 600, i += xstep) {
|
||||||
mouseMove((startx+i), (starty+y))
|
mouseMove((startx+i), (starty+y))
|
||||||
delay(pause)
|
delay(pause)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user