# PureBasic Forum

 It is currently Fri May 29, 2020 2:46 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: AddPathCurve : insert pointPosted: Tue Mar 29, 2016 10:20 am
 Enthusiast

Joined: Thu Apr 07, 2011 1:14 pm
Posts: 243
Location: 3 arks
Hi

Do you know if there is a way to insert point in a shape made with AddPathCurve() ?

Code:
#G_canvasVector=0
Global Dim pt.Point(8)

; add some point to begin
t\$ = "134/212/117/283/252/350/310/324/348/309/300/199/351/219/351/140/133/139/"
For i= 0 To ArraySize(pt())
pt(i)\x = Val(StringField(t\$,i*2+1,"/"))
pt(i)\y = Val(StringField(t\$,i*2+2,"/"))
Next

LoadFont(0, "arial", 20)

Procedure Drawcanvas(x=-100,y=-100,ok=0,insert=0)

If StartVectorDrawing(CanvasVectorOutput(0))

; gray background
AddPathBox(0,0, GadgetWidth(0),GadgetHeight(0))
VectorSourceColor(RGBA(200,200,200,255))
FillPath()

; draw points
For i =0 To ArraySize(pt())
MovePathCursor(pt(i)\x,pt(i)\y)
VectorFont(FontID(0), 25)

VectorSourceColor(RGBA(0, 0, 0, 80))

DrawVectorText(Str(i))
Next

MovePathCursor(pt(0)\x,pt(0)\y)
For i =0 To ArraySize(pt())
;AddPathLine(pt(i)\x, pt(i)\y)

If Mod(i,3)=0
AddPathBox(pt(i)\x-5,pt(i)\y-5,10,10)
VectorSourceColor(RGBA(255,0,0,100))
FillPath()
Else
If Mod(i,3)=1
u = i-1
If u<0
u = ArraySize(pt())
EndIf
MovePathCursor(pt(i)\x,pt(i)\y)
AddPathLine(pt(i)\x, pt(i)\y)
AddPathLine(pt(u)\x, pt(u)\y)
VectorSourceColor(RGBA(0,0,0,100))
StrokePath(1)
Else
u = i+1
If u>ArraySize(pt())
u = 0
EndIf
MovePathCursor(pt(i)\x,pt(i)\y)
AddPathLine(pt(i)\x, pt(i)\y)
AddPathLine(pt(u)\x, pt(u)\y)
VectorSourceColor(RGBA(0,0,0,100))
StrokePath(1)
EndIf

AddPathCircle(pt(i)\x,pt(i)\y,5)
VectorSourceColor(RGBA(255,255,0,100))
FillPath()
EndIf
Next

; Draw the shape
MovePathCursor(pt(0)\x,pt(0)\y)
For i =0 To ArraySize(pt()) Step 3

u = 1+i
If u > ArraySize(pt())
u =0
EndIf
v = u+1
If v > ArraySize(pt())
v =0
EndIf
w = v+1
If w > ArraySize(pt())
w=0
EndIf
;AddPathLine(pt(u)\x, pt(u)\y)
;AddPathLine(pt(v)\x, pt(v)\y)
AddPathCurve(pt(u)\x, pt(u)\y,pt(v)\x,pt(v)\y,pt(w)\x,pt(w)\y)
Next
VectorSourceColor(RGBA(0,0,0,120))
FillPath()
StopVectorDrawing()

EndIf
EndProcedure

w=800
h=600
OpenWindow(0,0,0,w,h,"insert point",#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_SystemMenu)

CanvasGadget(0,0,0,w,h)
Drawcanvas()

Repeat

event =WaitWindowEvent()

If event = #PB_Event_Gadget
If EventGadget() = 0

If EventType() = #PB_EventType_LeftButtonDown Or
(EventType() = #PB_EventType_MouseMove And
GetGadgetAttribute(#G_canvasVector, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)

If StartVectorDrawing(CanvasVectorOutput(#G_canvasVector))
x = GetGadgetAttribute(#G_canvasVector, #PB_Canvas_MouseX)
y = GetGadgetAttribute(#G_canvasVector, #PB_Canvas_MouseY)

If EventType() = #PB_EventType_LeftButtonDown
move = 0
For i= 0 To ArraySize(pt())
If x >= pt(i)\x-5 And x<=pt(i)\x-5+10 And y>=pt(i)\y-5 And y<=pt(i)\y-5+10
k1 = i
move = 1
Break
EndIf
Next
EndIf

StopVectorDrawing()

Drawcanvas(x,y,1)
If move = 1
pt(k1)\x = x
pt(k1)\y = y
Debug "point "+i+" : "+x+"/"+y
Else
; we don't move, but we have made a cli : add the point here !
If clic = 0
clic = 1
; InsertPt(k,x,y)
EndIf
EndIf
EndIf

ElseIf EventType() = #PB_EventType_MouseMove

If StartVectorDrawing(CanvasVectorOutput(#G_canvasVector))
x = GetGadgetAttribute(#G_canvasVector, #PB_Canvas_MouseX)
y = GetGadgetAttribute(#G_canvasVector, #PB_Canvas_MouseY)
StopVectorDrawing()
Drawcanvas(x,y,move)
EndIf

ElseIf EventType() = #PB_EventType_LeftButtonUp
Drawcanvas()
move = 0
clic = 0
EndIf

EndIf
EndIf

Until event = #PB_Event_CloseWindow

If this exemple, I would like to insert a point between 0 and 3 or 3 and 6 for exemple (at mouseX, mouseY).
Do you know how I can do that ?

Thanks a lot .

Top

 Post subject: Re: AddPathCurve : insert pointPosted: Thu Mar 31, 2016 7:09 am
 Enthusiast

Joined: Thu Apr 07, 2011 1:14 pm
Posts: 243
Location: 3 arks
Quote:
Quote:
[blendman] wrote:
Do you know if there is a way to insert point in a shape made with AddPathCurve() ?

Wilbert wrote:
Using De Casteljau's algorithm, you can get any point on a shape made with AddPathCurve().
I hope that helps.
Hi

I don't know why, your post has desappeared. But thanks for your link, i could probably use this algorithm. Now I have to understand how to add points easily ^^.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 11 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite

Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye