Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PolyLine library
#13
Problem
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
Reply


Messages In This Thread
PolyLine library - by Marcus - 02-29-2024, 04:25 PM
RE: PolyLine library - by aliensoldier - 02-29-2024, 04:54 PM
RE: PolyLine library - by kevin - 03-01-2024, 11:32 AM
RE: PolyLine library - by Marcus - 03-01-2024, 02:40 PM
RE: PolyLine library - by kevin - 03-01-2024, 03:02 PM
RE: PolyLine library - by Marcus - 03-01-2024, 06:32 PM
RE: PolyLine library - by kevin - 03-01-2024, 08:05 PM
RE: PolyLine library - by Marcus - 03-02-2024, 01:23 PM
RE: PolyLine library - by johnno56 - 03-01-2024, 09:36 PM
RE: PolyLine library - by Marcus - 03-01-2024, 10:03 PM
RE: PolyLine library - by kevin - 03-02-2024, 04:48 PM
RE: PolyLine library - by Marcus - 03-02-2024, 06:20 PM
RE: PolyLine library - by 1micha.elok - 03-05-2024, 06:53 AM
RE: PolyLine library - by kevin - 03-05-2024, 08:42 AM
RE: PolyLine library - by 1micha.elok - 03-05-2024, 11:15 AM
RE: PolyLine library - by Marcus - 03-05-2024, 08:52 PM
RE: PolyLine library - by Marcus - 03-08-2024, 08:21 PM
RE: PolyLine library - by 1micha.elok - 03-09-2024, 02:53 AM
RE: PolyLine library - by Marcus - 03-09-2024, 07:43 AM
RE: PolyLine library - by Marcus - 03-10-2024, 10:10 AM
RE: PolyLine library - by 1micha.elok - 03-11-2024, 12:52 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)