Page 1 sur 1

Modification de formes

Publié : mer. 01/oct./2008 11:52
par popstatic
bonjour a tous, j'en appelle a vous aujourd'hui pour savoir si un d'entre vous aurait un exemple concret de "dessin/redimension" de formes, par exemple pouvoir dessiner un rectangle a la souris (comme l'outil rectangle sous paint quoi) et pouvoir en suite modifier sa taille a l'aide de "poignées" (des ptits carrés par exemple)qui apparaitraient a ses coins lorsque l'on clique dessus....

helas je n'ai aucune piste, alors merci d'avance!

(PS ne vous cassez pas la tête hein, un exemple tout bete ira tres bien)

Publié : mer. 01/oct./2008 12:03
par popstatic
oooooops, j'ai parlé très vite avant de voir ce thread recent... http://www.purebasic.fr/french/viewtopic.php?t=8566

il y a creation de forme et detection de colision....
je vais essayer de voir ce que je peux faire, et je posterai si je trouve qq chose d'interessant

Publié : mer. 01/oct./2008 18:04
par kernadec
bonjour
ce que tu cherche c'est peut etre un truc comme celui la
carrément génial, je l'ai trouve sur le forum english
pour cela il suffit de charger google traducteur et dans la ligne Http;//
recopier le nom du site qui devient forum french...

Code : Tout sélectionner

; http://www.purebasic.fr/english/viewtopic.php?t=34138&highlight=open+fullscreen+mode
; auteur :  Raybarg   titre : Line Madness program 
;#####################################################################################
EnableExplicit

#RAD = 0.0175
#VEC_SCR_WIDTH = 800
#VEC_SCR_HEIGHT = 600
#VEC_SCR_DEPTH = 16
#VEC_INDICATOR_SIZE = 15

#VEC_SNOWFLAKES = 2000

Structure tVertex
  x.l
  y.l
EndStructure

Structure tSnowFlake
  x.f
  y.f
EndStructure

Declare.f findangle(x1.f,y1.f,X2.f,Y2.f)
Declare.l Vectorz_Main()
Declare.l Vertex_Add( Vertex.tVertex(), lX.l, lY.l )
Declare.l Vertex_Display( Vertex.tVertex(), bS.b )

Vectorz_Main()


Procedure.l Vectorz_Main()
  Protected mx.l, my.l, AddReleased.b = #True, bShowDebug.b = #False
  Protected hovered.l
  Protected *selected.tVertex, *previous.tVertex, *near1.tVertex, *near2.tVertex, lListPositionForNearest.l
  Protected bFound.b, bMovingVertex.b = #False
  Protected *temp.tVertex
  Protected Distance.f, angle.f, tempsnow.f
  Protected lCheckX.l, lCheckY.l
  Protected lMouseDistance.l, lPreviousDistance.l, lAddSnow.l
  
  NewList Vertex.tVertex()
  NewList Snow.tSnowFlake()
  
  Vertex_Add( Vertex.tVertex(), 100, 100 )
  Vertex_Add( Vertex.tVertex(), 100, 200 )
  Vertex_Add( Vertex.tVertex(), 200, 200 )
  Vertex_Add( Vertex.tVertex(), 200, 100 )
  
  *selected = @Vertex()
  
  If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
    MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  Else
    If OpenScreen(#VEC_SCR_WIDTH, #VEC_SCR_HEIGHT, #VEC_SCR_DEPTH, "Pixel Madness by Raybarg")
      Repeat
        FlipBuffers()
        ClearScreen(RGB(0,0,0))
        ExamineKeyboard()
        ExamineMouse()
        
        mx = MouseX()
        my = MouseY()
        
        If KeyboardPushed(#PB_Key_Add)
          If AddReleased = #True
            Vertex_Add( Vertex.tVertex(), mx, my )
            AddReleased = #False
          EndIf
        Else
          AddReleased = #True
        EndIf
        
        bMovingVertex = #False
        If MouseButton( #PB_MouseButton_Left ) And bFound = #True
          *selected\x = mx
          *selected\y = my
          bMovingVertex = #True
        ElseIf MouseButton( #PB_MouseButton_Left ) And lListPositionForNearest >= 0
          SelectElement( Vertex(), lListPositionForNearest )
          InsertElement( Vertex() )
          Vertex()\x = mx
          Vertex()\y = my
        EndIf
        
        If MouseButton( #PB_MouseButton_Right )
          bShowDebug = #True
        Else
          bShowDebug = #False
        EndIf
        
        StartDrawing( ScreenOutput() )
          Vertex_Display( Vertex.tVertex(), bShowDebug )
          
          bFound=#False
          *previous = #Null
          *near1 = #Null
          lListPositionForNearest = -1
          
          ForEach Vertex()
            If  mx >= Vertex()\x - (#VEC_INDICATOR_SIZE/2) And  mx <= Vertex()\x + (#VEC_INDICATOR_SIZE/2) And my >= Vertex()\y - (#VEC_INDICATOR_SIZE/2) And my <= Vertex()\y + (#VEC_INDICATOR_SIZE/2)
              FrontColor( RGB( 200,0,0))
              DrawingMode( #PB_2DDrawing_Outlined )
              Box( Vertex()\x - (#VEC_INDICATOR_SIZE/2-1), Vertex()\y - (#VEC_INDICATOR_SIZE/2-1), #VEC_INDICATOR_SIZE-1, #VEC_INDICATOR_SIZE-1 )
              bFound = #True
              If bMovingVertex = #False
                *selected.tVertex = @Vertex.tVertex()
              EndIf
              Break
            EndIf
          Next
          ForEach Vertex()
            If *previous = #Null
              *previous = @Vertex()
              *near1 = @Vertex()
              *near2 = @Vertex()
              lPreviousDistance = 9999
            Else
              Distance = Sqr( Pow(Vertex()\x-*previous\x,2) + Pow(Vertex()\y-*previous\y,2) )
              angle = findangle(Vertex()\x, Vertex()\y, *previous\x, *previous\y)
              lCheckX = *previous\x+Cos(angle *#RAD)*(Distance/2)
              lCheckY = *previous\y+Sin(angle *#RAD)*(Distance/2)
              lMouseDistance = Sqr( Pow(lCheckX-mx,2) + Pow(lCheckY-my,2) )
              If lMouseDistance < Distance/2 And lMouseDistance < lPreviousDistance
                *near1 = *previous
                *near2 = @Vertex()
                lListPositionForNearest = ListIndex( Vertex() )
                lPreviousDistance = lMouseDistance
              EndIf
              *previous = @Vertex()
            EndIf
          Next
          If lListPositionForNearest >= 0 And bFound = #False
            LineXY( *near1\x, *near1\y, *near2\x, *near2\y, RGB($FF,$CC,00) )
          EndIf
          
          
          
          If lAddSnow < #VEC_SNOWFLAKES
            AddElement( Snow() )
            Snow()\x = Random( #VEC_SCR_WIDTH/2 ) + #VEC_SCR_WIDTH/4
            Snow()\y = 1
            lAddSnow = lAddSnow +1
          EndIf
          
          FrontColor( RGB( 255,255,255))
          ForEach Snow()
            tempsnow = Snow()\x + Random(100/50)-1
            
            If Point(tempsnow, Snow()\y+1) = 0 And Point(Snow()\x,Snow()\y+1) = 0
              Snow()\y = Snow()\y + 1
              Snow()\x = tempsnow
            ElseIf Point(Snow()\x+1,Snow()\y) = 0 And Point(Snow()\x+1,Snow()\y+1) = 0 And Point(Snow()\x+1,Snow()\y-1) = 0
              Snow()\y = Snow()\y -1
              Snow()\x = Snow()\x +1
            ElseIf Point(Snow()\x-1,Snow()\y) = 0 And Point(Snow()\x-1,Snow()\y+1) = 0 And Point(Snow()\x-1,Snow()\y-1) = 0
              Snow()\y = Snow()\y -1
              Snow()\x = Snow()\x -1
            EndIf
            
            Plot( Snow()\x, Snow()\y )
            If Snow()\y >= #VEC_SCR_HEIGHT-5
              Snow()\x = Random( #VEC_SCR_WIDTH/2 ) + #VEC_SCR_WIDTH/4
              Snow()\y = 1
            EndIf
          Next
          
          
          FrontColor( RGB( 128,0,0))
          Line( mx - 6, my, 13, 0 )
          Line( mx, my - 6, 0, 13 )
        StopDrawing()
        
      Until KeyboardPushed(#PB_Key_Escape)
      
    Else
      MessageRequester("Error", "Could not open fullscreen mode", 0)
    EndIf
  EndIf
  
  ProcedureReturn #Null
EndProcedure

Procedure.l Vertex_Add( Vertex.tVertex(), lX.l, lY.l )
  AddElement( Vertex() )
  Vertex()\x = lX
  Vertex()\y = lY
  
  ProcedureReturn #Null
EndProcedure

Procedure.l Vertex_Display( Vertex.tVertex(), bS.b )
  Protected lPX.l, lPY.l, Distance.f, angle.f
  
  DrawingMode( #PB_2DDrawing_Outlined )
  ResetList( Vertex() )
  While NextElement( Vertex() )
    FrontColor( RGB( 128,128,128))
    Box( Vertex()\x - (#VEC_INDICATOR_SIZE/2), Vertex()\y - (#VEC_INDICATOR_SIZE/2), #VEC_INDICATOR_SIZE+1, #VEC_INDICATOR_SIZE+1 )
    If lPX <> 0
      LineXY( Vertex()\x, Vertex()\y, lPX, lPY )
      
      If bS = #True
        Distance = Sqr( Pow(Vertex()\x-lPX,2) + Pow(Vertex()\y-lPY,2) )
        angle = findangle(Vertex()\x, Vertex()\y, lPX, lPY)
        FrontColor( RGB( $80,00,00))
        Circle( lPX+Cos(angle *#RAD)*(Distance/2), lPY+Sin(angle *#RAD)*(Distance/2), Distance/2 )
      EndIf
    EndIf
    lPX = Vertex()\x
    lPY = Vertex()\y
  Wend
  
  ProcedureReturn #Null
EndProcedure

Procedure.f findangle( x1.f, y1.f, X2.f, Y2.f )
  Protected A.f, b.f, C.f, angle.f
  A.f = x1 - X2
  b.f = Y2 - y1
  C.f = Sqr( A * A + b * b )
  angle.f = ACos( A / C ) * 57.29577
  If y1 < Y2
    angle = 360.0 - angle
  EndIf
  ProcedureReturn angle.f
EndProcedure

Publié : mer. 01/oct./2008 19:20
par Frenchy Pilou
Tombe la neige! 8O

Publié : jeu. 02/oct./2008 1:52
par popstatic
kernadec a écrit :bonjour
ce que tu cherche c'est peut etre un truc comme celui la
carrément génial, je l'ai trouve sur le forum english
pour cela il suffit de charger google traducteur et dans la ligne Http;//
recopier le nom du site qui devient forum french...
Ah [Censuré] c'est ca a outrance! ^^
me reste plus qu'a le mettre en fenetré, a mettre l'edition en rectangle(s) et ca sera paaaaaarfait! merci a toi!


[Modérateur] retiens toi un peu quand même

Publié : jeu. 02/oct./2008 21:21
par popstatic
@ modérateur: désolé :oops:

Publié : ven. 03/oct./2008 5:56
par kernadec
bonjour Popstatic
tu n'as pas a être désolé!! tu n'as fait de tort a personne il me semble,
je suis comme toi, heureux de vivre une passion

un Modérateur rabajoie qui n'as pas la courage de ses opinions
tu n'en as que faire voila!

quand je trouve un code intéressant sur ce forum ou ailleurs
qui me permet de progresser plus rapidement dans cette passion,
cela me donne de la joie de vivre m'encourage et me rend heureux,
et qui ne le serait pas??
c'est pour cela que j'essaye de partager cette passion en renvoyant l'ascenseur avec mes modestes moyens.

Publié : ven. 03/oct./2008 10:23
par Backup
kernadec a écrit :bonjour Popstatic
tu n'as pas a être désolé!! tu n'as fait de tort a personne il me semble,
je suis comme toi, heureux de vivre une passion

un Modérateur rabajoie qui n'as pas la courage de ses opinions
tu n'en as que faire voila! .
pour rappel voici la liste des modérateurs de ce forum (ordre par nombre de messages sur le forum)
Dobro
Flype
Le Soldat Inconnu
LeCyb
nico
je ne sais pas lequel a moderé ce post (c'est pas moi)

mais de toute façon il s'agissait surement d'un propos "Malpoli"
et dans ce cas , ce modo a bien fait !! on est aussi lu par des mineures, des enfants....
et de toute façon un peu de surveillance des propos ne fait pas de mal :)

j'aurai modéré en mettant mon pseudo personellement, mais bon apres tout le message est passé non ? :)