03-05-2024, 06:53 AM
Problem
How to make closed loop and curved polyline ?
It makes sharp turn at X.
How to make closed loop and curved polyline ?
It makes sharp turn at X.
Code:
'===============================================
' TEST DRIVE
'
'Problem :
'- How to make closed loop and curved polyline ?
' It makes sharp turn at X.
'===============================================
'------------------
' INITIALIZATION
'------------------
#win32
include "polyline.n7"
set window "Test Drive", 160, 120,false,5
set redraw off
'color definition
white = [255,255,255]
gray = [128,128,128,50]
black = [0,0,0]
black_alpha = [0,0,0,24]
red = [168,0,0]
green = [0,255,0]
'points' coordinates
points = []
points[0] = [20,60]
points[1] = [50,30]
points[2] = [80,60]
points[3] = [110,90]
points[4] = [140,60]
points[5] = [110,30]
points[6] = [80,60]
points[7] = [50,90]
points[8] = [20,60]
' Create a polyline
path = PolyLine(points)
' Variables
distance = 1
move_pixel = 4
radius = 2
'-------------
' MAIN LOOP
'-------------
while not keydown(KEY_ESCAPE, true)
' Title
set caret width(primary)/2, 6; center "Test Drive"
set caret width(primary)/2, height(primary)-20; center "Sharp turn at X"
' Racing Track
set color gray ; draw ellipse 50-1,60, 32,32,1;draw ellipse 110+2,60, 32,32,1
set color black ; draw ellipse 50-1,60, 21,21,1;draw ellipse 110+2,60, 21,21,1
set color white ; set caret 20-8,60-6; wln "x"
'Polyline functions : .GetLength(), .GetPoint()
distance = (distance + move_pixel)%path.GetLength()
pos = path.GetPoint(distance,true) 'false = sharp, true = curved
' Draw circle that moves along path.
set color black_alpha; cls 'clear background screen
set color green; draw ellipse pos[0], pos[1], radius, radius, 1
redraw
fwait 10
wend