Re: Compétition PurePunch Juillet-Août 2014
Publié : mar. 05/août/2014 8:32
Bonjour comtois, original to programme, j'adore !
Forums PureBasic - Français
https://www.purebasic.fr/french/
Code : Tout sélectionner
;*******************************************************************************
;*
;* July-August 2014 PurePunch contest
;* PureBasic 5.30
;* 50 lines of 80 chars, 2 months delay
;*
;* Name : Je Te Vois
;* Author : Comtois
;* Date : 05/08/14
;* Notes : TransformSprite() ne fonctionne pas en opengl !!
;*
;*******************************************************************************
Macro ts(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
TransformSprite(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4)
CompilerElse
; Linux
TransformSprite(sprite, _x4, _y1, _x2, (_y1)-(_y3)+(_y4), _x3, (_y1)-(_y2)+(_y4), _x1, _y4)
CompilerEndIf
EndMacro
Macro M:Macro:EndMacro:M E:End:End#M:M gn:Global NewList:End#M:M R:Read.i:End#M
M st:Structure:E#M:M ts_:TransformSprite:E#M:M pr:Procedure:E#M:M N:Next:E#M
M sp:Sprite:E#M:M mo:Mouse:E#M:M Rp:Repeat:E#M:M C:Continue:E#M
M Sd:StartDrawing:E#M:M So:StopDrawing:E#M:M rt:Return:E#M:M ll:ClearList:E#M
st V2:x.d:y.d:E#St:st k:p1.V2:p2.V2:E#St:st Tria:No.i:p1.V2:p2.V2:p3.V2:E#St
st it:ok.i:x.d:y.d:p.d:a.d:E#St:gn Y.k():gn LP.V2():gn Z.d():gn q.it()
gn W.Tria():M AE:AddElement:End#M:M FE:ForEach:End#M:pr Gi(*it.it,*ry.k,*h.k)
rpx.d=*ry\p1\x:rpy.d=*ry\p1\y:rdx.d=*ry\p2\x-*ry\p1\x:rdy.d=*ry\p2\y-*ry\p1\y
spx.d=*h\p1\x:spy.d=*h\p1\y:sdx.d=*h\p2\x-*h\p1\x:sdy.d=*h\p2\y-*h\p1\y
rg.d=Sqr(rdx*rdx+rdy*rdy):smg.d=Sqr(sdx*sdx+sdy*sdy):If rdx/rg=sdx/smg And
rdy/rg=sdy/smg:pr#rt 0:E#If:T2.d=(rdx*(spy-rpy)+rdy*(rpx-spx))/(sdx*rdy-sdy*rdx)
T1.d=(spx+sdx*T2-rpx)/rdx:If T1<0:pr#rt 0:E#If:If T2<0 Or T2>1:pr#rt 0:E#If
*it\x=rpx+rdx*T1:*it\y=rpy+rdy*T1:*it\p=T1:pr#rt 1:E#Pr:pr J(gx.f,gy.f):ll(LP())
FE Y():AE(LP()):LP()\x=Y()\p1\x:LP()\y=Y()\p1\y:AE(LP()):LP()\x=Y()\p2\x
LP()\y=Y()\p2\y:N:FE LP():VX.f=LP()\x:VY.f=LP()\y:PushListPosition(LP())
While N#Element(LP()):If LP()\x=VX And LP()\y=VY:DeleteElement(LP()):E#If:Wend
PopListPosition(LP()):N:ll(Z()):FE LP():a.f=ATan2(LP()\x-gx,LP()\y-gy):AE(Z())
Z()=a-0.0001:AE(Z()):Z()=a:AE(Z()):Z()=a+0.0001:N:ll(q()):FE Z():a.f=Z()
dx.d=Cos(a):dy.d=Sin(a):ry.k:ry\p1\x=gx:ry\p1\y=gy:ry\p2\x=gx+dx:ry\p2\y=gy+dy
Protected.it CI,it:CI\ok=0:FE Y():g=Gi(@it,@ry,@Y()):If g=0:C:E#If:If CI\ok=0 Or
it\p<CI\p:CI=it:CI\ok=1:E#If:N:If (CI\ok=0):C:E#If:CI\a=a:AE(q()):q()=CI:N
SortStructuredList(q(),0,OffsetOf(it\a),TypeOf(it\a)):E#pr:pr draw()
sd(ScreenOutput()):J(Mo#X(),Mo#Y()):ok=0:Protected.d x,y,x0,y0:FE w()
Free#Sp(w()\No):N:ll(w()):FirstElement(q()):x0=q()\x:y0=q()\y:FE q():If ok
AE(w()):w()\p1\x=Mo#X():w()\p1\y=Mo#Y():w()\p2\x=x:w()\p2\y=y:w()\p3\x=q()\x
w()\p3\y=q()\y:E#If:x=q()\x:y=q()\y:ok=1:N:AE(w()):w()\p1\x=Mo#X()
w()\p1\y=Mo#Y():w()\p3\x=x0:w()\p3\y=y0:w()\p2\x=q()\x:w()\p2\y=q()\y:So():E#pr
InitSprite():InitMouse():InitKeyboard():OpenWindow(0,0,0,800,600,"")
OpenWindowedScreen(WindowID(0),0,0,800,600):Mo#Locate(400,300)
Create#Sp(0,32,32):sd(Sp#Output(0)):Circle(15,15,15,RGB(255,255,0)):So():Sx=799
Sy=599:AE(Y()):Y()\p1\x=0:Y()\p1\y=0:Y()\p2\x=Sx:Y()\p2\y=0:AE(Y()):Y()\p1\x=Sx
Y()\p1\y=0:Y()\p2\x=Sx:Y()\p2\y=Sy:AE(Y()):Y()\p1\x=Sx:Y()\p1\y=Sy:Y()\p2\x=0
Y()\p2\y=Sy:AE(Y()):Y()\p1\x=0:Y()\p1\y=Sy:Y()\p2\x=0:Y()\p2\y=0:Dim S.k(3):No=1
Rp:R Nb:For i=0 To Nb-1:R S(i)\p1\x:R S(i)\p1\y:R S(i)\p2\x:R S(i)\p2\y:AE(Y())
Y()\p1\x=S(i)\p1\x:Y()\p1\y=S(i)\p1\y:Y()\p2\x=S(i)\p2\x:Y()\p2\y=S(i)\p2\y:N
Create#Sp(No,256,256):sd(Sp#Output(No)):Box(0,0,256,256,RGB(0,50,140)):So()
If Nb=4:ts(No,S(0)\p1\x,S(0)\p1\y,S(0)\p2\x,S(0)\p2\y,S(1)\p2\x,S(1)\p2\y,
S(2)\p2\x,S(2)\p2\y):Else:ts(No,S(0)\p1\x,S(0)\p1\y,S(0)\p2\x,S(0)\p2\y,
S(1)\p2\x,S(1)\p2\y,S(1)\p2\x,S(1)\p2\y):E#If:No+1:Until Nb=0:Rp:Rp
ev=WindowEvent():Until ev=0 :ClearScreen($FFFFFF):ExamineMouse()
ExamineKeyboard():Draw():FE w():w()\no=Create#Sp(-1,256,256)
sd(Sp#Output(w()\no)):Box(0,0,256,256,RGB(250,70,0)):So():ts(w()\no,w()\p1\x,
w()\p1\y,w()\p2\x,w()\p2\y,w()\p3\x,w()\p3\y,w()\p3\x,w()\p3\y)
Display#Sp(w()\no,0,0):N:For i=1 To 5:Display#Sp(i,0,0):N
DisplayTransparent#Sp(0,Mo#X()-16,Mo#Y()-16):FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape):DataSection:Data.i 4,50,50,150,50,150,50,
150,150,150,150,50,150,50,150,50,50,3,450,300,550,450,550,450,350,450,350,450,
450,300,4,650,250,750,200,750,200,750,350,750,350,650,400,650,400,650,250,4,350,
80,450,80,450,80,450,220,450,220,350,220,350,220,350,80,4,120,320,170,370,170,
370,120,420,120,420,70,370,70,370,120,320,0:EndDataSection
Comme je l'ai déjà dit, les règles ne sont pas trop restrictives, exprès. Mais les participants doivent prendre en considération que les votants sont libres d'apprécier telle ou telle "astuce". Ça fait partie de la compétition.Ollivier a écrit :@DJ e/s
Mais c'est quoi ces règles en fait? Je comprends rien là...
J'ai le droit d'exécuter le compilateur en mode stand by par exemple et de balancer une image complètement foireuse visuellement, mais qui contient 1 méga de code!
T'as encore fait des règles dans les pâquerettes là!
On peut poster un programme de 40000 instructions avec ça!
Eh ben dis donc, tu t'es bien amusé pour trouver ça !! et ça marche sous linux ? sans doute oui sinon tu ne me le proposerais pas.graph100 a écrit :j'ai donné une correction de transformesprite récemment : regarde ça et vois si arrives à le puncher !
Code : Tout sélectionner
Macro ts(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4) CompilerIf #PB_Compiler_OS = #PB_OS_Windows TransformSprite(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4) CompilerElse ; Linux TransformSprite(sprite, _x4, _y1, _x2, (_y1)-(_y3)+(_y4), _x3, (_y1)-(_y2)+(_y4), _x1, _y4) CompilerEndIf EndMacro
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 800, 600, "Lumière")
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
#DirectX = #True
Macro ts(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4)
If #DirectX
TransformSprite(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4)
Else
TransformSprite(sprite, _x4, _y1, _x2, (_y1)-(_y3)+(_y4), _x3, (_y1)-(_y2)+(_y4), _x1, _y4)
EndIf
EndMacro
X1 = 100 : y1 = 100
x2 = 200 : y2 = 50
X3 = 150 : y3 = 150
CreateSprite(0, 1, 1)
Ts(0, X1, y1, X2, y2, x3, y3, x3, y3)
Repeat
Repeat
Event = WindowEvent()
Until Event = 0 Or event = #PB_Event_CloseWindow
ClearScreen(RGB(210, 210, 210))
ExamineKeyboard()
DisplaySprite(0, 0, 0)
StartDrawing(ScreenOutput())
LineXY(x1,y1,x2,y2,RGB(255,0,0))
LineXY(x2,y2,x3,y3,RGB(255,0,0))
LineXY(x3,y3,x1,y1,RGB(255,0,0))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or event = #PB_Event_CloseWindow
ça ne fonctionne pas.Ollivier a écrit :Je crois que j'en parle ici, avec Idle qui est à remercier, c'était il y a 3 ans quand même...
Code : Tout sélectionner
TransformSprite(sprite, _x1, _y1, _x2, (_y1)-(_y3)+(_y4), _x3, (_y1)-(_y2)+(_y4), _x4, _y4)
Code : Tout sélectionner
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 800, 400, "MoonLander", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 400)
KeyboardMode(1)
CreateSprite(1, 10, 10, 4)
Macro circle_(x, y, x1, y1, x2, y2, x3, y3, x4, y4)
Circle(x+x1, y+y1, 2, $FF)
Circle(x+x2, y+y2, 2, $FF00)
Circle(x+x3, y+y3, 2, $FF0000)
Circle(x+x4, y+y4, 2, $FFFFFF)
EndMacro
x = 150
y = 100
x1 = 10
y1 = 00
x2 = 100
y2 = 0
x3 = 100
y3 = 100
x4 = 0
y4 = 100
Macro Modifier(_x_)
If plus#_x_ = 0
plus#_x_ = 1
_mem_#_x_ = _x_
EndIf
_x_ + plus#_x_
If _x_ > _mem_#_x_+50 : plus#_x_ = -1 : EndIf
If _x_ < _mem_#_x_-50 : plus#_x_ = 1 : EndIf
EndMacro
Macro TransformSprite_linux(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
TransformSprite(sprite, _x1, _y1, _x2, _y2, _x3, _y3, _x4, _y4)
CompilerElse
; Linux
TransformSprite(sprite, _x4, _y1, _x2, (_y1)-(_y3)+(_y4), _x3, (_y1)-(_y2)+(_y4), _x1, _y4)
CompilerEndIf
EndMacro
Repeat
_count_ + 1
Repeat
_event_ = WindowEvent()
Until _event_ = 0 Or #PB_Event_CloseWindow
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
_event_ = #PB_Event_CloseWindow
EndIf
ClearScreen($2FC9F0)
Modifier(y1)
Modifier(x1)
TransformSprite_linux(1, x+x1, y+y1, x+x2, y+y2, x+x3, y+y3, x+x4, y+y4)
DisplaySprite(1, 0, 0)
; TransformSprite(1, 100, 100, 200, 100, 300, 300, 100, 200)
; DisplaySprite(1, 200, 0)
;
;
;
; TransformSprite(1, 100, 100, 200, 300, 300, 300, 100, 200)
; DisplaySprite(1, 400, 0)
StartDrawing(ScreenOutput())
LineXY(50, 150, 350, 150, $FF00)
circle_(x, y, x1, y1, x2, y2, x3, y3, x4, y4)
; circle_(200, 0, 100, 100, 200, 100, 300, 300, 100, 200)
; circle_(400, 0, 100, 100, 200, 300, 300, 300, 100, 200)
StopDrawing()
FlipBuffers()
Until _event_ = #PB_Event_CloseWindow
Yep, je rentre de vacances, j'ai pas touché un ordi pendant 1 mois et suis fin prêt pour finaliser le PurePunch pendant les 9 jours qui restent (mais ça fait plus beaucoup de temps car quand tu enlèves le temps passé au travail, à faire à manger, à dormir, au barbecue avec les copains, à emmener les enfants au centre aéré, à écouter ta douce te parler de son travail une fois que les enfants sont couchés alors que ton ordi est allumé, à regarder les autres productions PurePunch, à aller à la piscine et à regarder discrètement les jolies jambes de la maitre nageuse...)falsam a écrit :Plus que quelques jours à attendre ........
Oui oui, encore une semaine d'attentemajikeyric a écrit :Alors SPH tu vas nous le publier ton punch mystère ?
Ok, je publierais demaingraph100 a écrit :Pour qu'on ai le temps de la voir et de l'apprécier, tu ne devrais pas attendre autant