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