si t'as pas vu ça, alors effectivement, t'es un vicelard !!

Code : Tout sélectionner
#Jours_par_Semaine = 7
#Heures_par_Jour = 24
#Mn_par_Heure = 60
#Sec_par_Heure = 3600
#Sec_par_Mn = 60
Procedure Jour_en_Secondes(Jours.i)
secondes = Jours * #Heures_par_Jour * #Mn_par_Heure * #Sec_par_Mn
ProcedureReturn secondes
EndProcedure
Debug Jour_en_Secondes(1)
Code : Tout sélectionner
;Patrick88 - 06/03/2018 - Recherche de du point d'intersection de 2 segments d'après
; http://www.purebasic.fr/french/viewtopic.php?f=1&t=17175
;Niveau de difficulté : *
;Structure d'un vecteur
Structure Vector
x.f ;Position x
y.f ;Position y
EndStructure
;Points A, B et *pt
Global A.Vector, B.Vector, C.Vector, D.Vector, *pt.vector ; pt = pt d'intersection
;Afficher un texte
Global SpriteText, Buffer.s = "Intersection de 2 segments [A B] et [C D]", TextWidth, TextHeight
;Marge affichage texte
Global Margin = 6
;Plan de l'application
Declare GameStart()
Declare GameUpdate()
Declare GameEnd()
;Math
Declare.i inter2DPoint(*P1.Vector, *P2.Vector ,*P3.Vector, *P4.Vector)
GameStart()
Procedure GameStart()
If InitSprite()
InitKeyboard()
InitMouse()
;Définition du point A
A\x = 100
A\y = 150
;Définition du point B
B\x = 575
B\y = 525
;Définition du point A
C\x = 150
C\y = 573
;Définition du point B
D\x = 585
D\y = 50
*pt = Inter2DPoint(A, B, C, D)
OpenWindow(0, 0, 0, 800, 600, "Jeu de Math : Intersection de 2 segments [A B] et [C D]", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
BindEvent(#PB_Event_CloseWindow, @GameEnd())
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
;Creation du sprite text à afficher
SpriteText = CreateSprite(#PB_Any, 120, 24, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(SpriteText))
TextWidth = TextWidth(Buffer)
textHeight = TextHeight(Buffer)
;Fond
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 120, 24, RGBA(0, 0, 0, 0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
RoundBox(0, 0, 120, 24, 6, 6, RGBA(218, 165, 32, 255))
;Text
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((120 - TextWidth)/2, (24 - TextHeight)/2, Buffer, RGBA(0, 0, 0, 255))
;Contour
DrawingMode(#PB_2DDrawing_Outlined)
RoundBox(0, 0, 120, 24, 6, 6, RGBA(0, 0, 0, 255))
StopDrawing()
GameUpdate()
Else
GameEnd()
EndIf
EndProcedure
Procedure GameUpdate()
Repeat : Repeat : Until WindowEvent() = 0
ClearScreen(RGB(255,255,255))
;Affichage des point A B C D
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
;Affichage point A
Circle(A\x, A\y, 2, RGB(255, 0, 0))
DrawText(A\x - Margin*2, A\y - Margin*2, "A", RGB(0, 0, 0))
;Affichage point B
Circle(B\x, B\y, 2, RGB(255, 0, 0))
DrawText(B\x + Margin, B\y - Margin*2, "B", RGB(0, 0, 0))
;Affichage point C
Circle(C\x, C\y, 2, RGB(255, 0, 0))
DrawText(C\x + Margin, C\y - Margin*2, "C", RGB(0, 0, 0))
;Affichage point D
Circle(D\x, D\y, 2, RGB(255, 0, 0))
DrawText(D\x + Margin, D\y - Margin*2, "D", RGB(0, 0, 0))
;Ligne entre A et B
LineXY(A\x, A\y, B\x, B\y, RGB(0, 0, 0))
;Ligne entre C et D
LineXY(C\x, C\y, D\x, D\y, RGB(0, 0, 0))
;Affichage point D'intersection
Circle(*pt\x, *pt\y, 2, RGB(255, 0, 0))
DrawText(*pt\x + Margin, *pt\y - Margin*2, "Intersection", RGB(0, 0, 0))
StopDrawing()
ExamineKeyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
Procedure GameEnd()
End
EndProcedure
;Retourne l'intersection de deux vecteurs (Points 2D)
Procedure.i inter2DPoint(*P1.Vector, *P2.Vector ,*P3.Vector, *P4.Vector)
Protected *Result.Vector = AllocateMemory(SizeOf(Point))
Protected coef_S1.f, coef_S2.f ; coef directeur ou tangente alpha en radian
Protected ord_S1.f, ord_S2.f ; point sur l'ordonné
coef_S1 = (*P2\y - *P1\y) / (*P2\x - *P1\x)
coef_S2 = (*P4\y - *P3\y) / (*P4\x - *P3\x)
ord_S1 = *P1\y - coef_S1 * *P1\x
ord_S2 = *P3\y - coef_S2 * *P3\x
*Result\x = (ord_S2 - ord_S1) / (coef_S1 - coef_S2)
*Result\y = coef_S1 * *Result\x + ord_S1
ProcedureReturn *Result
EndProcedure
Micoute a écrit :Bonjour à tous,
comme il ne faut qu'une seule fonctionnalité à mettre en évidence, voici mon code.Code : Tout sélectionner
#Jours_par_Semaine = 7 #Heures_par_Jour = 24 #Mn_par_Heure = 60 #Sec_par_Heure = 3600 #Sec_par_Mn = 60 Procedure Jour_en_Secondes(Jours.i) secondes = Jours * #Heures_par_Jour * #Mn_par_Heure * #Sec_par_Mn ProcedureReturn secondes EndProcedure Debug Jour_en_Secondes(1)
Code : Tout sélectionner
Procedure Jour_en_Secondes(Jours.i)
secondes = 86400*Jours.i
ProcedureReturn secondes
EndProcedure
Debug Jour_en_Secondes(1)
Code : Tout sélectionner
;Patrick88 - 06/03/2018 - Indique de quel coté du segment [A B] se trouve le point C, à droite ou à gauche du segment d'après
; http://www.purebasic.fr/french/viewtopic.php?f=1&t=17175
;Niveau de difficulté : *
;Structure d'un vecteur
Structure Vector
x.f ;Position x
y.f ;Position y
EndStructure
;Points A, B et *pt
Global A.Vector, B.Vector, C.Vector, D.Vector, *pt.vector
;Afficher un texte
Global SpriteGauche,SpriteDroit, Buffer.s, TextWidth, TextHeight
;Marge affichage texte
Global Margin = 6
;Plan de l'application
Declare GameStart()
Declare GameUpdate()
Declare GameEnd()
;Math
Declare.i coTd1Segment2d(*P1.Vector, *P2.Vector ,*P3.Vector)
GameStart()
Procedure.l CreeSpritetexte(texte.s)
Protected SpriteText.l
;Creation du sprite text à afficher
SpriteText = CreateSprite(#PB_Any, 200, 24, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(SpriteText))
TextWidth = TextWidth(texte)
textHeight = TextHeight(texte)
;Fond
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, SpriteWidth(SpriteText), 24, RGBA(0, 0, 0, 0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
RoundBox(0, 0, SpriteWidth(SpriteText), 24, 6, 6, RGBA(218, 165, 32, 255))
;Text
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((SpriteWidth(SpriteText) - TextWidth)/2, (24 - TextHeight)/2, texte, RGBA(0, 0, 0, 255))
;Contour
DrawingMode(#PB_2DDrawing_Outlined)
RoundBox(0, 0, SpriteWidth(SpriteText), 24, 6, 6, RGBA(0, 0, 0, 255))
StopDrawing()
ProcedureReturn SpriteText
EndProcedure
Procedure GameStart()
If InitSprite()
InitKeyboard()
InitMouse()
;Définition du point A
A\x = 100
A\y = 150
;Définition du point B
B\x = 575
B\y = 525
;Définition du point C
C\x = 150
C\y = 150;573
*pt = coTd1Segment2d(A, B, C)
OpenWindow(0, 0, 0, 800, 600, "Jeu de Math : Indique de quel coté du segment [A B] se trouve le point C, à droite ou à gauche du segment. ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
BindEvent(#PB_Event_CloseWindow, @GameEnd())
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
SpriteGauche = CreeSpritetexte("et à gauche du segment [A B]")
SpriteDroit = CreeSpritetexte("et à droite du segment [A B]")
GameUpdate()
Else
GameEnd()
EndIf
EndProcedure
Procedure GameUpdate()
Repeat : Repeat : Until WindowEvent() = 0
ClearScreen(RGB(255,255,255))
;Affichage des point A B C D
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
;Affichage point A
Circle(A\x, A\y, 2, RGB(255, 0, 0))
DrawText(A\x - Margin*2, A\y - Margin*2, "A", RGB(0, 0, 0))
;Affichage point B
Circle(B\x, B\y, 2, RGB(255, 0, 0))
DrawText(B\x + Margin, B\y - Margin*2, "B", RGB(0, 0, 0))
;Affichage point C
Circle(C\x, C\y, 2, RGB(255, 0, 0))
DrawText(C\x + Margin, C\y - Margin*2, "C", RGB(0, 0, 0))
;Ligne entre A et B
LineXY(A\x, A\y, B\x, B\y, RGB(0, 0, 0))
StopDrawing()
If C\y > *pt\y
DisplayTransparentSprite(SpriteGauche, C\x+20, C\y - SpriteHeight(SpriteGauche)/2)
ElseIf C\y < *pt\y
DisplayTransparentSprite(SpriteDroit, C\x+20 , C\y - SpriteHeight(SpriteDroit)/2)
ElseIf C\y = *pt\y
DisplayTransparentSprite(SpriteDroit, C\x+20 , C\y - SpriteHeight(SpriteDroit)/2)
EndIf
;RotateSprite(SpriteText, Angle2DPoint(B, A), #PB_Absolute)
ExamineKeyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
Procedure GameEnd()
End
EndProcedure
; recherche de quel coté d'un segment se trouve le point
Procedure.i coTd1Segment2d(*P1.Vector, *P2.Vector ,*P3.Vector)
Protected *Result.Vector = AllocateMemory(SizeOf(Point))
Protected coef_S1.f, coef_S2.f ; coef directeur ou tangente alpha en radian
Protected ord_S1.f, ord_S2.f ; point sur l'ordonné
coef_S1 = (*P2\y - *P1\y) / (*P2\x - *P1\x)
ord_S1 = *P1\y - coef_S1 * *P1\x
*Result\x = *P3\x
*Result\y = coef_S1 * *Result\x + ord_S1
ProcedureReturn *Result
EndProcedure
Code : Tout sélectionner
;Patrick88 - 06/03/2018 - deplace un point C perpendiculairement à un segment [A B] d'après
; http://www.purebasic.fr/french/viewtopic.php?f=1&t=17175
;Niveau de difficulté : *
;Structure d'un vecteur
Structure Vector
x.f ;Position x
y.f ;Position y
EndStructure
;Points A, B et *pt
Global A.Vector, B.Vector, C.Vector, D.Vector, *pt.vector
;Afficher un texte
Global SpriteText, Buffer.s = "...", TextWidth, TextHeight
;Marge affichage texte
Global Margin = 6
;Plan de l'application
Declare GameStart()
Declare GameUpdate()
Declare GameEnd()
;Math
Declare.i DeplacePoint2dSur1Segment2d(*P1.Vector, *P2.Vector ,*P3.Vector)
GameStart()
Procedure GameStart()
If InitSprite()
InitKeyboard()
InitMouse()
;Définition du point A
A\x = 100
A\y = 150
;Définition du point B
B\x = 575
B\y = 525
;Définition du point C
C\x = 550
C\y = 50; 573
*pt = DeplacePoint2dSur1Segment2d(A, B, C)
OpenWindow(0, 0, 0, 800, 600, "Jeu de Math : deplace un point C perpendiculairement à un segment [A B] ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
BindEvent(#PB_Event_CloseWindow, @GameEnd())
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
;Creation du sprite text à afficher
SpriteText = CreateSprite(#PB_Any, 120, 24, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(SpriteText))
TextWidth = TextWidth(Buffer)
textHeight = TextHeight(Buffer)
;Fond
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 120, 24, RGBA(0, 0, 0, 0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
RoundBox(0, 0, 120, 24, 6, 6, RGBA(218, 165, 32, 255))
;Text
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((120 - TextWidth)/2, (24 - TextHeight)/2, Buffer, RGBA(0, 0, 0, 255))
;Contour
DrawingMode(#PB_2DDrawing_Outlined)
RoundBox(0, 0, 120, 24, 6, 6, RGBA(0, 0, 0, 255))
StopDrawing()
GameUpdate()
Else
GameEnd()
EndIf
EndProcedure
Procedure GameUpdate()
Repeat : Repeat : Until WindowEvent() = 0
ClearScreen(RGB(255,255,255))
;Affichage des point A B C D
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
;Affichage point A
Circle(A\x, A\y, 2, RGB(255, 0, 0))
DrawText(A\x - Margin*2, A\y - Margin*2, "A", RGB(0, 0, 0))
;Affichage point B
Circle(B\x, B\y, 2, RGB(255, 0, 0))
DrawText(B\x + Margin, B\y - Margin*2, "B", RGB(0, 0, 0))
;Affichage point C
Circle(C\x, C\y, 2, RGB(255, 0, 0))
DrawText(C\x + Margin, C\y - Margin*2, "C", RGB(0, 0, 0))
;Ligne entre A et B
LineXY(A\x, A\y, B\x, B\y, RGB(0, 0, 0))
;Affichage point projeté *px
Circle(*pt\x, *pt\y, 2, RGB(255, 0, 0))
DrawText(*pt\x + Margin, *pt\y - Margin*2, "Point sur le segment [A B]", RGB(0, 0, 0))
;Ligne entre C et *pt
LineXY(C\x, C\y, *pt\x, *pt\y, RGB(255, 0, 0))
StopDrawing()
ExamineKeyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
Procedure GameEnd()
End
EndProcedure
; deplace un point C perpendiculairement à un segment [A B]
Procedure.i DeplacePoint2dSur1Segment2d(*P1.Vector, *P2.Vector ,*P3.Vector)
Protected *Result.Vector = AllocateMemory(SizeOf(Point))
Protected coef1.f ; coef directeur ou tangente alpha en radian
Protected ord1.f ; point sur l'ordonné
; on deplace le point P3 sur le segment [A B]
coef1 = (*P2\y - *P1\y) / (*P2\x - *P1\x)
ord1 = *P1\y - coef1 * *P1\x
; on recalcul le point
*Result\x = (coef1 * (*p3\y - ord1) + *p3\x) / ( 1 + Pow(coef1,2))
*Result\y = (-1/coef1) * *Result\x + *p3\y + (*p3\x / coef1)
ProcedureReturn *Result
EndProcedure
Code : Tout sélectionner
x_arrive=X_depart.f+Cos(Angle*#PI/180)* Distance_a_parcourir.f
y_arrive=Y_depart.f+Sin(Angle*#PI/180)* Distance_a_parcourir.f
Code : Tout sélectionner
;Retourne l'angle entre deux vecteurs 2D
Procedure.f Angle2Segment2D(*P1.Vector, *P2.Vector ,*P3.Vector, *P4.Vector)
Protected angle1.f, angle2.f
angle1 = Angle2DPoint(*P1.Vector, *P2.Vector)
angle2 = Angle2DPoint(*P3.Vector, *P4.Vector)
ProcedureReturn angle1 - angle2
EndProcedure
non ce n'est pas mon proposfalsam a écrit :@Zorro : Calculer un point de chute uniquement en fonction d'un angle et d'une distance que je suppose linéaire et oblique me semble simpliste. Ca reviendrait à dire que la chute est verticale quand la distance est atteinte. Si ta distance est horizontale alors ta formule est dans ce cas bien compliquée![]()