mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
57 lines
1.3 KiB
Scala
57 lines
1.3 KiB
Scala
|
use "canvas"
|
||
|
use "std"
|
||
|
|
||
|
w = 800 h = 600
|
||
|
window("Animate line with thread", 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)
|
||
|
|
||
|
run = 1
|
||
|
thread("changehue")
|
||
|
|
||
|
def changehue() {
|
||
|
hue = 0
|
||
|
while run {
|
||
|
hue = hue + 0.0001
|
||
|
if (hue >= 1) hue = 0
|
||
|
qr = hue * 6 // временно для расчёта
|
||
|
hueindex = (qr - qr % 1) % 6
|
||
|
f = qr - (qr - qr % 1)
|
||
|
|
||
|
if hueindex == 0 color(255, f*255, 0)
|
||
|
else if hueindex == 1 color(255 - f*255, 255, 0)
|
||
|
else if hueindex == 2 color(0, 255, f*255)
|
||
|
else if hueindex == 3 color(0, 255-f*255, 255)
|
||
|
else if hueindex == 4 color(f*255, 0, 255)
|
||
|
else if hueindex == 5 color(255, 0, 255-f*255)
|
||
|
sleep(5)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
while run {
|
||
|
if checkhoriz(x1) d1x = -d1x
|
||
|
if checkhoriz(x2) d2x = -d2x
|
||
|
if checkvert(y1) d1y = -d1y
|
||
|
if checkvert(y2) d2y = -d2y
|
||
|
|
||
|
x1 = x1 + d1x x2 = x2 + d2x
|
||
|
y1 = y1 + d1y y2 = y2 + d2y
|
||
|
|
||
|
line(x1, y1, x2, y2)
|
||
|
repaint()
|
||
|
sleep(10)
|
||
|
if keypressed() == VK_ESCAPE run = 0
|
||
|
}
|
||
|
|
||
|
def checkhoriz(px) return (px >= w || px < 0)
|
||
|
def checkvert(py) return (py >= h || py < 0)
|