Own-Programming-Language-Tu.../examples/canvas/animate_line.own

56 lines
1.1 KiB
Plaintext
Raw Normal View History

2015-07-11 21:19:59 +03:00
use "canvas"
use "std"
w = 800 h = 600
window("Animate line", w, h)
// Крайние точки линии
x1 = rand(w) y1 = rand(h)
x2 = rand(w) y2 = rand(h)
// Направление движения
d1x = rand() d1y = -rand()
d2x = rand() d2y = rand()
// Очищаем экран
color(rand(#FFFFFF))
frect(0,0,w,h)
hue = 0
run = 1
while run {
if checkhoriz(x1) d1x = -d1x
if checkhoriz(x2) d2x = -d2x
if checkvert(y1) d1y = -d1y
if checkvert(y2) d2y = -d2y
2016-02-14 21:24:06 +02:00
x1 += d1x x2 += d2x
y1 += d1y y2 += d2y
2015-07-11 21:19:59 +03:00
2016-02-14 21:24:06 +02:00
hue += 0.0001
2015-07-11 21:19:59 +03:00
if (hue >= 1) hue = 0
sethsbcolor(hue)
line(x1, y1, x2, y2)
repaint()
sleep(10)
if keypressed() == VK_ESCAPE run = 0
}
2016-02-14 21:24:06 +02:00
def checkhoriz(px) = (px >= w || px < 0)
def checkvert(py) = (py >= h || py < 0)
2015-07-11 21:19:59 +03:00
2016-02-14 21:24:06 +02:00
def floor(v) = v - v % 1
2015-07-11 21:19:59 +03:00
def sethsbcolor(h1) {
qr = h1 * 6 // временно для расчёта
f = qr - floor(qr)
2016-02-14 21:24:06 +02:00
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)
case 3: color(0, 255-f*255, 255)
case 4: color(f*255, 0, 255)
case 5: color(255, 0, 255-f*255)
}
2015-07-11 21:19:59 +03:00
}