Page 1 sur 2
Polygons
Publié : ven. 30/sept./2005 10:34
par kelly
Code : Tout sélectionner
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("ERROR","Cant init DirectX",0)
End
EndIf
MainWnd.l = OpenWindow(0, 0, 0, 600,500, #PB_Window_ScreenCentered, "Polygon Beispiel")
If OpenWindowedScreen(MainWnd.l, 0, 0, 600,500, 1, 0, 0)
If P2D_InitPolygonDrawing()
; -- Triangle
P2D_SetPolygonPoint(2, 0, 0, 50)
P2D_SetPolygonPoint(2, 1, 220, 120)
P2D_SetPolygonPoint(2, 2, 30, 150)
P2D_CreatePolygon(2, RGB(255,0,255), RGB(255,0,0))
EndIf
EndIf
Repeat
While WindowEvent() : Wend
ExamineKeyboard()
ExamineMouse()
P2D_DisplayTransparentPolygon(2, 20, 140)
FlipBuffers()
ClearScreen(0, 4, 0)
Until KeyboardPushed(#PB_KEY_ESCAPE)
Ce type de polygon (ici un triangle) bug parfois !
Pourquoi ?? (remplacez donc le "50" de "P2D_SetPolygonPoint(2, 0, 0, 50)" par un "0" et la, ca marche)
Y a t'il une autre technique pour tracer des polygons ?
Publié : ven. 30/sept./2005 12:54
par Backup
la procedure cidessous
polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
ou
x.l =coordonée x du polygone
y.l =coordonée y du polygone
angle.l= nombre de cotés du polygone 3=triangle ; 4=carre ;5 penta, ect..
rotation.f = angle de rotation en degré du polygone !!
color.l = couleur du tracé !!
t= c'est juste une variable pour pouvoir ecrire les degrs pendant la rotation !!
Code : Tout sélectionner
#dobro=1
#Police=1
#Sprite=1
#PI=3.1415926
Declare polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN):;=largeur de l'ecran
EcranY = GetSystemMetrics_(#SM_CYSCREEN):;=hauteur de l'ecran
WindowID = OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered , "hello")
WindowID = WindowID(1)
Result = OpenWindowedScreen(WindowID,0,0,800, 600, 1, 0,0)
Resultat = InitMouse()
Repeat
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
;Star(x.l,y.l,intrad.l,n.l,phase.f,color.l)
x.l=400 ;location x
y.l=300 ; location y
taille.l=100
angle.l=4 ; pour un triangle 4 pour un carre , 8 pour un octogone ect ...
rotation.f=180
color.l=RGB($FF,$FF,$80)
For t=0 To 360
; Delay (200)
rotation.f=t
polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
FlipBuffers():; affiche l'ecran
ClearScreen(0,0,0)
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
Next t
Until Event=#PB_Event_CloseWindow
Procedure polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
If angle.l=4
Else
EndIf
rotation.f= rotation.f*0.01745329
StartDrawing(ScreenOutput() )
DrawText(StrF( t))
alpha.f=2*(#PI/angle)
For t.l=1 To angle
d1.f=(t-1)*alpha+rotation.f
d3.f=t*alpha+rotation.f
LineXY(x+taille*Sin(d1),y+taille*Cos(d1),x+taille*Sin(d3),y+taille*Cos(d3),color)
Next
StopDrawing()
EndProcedure
Publié : ven. 30/sept./2005 16:25
par kelly
teuteuteut !!!!!!!!
Dobro, je parle de polygones remplis (je cherche ca moi)
Publié : ven. 30/sept./2005 16:51
par comtois
avec les valeurs de ton triangle , ça marche , et le triangle est rempli , j'espère que je ne vais pas me faire engueuler
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenScreen(800,600,32,"Demo")
Dim points.Point(2)
points(0)\x=0
points(0)\y=50
points(1)\x=220
points(1)\y=120
points(2)\x=30
points(2)\y=150
Repeat
FlipBuffers()
ClearScreen(0,0,30)
ExamineKeyboard()
hdc=StartDrawing(ScreenOutput())
If hdc
FrontColor(255,255,55)
Polygon_(hdc,points(),3)
EndIf
StopDrawing()
Until KeyboardPushed(#PB_Key_Escape)
Publié : ven. 30/sept./2005 17:12
par kelly
Voila un polygon digne de ce nom. Merci Comtois. Libre a toi maintenant d'epouser la fillotte du duc de pouille. Tu en etait fou... JE TE LA DONNE EN EPOUSAILLE !!!
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"Demo")
Dim points.Point(5)
points(0)\x=50
points(0)\y=0
points(1)\x=220
points(1)\y=120
points(2)\x=30
points(2)\y=150
points(3)\x=111
points(3)\y=650
points(4)\x=888
points(4)\y=11
points(5)\x=65
points(5)\y=325
Repeat
FlipBuffers()
ClearScreen(0,0,30)
ExamineKeyboard()
hdc=StartDrawing(ScreenOutput())
If hdc
FrontColor(255,255,55)
Polygon_(hdc,points(),6)
EndIf
StopDrawing()
Until KeyboardPushed(#PB_Key_Escape)
Publié : ven. 30/sept./2005 17:38
par comtois
le duc de pouille avait aussi un fillot , il a fini sa carrière au vatican en devenant pape.
Publié : ven. 30/sept./2005 22:56
par Backup
teuteuteut !!!!!!!!
Dobro, je parle de polygones remplis (je cherche ca moi)
ya bien qu'a toi que ça pose un problem a remplir !
et avant que tu critique !
avec cette version ya un avantage !! tu choisi le nombre de cote du polygone !
ça marche pas QUE pour les triangles et pis c'est sans LIB !
et en plus il tourne !
Code : Tout sélectionner
#dobro=1
#Police=1
#Sprite=1
#PI=3.1415926
Declare polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t,coul_remp.l)
Declare rempli(x,y,Couleur)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN):;=largeur de l'ecran
EcranY = GetSystemMetrics_(#SM_CYSCREEN):;=hauteur de l'ecran
WindowID = OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered , "hello")
WindowID = WindowID(1)
Result = OpenWindowedScreen(WindowID,0,0,800, 600, 1, 0,0)
Resultat = InitMouse()
Repeat
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
;Star(x.l,y.l,intrad.l,n.l,phase.f,color.l)
x.l=400 ;location x
y.l=300 ; location y
taille.l=100
angle.l=Random(10)+2 ; pour un triangle 4 pour un carre , 8 pour un octogone ect ...
rotation.f=180
For tp=0 To 360
; Delay (200)
t=1
rotation.f=tp
color.l=RGB($FF,$FF,$FF) ; couleur du tour$
coul_remp.l=RGB($A8,$B0,$2) ; couleur du remplissage !
c=c+1
polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t,coul_remp.l)
If c=50
angle.l=Random(8)+3
c=0
EndIf
FlipBuffers():; affiche l'ecran
ClearScreen(0,0,0)
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
Next tp
Until Event=#PB_Event_CloseWindow
Procedure polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t,coul_remp.l)
rotation.f= rotation.f*0.01745329
alpha.f=2*(#PI/angle)
For t.l=1 To angle
d1.f=(t-1)*alpha+rotation.f
d3.f=t*alpha+rotation.f
StartDrawing(ScreenOutput() )
For i=1 To taille-1
LineXY(x-i*Sin(d1),y-i*Cos(d1),x-i*Sin(d3),y-i*Cos(d3),coul_remp.l)
Next i
StopDrawing()
Next t
EndProcedure
Publié : sam. 01/oct./2005 0:02
par LeCyb
Je dois être le plus mauvais du forum en graphisme mais tu peux pas utiliser la fonction FillArea ?
C'est que le triangle remplis il est un poil moche quand il tourne (on voit les traces noires entre les lignes).
Publié : sam. 01/oct./2005 0:12
par Backup
ben c'est pas de ma faute si le pure ne gere pas beaucoup de chiffre en flottant
plus serieusement , le probleme c'est que la fonction lignexy cree des petits trous , et le fill area passe au travers !!
j'ai bien essayé , mais j'ai pas voulu passer ma soiré la dessus !
essaye si tu veux !

Publié : sam. 01/oct./2005 9:03
par kelly
Ton remplissage n'est pas celui que ferait un paint. Et puis ca rame avec de grands polygons (voir le code).
Par contre, dite moi d'ou viennent ces polygons. Ce n'est pas dans le PB d'origine. Alors, qui a fait cette lib, et combien en existe t'il ?
Code : Tout sélectionner
#dobro=1
#Police=1
#Sprite=1
#PI=3.1415926
Declare polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t,coul_remp.l)
Declare rempli(x,y,Couleur)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN):;=largeur de l'ecran
EcranY = GetSystemMetrics_(#SM_CYSCREEN):;=hauteur de l'ecran
WindowID = OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered , "hello")
WindowID = WindowID(1)
Result = OpenWindowedScreen(WindowID,0,0,800, 600, 1, 0,0)
Resultat = InitMouse()
Repeat
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
;Star(x.l,y.l,intrad.l,n.l,phase.f,color.l)
x.l=400 ;location x
y.l=300 ; location y
taille.l=400
angle.l=Random(10)+2 ; pour un triangle 4 pour un carre , 8 pour un octogone ect ...
rotation.f=180
For tp=0 To 360
; Delay (200)
t=1
rotation.f=tp
color.l=RGB($FF,$FF,$FF) ; couleur du tour$
coul_remp.l=RGB($A8,$B0,$2) ; couleur du remplissage !
c=c+1
polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t,coul_remp.l)
If c=50
angle.l=Random(100)+3
c=0
EndIf
FlipBuffers():; affiche l'ecran
ClearScreen(0,0,0)
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
Next tp
Until Event=#PB_Event_CloseWindow
Procedure polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t,coul_remp.l)
rotation.f= rotation.f*0.01745329
alpha.f=2*(#PI/angle)
For t.l=1 To angle
d1.f=(t-1)*alpha+rotation.f
d3.f=t*alpha+rotation.f
StartDrawing(ScreenOutput() )
For i=1 To taille-1
LineXY(x-i*Sin(d1),y-i*Cos(d1),x-i*Sin(d3),y-i*Cos(d3),coul_remp.l)
Next i
StopDrawing()
Next t
EndProcedure
Publié : sam. 01/oct./2005 13:38
par Dr. Dri
Pour ceux qui douteraient encore de la vitesse de dessin
http://purebasic.hmt-forum.com/viewtopic.php?t=3701
Dri

Publié : sam. 01/oct./2005 13:39
par Backup
tiens fillette !!
Code : Tout sélectionner
#dobro=1
#Police=1
#Sprite=1
#PI=3.1415926
Declare polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,r.b,coul_remp.l)
Declare remplis(*hdc,x,y,couleur_remplissage)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN):;=largeur de l'ecran
EcranY = GetSystemMetrics_(#SM_CYSCREEN):;=hauteur de l'ecran
WindowID = OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered , "hello")
WindowID = WindowID(1)
ecran= OpenWindowedScreen(WindowID,0,0,800, 600, 1, 0,0)
Resultat = InitMouse()
Repeat
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
x.l=400 ;location x
y.l=300 ; location y
taille.l=300
angle.l=4 ; pour un triangle 4 pour un carre , 8 pour un octogone ect ...
rotation.f=180
For tp=0 To 360
; Delay (200)
r=1 ; remplis ou pas !!
rotation.f=tp ; parametre de rotation en degre
color.l=RGB($FF,$FF,$FF) ; couleur du tour$
coul_remp.l=RGB($F9,$FE,$8B) ; couleur du remplissage !
c=c+1
polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,r,coul_remp.l)
If c=50
angle.l=Random(8)+3
c=0
EndIf
FlipBuffers():; affiche l'ecran
ClearScreen(0,0,0)
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
Next tp
Until Event=#PB_Event_CloseWindow
Procedure polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,r.b,coul_remp.l)
rotation.f= rotation.f*0.01745329
alpha.f=2*(#PI/angle)
For t.l=1 To angle
d1.f=(t-1)*alpha+rotation.f
d3.f=t*alpha+rotation.f
*dc=StartDrawing(ScreenOutput() )
DrawingMode(4)
LineXY(x+taille*Sin(d1),y+taille*Cos(d1),x+taille*Sin(d3),y+taille*Cos(d3),color.l); polygone vide
StopDrawing()
Next t
If r=1
*dc=StartDrawing(ScreenOutput() )
DrawingMode(4)
remplis(*dc,x,y,coul_remp.l )
StopDrawing()
EndIf
EndProcedure
Procedure remplis(*hdc,x,y,couleur_remplissage)
pinceau=CreateSolidBrush_(couleur_remplissage)
SelectObject_(*hdc,pinceau)
ExtFloodFill_(*hdc,x,y,GetPixel_(*hdc,x,y),#FLOODFILLSURFACE)
DeleteObject_(pinceau)
ReleaseDC_(WindowID(),*hdc)
EndProcedure
Publié : sam. 01/oct./2005 15:01
par kelly
Ca marche pas.
Par contre, d'où viennent des fonction de polygons ????
Publié : sam. 01/oct./2005 16:38
par Dr. Dri
explique moi ce qui ne marche pas stp
(plus de détails)
sinon cette fonction fait partie de l'api win32
Dri
Publié : sam. 01/oct./2005 16:55
par Backup
@Kelly : si le code que j'ai mis t'indifere , dit le moi
je saurai m'en souvenir !