use ["canvas", "math", "std"] ball = {"x": 400, "y": 400, "sx": 5.0, "sy": 5.0} max_speed = 25 down = false x = 0.00 y = 0.00 x2 = 0.00 y2 = 0.00 rad = 0 def vlen(x1, y1, x2, y2) = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) // вычесление длины вектора canvas = showcanvas() setOnTouchEvent(::onTouch) canvas.setTextSize(25) while (true) { update() render() repaint() sleep(33) // задержка перед следующим рендерингом кадра } def render() { canvas.drawColor(#ff343434) canvas.setColor(#ffff0076) canvas.drawCircle(ball.x, ball.y, 30) if (down) { canvas.setColor(#ff0097f0) canvas.setStyle(Style.STROKE) canvas.setStrokeWidth(5) canvas.drawCircle(x, y, 65) canvas.drawCircle(x, y, 130) canvas.setStyle(Style.FILL) canvas.drawCircle(x2, y2, 60) canvas.drawLine(x, y, x2, y2) } canvas.setColor(#ffaa7500) canvas.drawText("x1="+x+",y1="+y+",x2="+x2+",y2="+y2, 0,50) canvas.drawText("Stick: " + cos(rad)+","+sin(rad), 0, 75) canvas.drawText("sp: " + ball.sx +","+ball.sy, 0, 100) canvas.drawText("rad: " + rad, 0, 125) } def update() { if (down) { rad = atan2(y2 - y , x2 - x) len = sqrt((x2-x)*(x2-x)+(y2-y)*(y2-y)) if (len > 130) len = 130 dx = len * max_speed / 130 ball.sx = cos(rad) * dx ball.sy = sin(rad) * dx } ball.sx *= 0.9 // Замедление ball.sy *= 0.9 // .. ball.x += ball.sx ball.y += ball.sy } def onTouch(e) { // Обработка тача if (e.action == Action.DOWN) { down = true x = e.x y = e.y х2 = e.x y2 = e.y } if (e.action == Action.MOVE) { x2 = e.x y2 = e.y } if (e.action == Action.UP) down = false }