It is currently Fri Oct 18, 2019 8:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: AddPathCurve : insert point
PostPosted: Tue Mar 29, 2016 10:20 am 
Offline
Enthusiast
Enthusiast
User avatar

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
 Profile  
Reply with quote  
 Post subject: Re: AddPathCurve : insert point
PostPosted: Thu Mar 31, 2016 7:09 am 
Offline
Enthusiast
Enthusiast
User avatar

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
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 guests


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

Search for:
Jump to:  

 


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