> Mon Economiseur d'Ecran (PB4)

Programmation d'applications complexes
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

> Mon Economiseur d'Ecran (PB4)

Message par SPH »

Bon, je corrige ce premier post pour y mettre le résultat PRESQUE definitif de mon economiseur d'ecran. Sur ce coup, l'ASM est mon ami et m'a permi de jouer avec toutes les couleurs existantes et d'etre plus rapide d'execution.
:10:
ps : un code avec + d'ASM (donc + rapide) se trouve plus loin dans ce tread...

Code : Tout sélectionner

; Codé par SPH(2006) sur PB4

InitSprite() 
InitMouse() 
InitKeyboard() 

;SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )

If ExamineDesktops() 
dw=DesktopWidth(0) 
dh=DesktopHeight(0) 
Else 
dw=1024 
dh=768 
EndIf 
cmb=14

OpenScreen(dw,dh,32,"") 

rrr.b=0
vvv.b=0
bbb.b=0

Dim t1.f(cmb) 
Dim t2.f(cmb) 
Dim tt1.f(cmb) 
Dim tt2.f(cmb) 
Dim t3.f(cmb) 
Dim t4.f(cmb) 
Dim tt3.f(cmb) 
Dim tt4.f(cmb) 
Dim rr.b(cmb) 
Dim vv.b(cmb) 
Dim bb.b(cmb) 
Dim ra1.f(cmb) 
Dim ra2.f(cmb) 
Dim ra3.f(cmb) 
Dim ra4.f(cmb) 
Dim mix(cmb) 
Dim miy(cmb) 


SPH: 
crono=0
swp.b=Random(4)

mix=dw/2 
miy=dh/2 

mix2=mix/2-1 
miy2=miy/2-1 

t0.f=Random(400)/1000 
tt0.f=0.009+Random(500)/10000 
t1.f=Random(400)/1000 
tt1.f=0.009+Random(500)/10000 
t2.f=Random(400)/1000 
tt2.f=0.009+Random(500)/10000 
t3.f=Random(400)/1000 
tt3.f=0.009+Random(500)/10000 
ra0=miy2/(8+Random(4)) 

Dim r.w(dw,dh) 
Dim v.w(dw,dh) 
Dim b.w(dw,dh) 


For i=0 To cmb 
ry1=400+Random(700) 
ry2=400+Random(700) 
t1.f(i)=Random(80)/(420+Random(600)) 
t2.f(i)=Random(80)/(420+Random(600)) 
tt1.f(i)=(1+Random(45))/ry1 
tt2.f(i)=(1+Random(45))/ry2 
t3.f(i)=Random(80)/(420+Random(600)) 
t4.f(i)=Random(80)/(420+Random(600)) 
tt3.f(i)=(1+Random(45))/700 
tt4.f(i)=(1+Random(45))/700 
x=255
y=Random(x)
rr(i)=y
x-y
y=Random(x)
vv(i)=x
x-y
y=Random(x)
bb(i)=x
If Random(1+swp)=0
Swap rr(i),bb(i)
Else
If Random(1+swp)=0
Swap vv(i),bb(i)
EndIf
EndIf


ra1(i)=dh/(8.3+Random(400)/200) 
ra2(i)=dh/(8.3+Random(400)/200) 
ra3(i)=dh/(8.3+Random(400)/200) 
ra4(i)=dh/(8.3+Random(400)/200) 
mix(i)=dw/4+Random(dw/2.1) 
miy(i)=dh/4+Random(dh/2.1) 
Next 

dkx=dw/2.67
dky=dh/2.67

swp.b=Random(20)

Repeat ;############################ 

For l=0 To cmb 
x1=mix(l)+Cos(t1(l))*ra1(l)-Cos(t3(l))*ra2(l) 
y1=miy(l)+Sin(t1(l))*ra1(l)-Sin(t3(l))*ra2(l) 

x2=mix(l)+Cos(t2(l))*ra3(l)-Cos(t4(l))*ra4(l) 
y2=miy(l)+Sin(t2(l))*ra4(l)-Sin(t4(l))*ra3(l) 

t1(l)+tt1(l) 
t2(l)+tt2(l) 
t3(l)+tt3(l) 
t4(l)+tt4(l) 

x=x2-x1 
y=y2-y1

dist=Sqr(x*x+y*y) 
xf.f=x/dist 
yf.f=y/dist 

xx1.f=x1 
yy1.f=y1 

For i=0 To dist 
x=xx1.f 
y=yy1.f

zz.l=(dh+1)*2*y+2*(x-1)

;********* procedure ASM antialiasing + affinage des couleurs (real 24bits rulez)

;R
!MOV      dword Ecx,[a_r]
!add      dword Ecx,[v_zz]
!mov      ax,[ecx]

!MOV      dword Edx,[a_rr]
!add      dword Edx,[v_l]
!mov      dl,[edx]
!xor      dh,dh
!add      ax,dx
!mov      [ecx],ax

!add      ecx,4
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,2
!mov      ax,[ecx]
!add      ax,dx
!add      ax,dx
!add      ax,dx
!add      ax,40
!mov      [ecx],ax

!sub      ecx,[v_dh] 
!sub      ecx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax
;********************
;V
!MOV      dword Ecx,[a_v]
!add      dword Ecx,[v_zz]
!mov      ax,[ecx]

!MOV      dword Edx,[a_vv]
!add      dword Edx,[v_l]
!mov      dl,[edx]
!xor      dh,dh
!add      ax,dx
!mov      [ecx],ax

!add      ecx,4
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,2
!mov      ax,[ecx]
!add      ax,dx
!add      ax,dx
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,[v_dh] 
!sub      ecx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax
;********************
;B
!MOV      dword Ecx,[a_b]
!add      dword Ecx,[v_zz]
!mov      ax,[ecx]

!MOV      dword Edx,[a_bb]
!add      dword Edx,[v_l]
!mov      dl,[edx]
!xor      dh,dh
!add      ax,dx
!mov      [ecx],ax

!add      ecx,4
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,2
!mov      ax,[ecx]
!add      ax,dx
!add      ax,dx
!add      ax,dx
!add      ax,130
!mov      [ecx],ax

!sub      ecx,[v_dh] 
!sub      ecx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!add      ecx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax
;******************************************** fin de ma sublime procedure ASM

xx1.f+xf 
yy1.f+yf 

Next i
Next l 

dkx2=dkx+Cos(t0)*ra0+Cos(t2)*ra0 
dky2=dky+Sin(t1)*ra0+Sin(t3)*ra0 
t0+tt0 
t1+tt1 
t2+tt2 
t3+tt3 

crono+1 

ExamineMouse() 
xmouse2=MouseDeltaX()/25 
ymouse2=MouseDeltaY()/25 

;*******************************************************    affichage 
StartDrawing(ScreenOutput()) 

For u=0 To miy2 
zz.l=(dh+1)*2*(u+dky2)+2*dkx2
For i=0 To mix2
zz.l+2

!MOV      dword Ecx,[a_r]
!add      dword Ecx,[v_zz]
!mov      ax, [ecx]
!mov      [v_rrr], ah

!MOV      dword Ecx,[a_v]
!add      dword Ecx,[v_zz]
!mov      ax, [ecx]
!mov      [v_vvv], ah

!MOV      dword Ecx,[a_b]
!add      dword Ecx,[v_zz]
!mov      ax, [ecx]
!mov      [v_bbb], ah

If swp=0
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(vvv,rrr,bbb))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(rrr,bbb,vvv))
Else
If swp=1
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(rrr,vvv,bbb))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(vvv,bbb,rrr))
Else
If swp=2
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(bbb,rrr,vvv))
Plot (i,miy-u-1,RGB(rrr,vvv,bbb))
Plot (mix-i-1,miy-u-1,RGB(bbb,rrr,vvv))
Else
If swp=3
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(vvv,bbb,rrr))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,bbb))
Else
If swp=4 Or swp=5
If Random(swp*9-36)=0
Plot (i,u,RGB(rrr,vvv,rrr))
Plot (mix-i-1,u,RGB(rrr,vvv,rrr))
Plot (i,miy-u-1,RGB(rrr,vvv,rrr))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,rrr))
Else
If Random(9)=0
Plot (i,u,RGB(bbb,bbb,vvv))
Plot (mix-i-1,u,RGB(rrr,bbb,vvv))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(vvv,rrr,bbb))
EndIf
EndIf
Else
If swp=6 Or swp=7
If Random(swp*6-36)=0
Plot (i,u,RGB(rrr,bbb,vvv))
Plot (mix-i-1,u,RGB(rrr,bbb,vvv))
Plot (i,miy-u-1,RGB(rrr,bbb,vvv))
Plot (mix-i-1,miy-u-1,RGB(rrr,bbb,vvv))
EndIf
Else
If swp=8
If i+u<mix/2.2
Plot (i,u,RGB(vvv,bbb,rrr))
Plot (mix-i-1,u,RGB(vvv,bbb,rrr))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(vvv,bbb,rrr))
Else
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(rrr,vvv,bbb))
Plot (i,miy-u-1,RGB(rrr,vvv,bbb))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,bbb))
EndIf
Else
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(rrr,vvv,bbb))
Plot (i,miy-u-1,RGB(rrr,vvv,bbb))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,bbb))
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf

Next 
Next 

stop:
StopDrawing() 
GrabSprite(0,0,0,mix,miy) 
DisplaySprite(0,mix,0) 
DisplaySprite(0,0,miy) 
DisplaySprite(0,mix,miy) 
If crono>=1000 
StartDrawing(ScreenOutput()) 
For i=0 To dh Step 16
Box(0,i,dw,crono-1000,0) 
Next 
StopDrawing() 
If crono=1016
Goto SPH
EndIf 
EndIf 
FlipBuffers()
;*******************************************************    fin affichage 
ok:
ExamineKeyboard() 
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All) 
End 
Dernière modification par SPH le lun. 05/juin/2006 5:31, modifié 16 fois.
Avatar de l’utilisateur
Mindphazer
Messages : 694
Inscription : mer. 24/août/2005 10:42

Message par Mindphazer »

Voui, c'est sympa comme truc

(il faut juste préciser que c'est du PB 4...)
Bureau : Win10 64bits
Maison : Macbook Pro M3 16" SSD 512 Go / Ram 24 Go - iPad Pro 32 Go (pour madame) - iPhone 15 Pro Max 256 Go
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Message par SPH »

En voici mon ancien code :wink:

Vous pouvez changer la valeur CMB (combien). elle indique combien de shadeline s'affiche...

Code : Tout sélectionner

InitSprite() 
InitMouse() 
InitKeyboard() 
If ExamineDesktops() 
dw=DesktopWidth(0) 
dh=DesktopHeight(0) 
Else 
dw=1024 
dh=768 
EndIf 
cmb=8

OpenScreen(dw,dh,32,"") 



Dim t1.f(cmb) 
Dim t2.f(cmb) 
Dim tt1.f(cmb) 
Dim tt2.f(cmb) 
Dim t3.f(cmb) 
Dim t4.f(cmb) 
Dim tt3.f(cmb) 
Dim tt4.f(cmb) 
Dim rr.b(cmb) 
Dim vv.b(cmb) 
Dim bb.b(cmb) 
Dim ra1.f(cmb) 
Dim ra2.f(cmb) 
Dim ra3.f(cmb) 
Dim ra4.f(cmb) 
Dim mix(cmb) 
Dim miy(cmb) 


la: 
crono=0 

mix=dw/2 
miy=dh/2 

mix2=mix/2-1 
miy2=miy/2-1 


t0.f=Random(400)/1000 
tt0.f=0.02+Random(200)/10000 
t1.f=Random(400)/1000 
tt1.f=0.02+Random(200)/10000 
ra0=miy2/(4+Random(4)) 


Dim p(dw*dh) 
Dim r.b(dw,dh) 
Dim v.b(dw,dh) 
Dim b.b(dw,dh) 


For i=0 To cmb 
ry1=400+Random(700) 
ry2=400+Random(700) 
t1.f(i)=Random(80)/(420+Random(600)) 
t2.f(i)=Random(80)/(420+Random(600)) 
tt1.f(i)=(1+Random(45))/ry1 
tt2.f(i)=(1+Random(45))/ry2 
t3.f(i)=Random(80)/(420+Random(600)) 
t4.f(i)=Random(80)/(420+Random(600)) 
tt3.f(i)=(1+Random(45))/700 
tt4.f(i)=(1+Random(45))/700 
x=Random(5) 
crono+x*3
rr(i)=Random(x)
x-rr(i) 
vv(i)=Random(x)
x-vv(i) 
bb(i)=Random(x)
If Random(1)=0 
Swap rr(i),bb(i) 
EndIf 
ra1(i)=dh/(8.3+Random(400)/200) 
ra2(i)=dh/(8.3+Random(400)/200) 
ra3(i)=dh/(8.3+Random(400)/200) 
ra4(i)=dh/(8.3+Random(400)/200) 
mix(i)=dw/4+Random(dw/2.5) 
miy(i)=dh/4+Random(dh/2.5) 
Next 

dkx=dw/3 
dky=dh/3 


Repeat ;############################ 

For l=0 To cmb 
x1=mix(l)+Cos(t1(l))*ra1(l)-Cos(t3(l))*ra2(l) 
y1=miy(l)+Sin(t1(l))*ra1(l)-Sin(t3(l))*ra2(l) 

x2=mix(l)+Cos(t2(l))*ra3(l)-Cos(t4(l))*ra4(l) 
y2=miy(l)+Sin(t2(l))*ra4(l)-Sin(t4(l))*ra3(l) 


t1(l)+tt1(l) 
t2(l)+tt2(l) 
t3(l)+tt3(l) 
t4(l)+tt4(l) 

x=x2-x1 
y=y2-y1 

dist=Sqr(x*x+y*y) 
xf.f=x/dist 
yf.f=y/dist 

xx1.f=x1 
yy1.f=y1 

For i=0 To dist 
x=xx1.f 
y=yy1.f 
r(x,y)+rr(l) 
v(x,y)+vv(l) 
b(x,y)+bb(l) 
p(y*dw+x)=RGB(r(x,y),v(x,y),b(x,y)) 
r(x-1,y)+rr(l)/2
v(x-1,y)+vv(l)/2
b(x-1,y)+bb(l)/2
p(y*dw+x-1)=RGB(r(x-1,y),v(x-1,y),b(x-1,y)) 
r(x+1,y)+rr(l)/2
v(x+1,y)+vv(l)/2
b(x+1,y)+bb(l)/2
p(y*dw+x+1)=RGB(r(x+1,y),v(x+1,y),b(x+1,y)) 
r(x,y-1)+rr(l)/2
v(x,y-1)+vv(l)/2
b(x,y-1)+bb(l)/2
p((y-1)*dw+x)=RGB(r(x,y-1),v(x,y-1),b(x,y-1)) 
r(x,y+1)+rr(l)/2
v(x,y+1)+vv(l)/2
b(x,y+1)+bb(l)/2
p((y+1)*dw+x)=RGB(r(x,y+1),v(x,y+1),b(x,y+1)) 
xx1.f+xf 
yy1.f+yf 
Next 
Next l 

dkx2=dkx+Cos(t0)*ra0 
dky2=dky+Sin(t1)*ra0 
t0+tt0 
t1+tt1 

crono+1 

ExamineMouse() 
xmouse2=MouseDeltaX()/25 
ymouse2=MouseDeltaY()/25 



;StartDrawing(ScreenOutput()) 
;MemVideo = DrawingBuffer() 
;CopyMemory(@p(), MemVideo, dw*dh*4) 
;StopDrawing() 
;FlipBuffers() 
;Goto mm 



;*******************************************************    affichage 
StartDrawing(ScreenOutput()) 

For u=0 To miy2 
For i=0 To mix2 
Plot (i,u,p(i+dkx2+(u+dky2)*dw)) 
Plot (mix-i-1,u,p(i+dkx2+(u+dky2)*dw)) 
Plot (i,miy-u-1,p(i+dkx2+(u+dky2)*dw)) 
Plot (mix-i-1,miy-u-1,p(i+dkx2+(u+dky2)*dw)) 
Next 
Next 
StopDrawing() 
GrabSprite(0,0,0,mix,miy) 
DisplaySprite(0,mix,0) 
DisplaySprite(0,0,miy) 
DisplaySprite(0,mix,miy) 
If crono>=1000 
StartDrawing(ScreenOutput()) 
For i=0 To dh Step 16 
For u=0 To crono-1000 
LineXY(0,i+u,dw,i+u,0) 
Next 
Next 
StopDrawing() 
If crono=1015 
Goto la 
EndIf 
EndIf 
FlipBuffers() 
;*******************************************************    fin affichage 

mm: 
ExamineKeyboard() 
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All) 
End 
Dernière modification par SPH le jeu. 25/mai/2006 23:14, modifié 1 fois.
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Message par SPH »

Mon ancien code encore plus beau :

Code : Tout sélectionner

InitSprite() 
InitMouse() 
InitKeyboard() 
If ExamineDesktops() 
dw=DesktopWidth(0) 
dh=DesktopHeight(0) 
Else 
dw=1024 
dh=768 
EndIf 
cmb=40

OpenScreen(dw,dh,32,"") 



Dim t1.f(cmb) 
Dim t2.f(cmb) 
Dim tt1.f(cmb) 
Dim tt2.f(cmb) 
Dim t3.f(cmb) 
Dim t4.f(cmb) 
Dim tt3.f(cmb) 
Dim tt4.f(cmb) 
Dim rr.b(cmb) 
Dim vv.b(cmb) 
Dim bb.b(cmb) 
Dim ra1.f(cmb) 
Dim ra2.f(cmb) 
Dim ra3.f(cmb) 
Dim ra4.f(cmb) 
Dim mix(cmb) 
Dim miy(cmb) 


la: 
crono=0 

mix=dw/2 
miy=dh/2 

mix2=mix/2-1 
miy2=miy/2-1 


t0.f=Random(400)/1000 
tt0.f=0.02+Random(200)/10000 
t1.f=Random(400)/1000 
tt1.f=0.02+Random(200)/10000 
ra0=miy2/(4+Random(4)) 


Dim p(dw*dh) 
Dim r.b(dw,dh) 
Dim v.b(dw,dh) 
Dim b.b(dw,dh) 


For i=0 To cmb 
ry1=400+Random(700) 
ry2=400+Random(700) 
t1.f(i)=Random(80)/(420+Random(600)) 
t2.f(i)=Random(80)/(420+Random(600)) 
tt1.f(i)=(1+Random(45))/ry1 
tt2.f(i)=(1+Random(45))/ry2 
t3.f(i)=Random(80)/(420+Random(600)) 
t4.f(i)=Random(80)/(420+Random(600)) 
tt3.f(i)=(1+Random(45))/700 
tt4.f(i)=(1+Random(45))/700 
x=Random(5) 
crono+x*3
rr(i)=Random(x/1.5)
x-rr(i) 
vv(i)=Random(x)
x-vv(i) 
bb(i)=Random(x)
If Random(1)=0 
Swap vv(i),bb(i) 
EndIf 
ra1(i)=dh/(8.3+Random(400)/200) 
ra2(i)=dh/(8.3+Random(400)/200) 
ra3(i)=dh/(8.3+Random(400)/200) 
ra4(i)=dh/(8.3+Random(400)/200) 
mix(i)=dw/4+Random(dw/2.5) 
miy(i)=dh/4+Random(dh/2.5) 
Next 

dkx=dw/3 
dky=dh/3 


Repeat ;############################ 

For l=0 To cmb 
x1=mix(l)+Cos(t1(l))*ra1(l)-Cos(t3(l))*ra2(l) 
y1=miy(l)+Sin(t1(l))*ra1(l)-Sin(t3(l))*ra2(l) 

x2=mix(l)+Cos(t2(l))*ra3(l)-Cos(t4(l))*ra4(l) 
y2=miy(l)+Sin(t2(l))*ra4(l)-Sin(t4(l))*ra3(l) 


t1(l)+tt1(l) 
t2(l)+tt2(l) 
t3(l)+tt3(l) 
t4(l)+tt4(l) 

x=x2-x1 
y=y2-y1 

dist=Sqr(x*x+y*y) 
xf.f=x/dist 
yf.f=y/dist 

xx1.f=x1 
yy1.f=y1 

For i=0 To dist 
x=xx1.f 
y=yy1.f 
r(x,y)+rr(l) 
v(x,y)+vv(l) 
b(x,y)+bb(l) 
p(y*dw+x)=RGB(r(x,y),v(x,y),b(x,y)) 
r(x-1,y)+rr(l)/2
v(x-1,y)+vv(l)/2
b(x-1,y)+bb(l)/2
p(y*dw+x-1)=RGB(r(x-1,y),v(x-1,y),b(x-1,y)) 
r(x+1,y)+rr(l)/2
v(x+1,y)+vv(l)/2
b(x+1,y)+bb(l)/2
p(y*dw+x+1)=RGB(r(x+1,y),v(x+1,y),b(x+1,y)) 
r(x,y-1)+rr(l)/2
v(x,y-1)+vv(l)/2
b(x,y-1)+bb(l)/2
p((y-1)*dw+x)=RGB(r(x,y-1),v(x,y-1),b(x,y-1)) 
r(x,y+1)+rr(l)/2
v(x,y+1)+vv(l)/2
b(x,y+1)+bb(l)/2
p((y+1)*dw+x)=RGB(r(x,y+1),v(x,y+1),b(x,y+1)) 
xx1.f+xf 
yy1.f+yf 
Next 
Next l 

dkx2=dkx+Cos(t0)*ra0 
dky2=dky+Sin(t1)*ra0 
t0+tt0 
t1+tt1 

crono+1 

ExamineMouse() 
xmouse2=MouseDeltaX()/25 
ymouse2=MouseDeltaY()/25 



;StartDrawing(ScreenOutput()) 
;MemVideo = DrawingBuffer() 
;CopyMemory(@p(), MemVideo, dw*dh*4) 
;StopDrawing() 
;FlipBuffers() 
;Goto mm 



;*******************************************************    affichage 
StartDrawing(ScreenOutput()) 

For u=0 To miy2 
For i=0 To mix2 
Plot (i,u,p(i+dkx2+(u+dky2)*dw)) 
Plot (mix-i-1,u,p(i+dkx2+(u+dky2)*dw)) 
Plot (i,miy-u-1,p(i+dkx2+(u+dky2)*dw)) 
Plot (mix-i-1,miy-u-1,p(i+dkx2+(u+dky2)*dw)) 
Next 
Next 
StopDrawing() 
GrabSprite(0,0,0,mix,miy) 
DisplaySprite(0,mix,0) 
DisplaySprite(0,0,miy) 
DisplaySprite(0,mix,miy) 
If crono>=1000 
StartDrawing(ScreenOutput()) 
For i=0 To dh Step 16 
For u=0 To crono-1000 
LineXY(0,i+u,dw,i+u,0) 
Next 
Next 
StopDrawing() 
If crono=1015 
Goto la 
EndIf 
EndIf 
FlipBuffers() 
;*******************************************************    fin affichage 

mm: 
ExamineKeyboard() 
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All) 
End 
Dernière modification par SPH le jeu. 25/mai/2006 23:15, modifié 1 fois.
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

superbe #good
Image
CameleonTH
Messages : 333
Inscription : sam. 25/juin/2005 11:18
Localisation : Laon (02)
Contact :

Message par CameleonTH »

Sa rend super bien et sa fai un effet d'optique par la méme ocasion, on voit que se son les méme images mai on a l'impression que chaques images bouge alors que c'est leurs contenue qui bouge.
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

si tu veut pouvoir gerer une boite de config faut faire comme ça

(la boite de config s'apelle par le menu "parametrer le screen saver"
de windows !! apres l'avoir compillé en screensaver et mis dans C:\WINDOWS\system32 (sous XP))

dans le code ci dessous :

la variable dobro=0 indique que le bon mot de passe "dobro" n'as pas ete entré !
alors que dobro=1 indique que le bon mot de passe a ete entré

a toi de voir ce que tu fais de cette info !!



Code : Tout sélectionner


; code Pure basic 4.00 

; ici les initialisations des variables et tableaux 
;"/s" pour le lancer
;"/c:" + un nombre pour le faire Paramétrer
;"/p", espace, et un nombre qd son nom est simplement séletionné dans la boîte des propriétés du bureau
; "/p" , peut etre Preview ??

;Code: 
;

;- Gadget Constants
;
Enumeration
  #Window_0
  #code
  #Text_0
  #Police
EndEnumeration
  
Resultat = InitSprite()
Resultat = InitSprite3D() 
FontID = LoadFont(#Police, "system", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN)
EcranY = GetSystemMetrics_(#SM_CYSCREEN)
InitMouse()
InitKeyboard()
  
  
  
  
Procedure Open_Window_0()
  If OpenWindow(#Window_0, 293, 129, 249, 109, "config", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar)
    If CreateGadgetList(WindowID(#Window_0))
      StringGadget(#code, 40, 50, 170, 30, "", #PB_String_Password)
      TextGadget(#Text_0, 10, 20, 90, 20, "ENTREZ le Code")
    EndIf
  EndIf
EndProcedure




;*********** pour le screensaver
Param.s = Left(ProgramParameter(), 2)
If Param = "/p"
  End
EndIf

If Param = "/c" :;l'utilisateur veut paramettrer le screensaver !
  Open_Window_0():; jouvre ma fenetre ( cree a partir de visual designer)
  Repeat
    Texte$ = GetGadgetText(#code):;je recupere le contenu de ma boite de config
    If Texte$="dobro":;si le gars tappe le code "dobro"
      dobro=1:; c'est bon on affiche pas la surimpression
      code$="ok":;on se prepare a ecrire le mot "ok" dans un fichier
      Resultat = OpenFile(1, "matrix.ini") :;on cree le fichier
      WriteStringN(1,code$) :; on ecrit dedans "ok"
      CloseFile(1)
    Else
      dobro=0:; la le mec a pas rentré le bon code
    EndIf
  Until WindowEvent() = #PB_Event_CloseWindow :; le gars a fermé la boite de config
EndIf

GetCursorPos_(SourisOrigine.POINT)
ShowCursor_(0)
; ***********************************

FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN)
EcranY = GetSystemMetrics_(#SM_CYSCREEN)

If ReadFile(1, "matrix.ini"):;en temps normal on commence par regarder si le screen saver est enregistré
  code$ = ReadString(1) :; on lit le contenu de "matrix.ini"
  CloseFile(1)
EndIf
 
If code$="ok":; bon le gars est enregistré
  dobro=1:; ce flag va retirer la surimpression
Else
  dobro=0:; il n'est pas enregistrer donc on peut agir en consequence ici (affiche la surimpression par ex !! )
EndIf
;************ c'est tout pour le parametrage du screen saver
ShowCursor_(0)
; ***********************************

;NbSprite = EcranX / 40 * 3
NbSprite =12
OpenWindow(1, 0, 0, EcranX, EcranY, "Dos 3.10", #PB_Window_BorderLess)
SetWindowPos_(WindowID(1), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE) ; fenêtre toujours au premier plan
OpenWindowedScreen(WindowID(1), 0, 0, EcranX, EcranY, 1, 0, 0)

; faire ici les initialisations du pre affichage

dw=EcranX 
dh=EcranY
cmb=40

Dim t1.f(cmb)
Dim t2.f(cmb)
Dim tt1.f(cmb)
Dim tt2.f(cmb)
Dim t3.f(cmb)
Dim t4.f(cmb)
Dim tt3.f(cmb)
Dim tt4.f(cmb)
Dim rr.b(cmb)
Dim vv.b(cmb)
Dim bb.b(cmb)
Dim ra1.f(cmb)
Dim ra2.f(cmb)
Dim ra3.f(cmb)
Dim ra4.f(cmb)
Dim mix(cmb)
Dim miy(cmb)


la:
crono=0

mix=dw/2
miy=dh/2

mix2=mix/2-1
miy2=miy/2-1


t0.f=Random(400)/1000
tt0.f=0.02+Random(200)/10000
t1.f=Random(400)/1000
tt1.f=0.02+Random(200)/10000
ra0=miy2/(4+Random(4))


Dim p(dw*dh)
Dim r.b(dw,dh)
Dim v.b(dw,dh)
Dim b.b(dw,dh)


For i=0 To cmb
  ry1=400+Random(700)
  ry2=400+Random(700)
  t1.f(i)=Random(80)/(420+Random(600))
  t2.f(i)=Random(80)/(420+Random(600))
  tt1.f(i)=(1+Random(45))/ry1
  tt2.f(i)=(1+Random(45))/ry2
  t3.f(i)=Random(80)/(420+Random(600))
  t4.f(i)=Random(80)/(420+Random(600))
  tt3.f(i)=(1+Random(45))/700
  tt4.f(i)=(1+Random(45))/700
  x=Random(5)
  crono+x*3
  rr(i)=Random(x/1.5)
  x-rr(i)
  vv(i)=Random(x)
  x-vv(i)
  bb(i)=Random(x)
  If Random(1)=0
    Swap vv(i),bb(i)
  EndIf
  ra1(i)=dh/(8.3+Random(400)/200)
  ra2(i)=dh/(8.3+Random(400)/200)
  ra3(i)=dh/(8.3+Random(400)/200)
  ra4(i)=dh/(8.3+Random(400)/200)
  mix(i)=dw/4+Random(dw/2.5)
  miy(i)=dh/4+Random(dh/2.5)
Next

dkx=dw/3
dky=dh/3



Repeat :;boucle principale
  
  For l=0 To cmb
    x1=mix(l)+Cos(t1(l))*ra1(l)-Cos(t3(l))*ra2(l)
    y1=miy(l)+Sin(t1(l))*ra1(l)-Sin(t3(l))*ra2(l)
    
    x2=mix(l)+Cos(t2(l))*ra3(l)-Cos(t4(l))*ra4(l)
    y2=miy(l)+Sin(t2(l))*ra4(l)-Sin(t4(l))*ra3(l)
    
    
    t1(l)+tt1(l)
    t2(l)+tt2(l)
    t3(l)+tt3(l)
    t4(l)+tt4(l)
    
    x=x2-x1
    y=y2-y1
    
    dist=Sqr(x*x+y*y)
    xf.f=x/dist
    yf.f=y/dist
    
    xx1.f=x1
    yy1.f=y1
    
    For i=0 To dist
      x=xx1.f
      y=yy1.f
      r(x,y)+rr(l)
      v(x,y)+vv(l)
      b(x,y)+bb(l)
      p(y*dw+x)=RGB(r(x,y),v(x,y),b(x,y))
      r(x-1,y)+rr(l)/2
      v(x-1,y)+vv(l)/2
      b(x-1,y)+bb(l)/2
      p(y*dw+x-1)=RGB(r(x-1,y),v(x-1,y),b(x-1,y))
      r(x+1,y)+rr(l)/2
      v(x+1,y)+vv(l)/2
      b(x+1,y)+bb(l)/2
      p(y*dw+x+1)=RGB(r(x+1,y),v(x+1,y),b(x+1,y))
      r(x,y-1)+rr(l)/2
      v(x,y-1)+vv(l)/2
      b(x,y-1)+bb(l)/2
      p((y-1)*dw+x)=RGB(r(x,y-1),v(x,y-1),b(x,y-1))
      r(x,y+1)+rr(l)/2
      v(x,y+1)+vv(l)/2
      b(x,y+1)+bb(l)/2
      p((y+1)*dw+x)=RGB(r(x,y+1),v(x,y+1),b(x,y+1))
      xx1.f+xf
      yy1.f+yf
    Next i
  Next l
  
  dkx2=dkx+Cos(t0)*ra0
  dky2=dky+Sin(t1)*ra0
  t0+tt0
  t1+tt1
  
  crono+1
  ExamineMouse()
  xmouse2=MouseDeltaX()/25
  ymouse2=MouseDeltaY()/25
  
  
  
  
  ;*******************************************************    affichage
  StartDrawing(ScreenOutput())
  
  For u=0 To miy2
    For i=0 To mix2
      Plot (i,u,p(i+dkx2+(u+dky2)*dw))
      Plot (mix-i-1,u,p(i+dkx2+(u+dky2)*dw))
      Plot (i,miy-u-1,p(i+dkx2+(u+dky2)*dw))
      Plot (mix-i-1,miy-u-1,p(i+dkx2+(u+dky2)*dw))
    Next
  Next
  StopDrawing()
  GrabSprite(0,0,0,mix,miy)
  DisplaySprite(0,mix,0)
  DisplaySprite(0,0,miy)
  DisplaySprite(0,mix,miy)
  If crono>=1000
    StartDrawing(ScreenOutput())
    For i=0 To dh Step 16
      For u=0 To crono-1000
        LineXY(0,i+u,dw,i+u,0)
      Next
    Next
    StopDrawing()
    
    If crono=1015
      Goto la
    EndIf
  EndIf
  ;*******************************************************    fin affichage  
  FlipBuffers():;affichage 
  mm:
  ExamineKeyboard()
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All)
End 
ShowCursor_(1)
Avatar de l’utilisateur
Droopy
Messages : 1151
Inscription : lun. 19/juil./2004 22:31

Message par Droopy »

Superbe :wink:
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

puisqu'on en est aux screen saver ,
je resort mon Matrix4 (pour les nouveaux :lol: )
mis a la sauce Purebasic 4.00 (mais sans optimisation, juste compatible)


Code : Tout sélectionner

; Matrix Cree Par Dobro
;CallDebugger
; code PureBasic 4.00

Enumeration
    #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
    #code
    #Text_0
EndEnumeration
Procedure Open_Window_0()
    If OpenWindow(#Window_0, 293, 129, 249, 109, "config",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
        If CreateGadgetList(WindowID(#Window_0))
            StringGadget(#code, 40, 50, 170, 30, "", #PB_String_Password)
            TextGadget(#Text_0, 10, 20, 90, 20, "ENTREZ le Code")
        EndIf
    EndIf
EndProcedure
nbrsprite=18:;nombre de sprite dans les lignes 
; on appercoit les sprites sur la meme colonne affiché l'un apres l'autre !!
taille_fonte =20
Dim ysprite(1000)
Dim de(1000)
Dim nom$(nbrsprite)
Dim index(nbrsprite)

Dim y(nbrsprite)


sprite=1
#Police=1
;*********** pour le screensaver
Param.s = Left(ProgramParameter(), 2)
If Param = "/p"
    End
EndIf

If Param = "/c" :;l'utilisateur veut paramettrer le screensaver !
    Open_Window_0():; jouvre ma fenetre ( cree a partir de visual designer)
    Repeat
        Texte$ = GetGadgetText(#code):;je recupere le contenu de ma boite de config
        If Texte$="dobro":;si le gars tappe le code "dobro"
        dobro=1:; c'est bon on affiche pas la surimpression
        code$="ok":;on se prepare a ecrire le mot "ok" dans un fichier
        Resultat = OpenFile(1, "matrix.ini") :;on cree le fichier
        WriteStringN(1,code$) :; on ecrit dedans "ok"
        CloseFile(1)
    Else
        dobro=0:; la le mec a pas rentré le bon code
    EndIf
Until WindowEvent() = #PB_Event_CloseWindow :; le gars a fermé la boite de config
EndIf

GetCursorPos_(SourisOrigine.POINT)
ShowCursor_(0)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", taille_fonte, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN)
EcranY = GetSystemMetrics_(#SM_CYSCREEN)

;If ReadFile(1, "matrix.ini"):;en temps normal on commence par regarder si le screen saver est enregistré
 ;   code$ = ReadString() :; on lit le contenu de "matrix.ini"
;EndIf
;CloseFile(1) 
If code$="ok":; bon le gars est enregistré
    dobro=1:; ce flag va retirer la surimpression
Else
    dobro=0:; il n'est pas enregistrer donc on affiche la surimpression
EndIf
;************ c'est tout pour le parametrage du screen saver




;NbSprite = EcranX / 40 * 3
OpenWindow(1, 0, 0, EcranX, EcranY, "Matrix", #PB_Window_BorderLess )

SetWindowPos_(WindowID(1), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE) ; fenêtre toujours au premier plan

OpenWindowedScreen(WindowID(1), 0, 0, EcranX, EcranY, 1, 0, 0)
   
    For reserv=1 To nbrsprite
        nom$(reserv)=Space(30) 
    Next reserv
   
    ; on crée un sprite
    For spr=1 To nbrsprite:; nombre de sprite
         Resultat = CreateSprite(spr, 24,27*Len(nom$(spr)),0)
        
        For chaine=33 To 58:; nombre de caractere dans un sprite
            car$=Chr(chaine+Random(223))
            y(spr)=y(spr)+27:; pour que le text s'ecrive une ligne au dessous dans le sprite
            StartDrawing(SpriteOutput(spr)):;on commence a dessiner dans le sprite SPR
            BackColor(RGB(0,0,0)):;couleur de fond noir
            c = c +255/25 :; on eclaircie la couleur d'ecriture!!
            If c>255:c=20:EndIf:; si on depasse 255 (verta fond) on ramene a 20 (vert sombre)
            If chaine=58
                c = 0 :; on fixe la couleur a 20 (vert sombre)
            EndIf 
            ;c=255
            FrontColor(RGB(0, c, 0)): ;on prend la couleur defini plus haut pour dessiner
            If chaine=57:;l'avant dernier caractere
                FrontColor(RGB(130, 255,130)): ;on choisi une couleur verte presque blanche 
            EndIf 
            ;ConsoleLocate(0, y(spr)):;ceci pose le crayon au bon endroit (une ligne en dessous) comme indique plus haut
            DrawingFont(FontID):;attention on va ecrire du text sur la zone reserve du sprite
            DrawText(0, y(spr),car$):; voila on le fait
            long = TextWidth(nom$(1))
            StopDrawing():; signale que l'on arrete de dessiner sur le sprite SPR
        Next chaine
    Next spr
    ;ceci prepare les colonne qui vont etre solicite pour l'affichage, un "precalcul" en fait
    xrez=Int(EcranX/27)
    Dim col(xrez)
    For t=1 To EcranX Step 27
        col(h)=t
        h+1
        du:
    Next t
    
    ;***********************************
    indexc=0
    
    For ind=1 To xrez :;correspond au nombre de colonne (en 1024)
        ysprite(ind)=-(long*2)-Random(long*10):; tire au hazard une ligne pourle depart d"un sprite
        If Col<>EcranX :; tant que la valeur lu est differente de la rez ecran en x
            indexc=indexc+1 :
            de(ind)=col(ind)
            ;If carcol$=""
            ;    de(ind)=27
            ;EndIf
        Else
            indexc=0
        EndIf
    Next ind
    indexc=0
    pseud=255
    Repeat
       
        ;Debug st
        RandomSeed(Random(255))
        For ind=1 To xrez
            ; si le sprite sort en bas
            If ysprite(ind)>EcranY
                ysprite(ind)=-(2+long*2)-Random(long*2)
            EndIf
            ; toute l'astuce de l'animation est la !!
            spr=spr+1
            If spr>nbrsprite:; on affiche les sprite en decalant une lettre !!
                spr=1
            EndIf
            ysprite(ind)=ysprite(ind)+Random(8)+2:; vitesse de descente des sprites
            ;DisplayTransparentSprite (spr, de(ind), ysprite(ind))
            DisplaySprite(spr, de(ind), ysprite(ind)) 
            ;CallDebugger
            ;Debug st2
            
            
        Next ind
        ; affichage des noms
        
        If pseud>=380
            pseud=254
        EndIf
        If dobro=0
        ;**************** crée par Dobro **********************
        StartDrawing( ScreenOutput()) 
        BackColor(RGB(0,0,0)):;couleur de fond noir
        FrontColor(RGB(0, 120, 0))
        ;Locate(EcranX-TextLength("Créé par Dobro")-100, EcranY-25):;ceci pose le crayon au bon endroit (une ligne en dessous) comme indique plus haut
        DrawingFont(FontID):;attention on va ecrire du text sur la zone reserve du sprite
        DrawText(EcranX-TextWidth("Créé par Dobro")-100, EcranY-25,"Créé par Dobro"):; voila on le fait
        StopDrawing():
        ; ********************************************
        EndIf
        FlipBuffers()
        ClearScreen(RGB(0,0,0))
        
        GetCursorPos_(Souris.POINT)
    Until WindowEvent() = #PB_Event_CloseWindow Or Souris\x <> SourisOrigine\x Or Souris\y <> SourisOrigine\y
    ShowCursor_(1)
; IDE Options = PureBasic v3.94 (Windows - x86)
; CursorPosition = 78
; FirstLine = 68
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Message par SPH »

Voila, j'ai modifié mon premier post. Il explique ce que vous devez savoir.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

C'est super, bravo.
http://purebasic.developpez.com/
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Message par djes »

Très joli :D
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Message par SPH »

Je ne sais pas pour vous, mais moi, je suis tombé amoureux de mon code. J'arrete pas de matter ce que ca donne... Au point où je l'ai tellement regardé que ca me gave maintenant !

A propos, regardez mon code et trouvez la partie :

Code : Tout sélectionner

swp.b=Random(20) 

Repeat ;############################ 
Essayez "swp=5" puis "swp=7" (vous verrez un effet de flou/blur)
Le tracage est beaucoup plus rapide !! Mais justement, ne faut il pas que je mette un Delay(1) sur l'ensemble du code ????
Car dans Delay, je suppose que le programme affiche a une vitesse folle sur de tres gros PC, non ?????
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Message par SPH »

Bien plus rapide car presque entierement en ASSEMBLEUR :

Code : Tout sélectionner

; Codé par SPH(2006) sur PB4

InitSprite() 
InitMouse() 
InitKeyboard() 

SetPriorityClass_ ( GetCurrentProcess_ (), #IDLE_PRIORITY_CLASS )

If ExamineDesktops() 
dw.w=DesktopWidth(0) 
dh.w=DesktopHeight(0) 
Else 
dw.w=1024 
dh.w=768 
EndIf 
cmb.w=14

OpenScreen(dw,dh,32,"") 

rrr.b=0
vvv.b=0
bbb.b=0

zz.l=0
x.w=0
y.w=0

Dim t1.f(cmb) 
Dim t2.f(cmb) 
Dim tt1.f(cmb) 
Dim tt2.f(cmb) 
Dim t3.f(cmb) 
Dim t4.f(cmb) 
Dim tt3.f(cmb) 
Dim tt4.f(cmb) 
Dim rr.b(cmb) 
Dim vv.b(cmb) 
Dim bb.b(cmb) 
Dim ra1.f(cmb) 
Dim ra2.f(cmb) 
Dim ra3.f(cmb) 
Dim ra4.f(cmb) 
Dim mix(cmb) 
Dim miy(cmb) 


SPH: 
crono.w=0
swp.b=Random(4)

mix=dw/2 
miy=dh/2 

mix2=mix/2-1 
miy2=miy/2-1 

t0.f=Random(400)/1000 
tt0.f=0.009+Random(500)/10000 
t1.f=Random(400)/1000 
tt1.f=0.009+Random(500)/10000 
t2.f=Random(400)/1000 
tt2.f=0.009+Random(500)/10000 
t3.f=Random(400)/1000 
tt3.f=0.009+Random(500)/10000 
ra0.w=miy2/(8+Random(4)) 

Dim r.w(dw,dh) 
Dim v.w(dw,dh) 
Dim b.w(dw,dh) 


For i=0 To cmb 
ry1=400+Random(700) 
ry2=400+Random(700) 
t1.f(i)=Random(80)/(420+Random(600)) 
t2.f(i)=Random(80)/(420+Random(600)) 
tt1.f(i)=(1+Random(45))/ry1 
tt2.f(i)=(1+Random(45))/ry2 
t3.f(i)=Random(80)/(420+Random(600)) 
t4.f(i)=Random(80)/(420+Random(600)) 
tt3.f(i)=(1+Random(45))/700 
tt4.f(i)=(1+Random(45))/700 
x=255
y=Random(x)
rr(i)=y
x-y
y=Random(x)
vv(i)=x
x-y
y=Random(x)
bb(i)=x
If Random(1+swp)=0
Swap rr(i),bb(i)
Else
If Random(1+swp)=0
Swap vv(i),bb(i)
EndIf
EndIf


ra1(i)=dh/(8.3+Random(400)/200) 
ra2(i)=dh/(8.3+Random(400)/200) 
ra3(i)=dh/(8.3+Random(400)/200) 
ra4(i)=dh/(8.3+Random(400)/200) 
mix(i)=dw/4+Random(dw/2.1) 
miy(i)=dh/4+Random(dh/2.1) 
Next 

dkx=dw/2.67
dky=dh/2.67

swp.b=Random(20)
If swp=5 Or swp=7
crono-300
EndIf


Repeat ;############################ 

For l=0 To cmb 
x1=mix(l)+Cos(t1(l))*ra1(l)-Cos(t3(l))*ra2(l) 
y1=miy(l)+Sin(t1(l))*ra1(l)-Sin(t3(l))*ra2(l) 

x2=mix(l)+Cos(t2(l))*ra3(l)-Cos(t4(l))*ra4(l) 
y2=miy(l)+Sin(t2(l))*ra4(l)-Sin(t4(l))*ra3(l) 

t1(l)+tt1(l) 
t2(l)+tt2(l) 
t3(l)+tt3(l) 
t4(l)+tt4(l) 

x=x2-x1 
y=y2-y1

dist.l=Sqr(x*x+y*y) 
xf.f=x/dist 
yf.f=y/dist 

xx1.f=x1 
yy1.f=y1 


For i=0 To dist 
;x=xx1.f 
;y=yy1.f

;zz.l=(dh+1)*2*y+2*(x-1)
!xor eax,eax
!mov ax,[v_dh]
!inc ax
!sal eax,1
!cvttss2si ecx,[v_yy1] ; (conversion du flotant en entier avec troncature des décimales) 
;!mov [v_y],cx
!mul ecx
;!xor edx,edx
;!mov dx,[v_y]
;!mul edx

;
!cvttss2si ecx,[v_xx1] ; (conversion du flotant en entier avec troncature des décimales) 
;!mov [v_x],cx
;!xor edx,edx
;!mov dx,[v_x]
!dec cx
!sal ecx,1
!add eax,ecx
;
!mov [v_zz],eax
;326
;Debug zz
;End



;********* procedure ASM antialiasing + affinage des couleurs (real 24bits rulez)

;R
!MOV      dword Ecx,[a_r]
!add      ecx,[v_zz]
!mov      ax,[ecx]

!MOV      dword Edx,[a_rr]
!add      dword Edx,[v_l]
!mov      dl,[edx]
!xor      dh,dh
!add      ax,dx
!mov      [ecx],ax

!add      ecx,4
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,2
!mov      ax,[ecx]
!add      ax,dx
!add      ax,dx
!add      ax,dx
!add      ax,40
!mov      [ecx],ax

!sub      cx,[v_dh] 
!sub      cx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!add      cx,[v_dh] 
!add      cx,[v_dh] 
!add      cx,[v_dh] 
!add      cx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax
;********************
;V
!MOV      dword Ecx,[a_v]
!add      ecx,[v_zz]
!mov      ax,[ecx]

!MOV      dword Edx,[a_vv]
!add      dword Edx,[v_l]
!mov      dl,[edx]
!xor      dh,dh
!add      ax,dx
!mov      [ecx],ax

!add      ecx,4
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,2
!mov      ax,[ecx]
!add      ax,dx
!add      ax,dx
!add      ax,dx
!add      ax,40
!mov      [ecx],ax

!sub      cx,[v_dh] 
!sub      cx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!add      cx,[v_dh] 
!add      cx,[v_dh] 
!add      cx,[v_dh] 
!add      cx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax
;********************
;B
!MOV      dword Ecx,[a_b]
!add      ecx,[v_zz]
!mov      ax,[ecx]

!MOV      dword Edx,[a_bb]
!add      dword Edx,[v_l]
!mov      dl,[edx]
!xor      dh,dh
!add      ax,dx
!mov      [ecx],ax

!add      ecx,4
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!sub      ecx,2
!mov      ax,[ecx]
!add      ax,dx
!add      ax,dx
!add      ax,dx
!add      ax,40
!mov      [ecx],ax

!sub      cx,[v_dh] 
!sub      cx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax

!add      cx,[v_dh] 
!add      cx,[v_dh] 
!add      cx,[v_dh] 
!add      cx,[v_dh] 
!mov      ax,[ecx]
!add      ax,dx
!mov      [ecx],ax
;******************************************** fin de ma sublime procedure ASM

xx1.f+xf 
yy1.f+yf 

Next i
Next l 

dkx2.w=dkx+Cos(t0)*ra0+Cos(t2)*ra0 
dky2.w=dky+Sin(t1)*ra0+Sin(t3)*ra0 
t0+tt0 
t1+tt1 
t2+tt2 
t3+tt3 

;crono+1 
!inc [v_crono]

ExamineMouse() 
xmouse2=MouseDeltaX()/25 
ymouse2=MouseDeltaY()/25 

;*******************************************************    affichage 
StartDrawing(ScreenOutput()) 
For u=0 To miy2 
;zz=(dh+1)*2*(u+dky2)+2*dkx2
;Debug zz
!xor eax,eax
!mov ax,[v_dh]
!inc ax
!sal eax,1
;
!xor ecx,ecx
!mov cx,[v_dky2]
!add ecx,dword[v_u]
!mul ecx
;
!xor ecx,ecx
!mov cx,[v_dkx2]
!sal ecx,1
!add eax,ecx
!mov [v_zz],eax
;Debug zz
;Debug("=====")


For i=0 To mix2
;zz+2
!add [v_zz],2

!MOV      dword ecx,[a_r]
!add      ecx,[v_zz]
!mov      ax, [ecx]
!mov      [v_rrr], ah

!MOV      dword ecx,[a_v]
!add      ecx,[v_zz]
!mov      ax, [ecx]
!mov      [v_vvv], ah

!MOV      dword ecx,[a_b]
!add      ecx,[v_zz]
!mov      ax, [ecx]
!mov      [v_bbb], ah

If swp>8
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(rrr,vvv,bbb))
Plot (i,miy-u-1,RGB(rrr,vvv,bbb))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,bbb))
Else
If swp=1
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(rrr,vvv,bbb))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(vvv,bbb,rrr))
Else
If swp=2
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(bbb,rrr,vvv))
Plot (i,miy-u-1,RGB(rrr,vvv,bbb))
Plot (mix-i-1,miy-u-1,RGB(bbb,rrr,vvv))
Else
If swp=3
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(vvv,bbb,rrr))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,bbb))
Else
If swp=4 Or swp=5
If Random(swp*9-36)=0
Plot (i,u,RGB(rrr,vvv,rrr))
Plot (mix-i-1,u,RGB(rrr,vvv,rrr))
Plot (i,miy-u-1,RGB(rrr,vvv,rrr))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,rrr))
Else
If Random(9)=0
Plot (i,u,RGB(bbb,bbb,vvv))
Plot (mix-i-1,u,RGB(rrr,bbb,vvv))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(vvv,rrr,bbb))
EndIf
EndIf
Else
If swp=6 Or swp=7
If Random(swp*6-36)=0
Plot (i,u,RGB(rrr,bbb,vvv))
Plot (mix-i-1,u,RGB(rrr,bbb,vvv))
Plot (i,miy-u-1,RGB(rrr,bbb,vvv))
Plot (mix-i-1,miy-u-1,RGB(rrr,bbb,vvv))
EndIf
Else
If swp=8
If i+u<mix/2
Plot (i,u,RGB(vvv,bbb,rrr))
Plot (mix-i-1,u,RGB(vvv,bbb,rrr))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(vvv,bbb,rrr))
Else
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(rrr,vvv,bbb))
Plot (i,miy-u-1,RGB(rrr,vvv,bbb))
Plot (mix-i-1,miy-u-1,RGB(rrr,vvv,bbb))
EndIf
Else
Plot (i,u,RGB(rrr,vvv,bbb))
Plot (mix-i-1,u,RGB(vvv,rrr,bbb))
Plot (i,miy-u-1,RGB(vvv,bbb,rrr))
Plot (mix-i-1,miy-u-1,RGB(rrr,bbb,vvv))
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf

Next 
Next 

stop:
StopDrawing() 
GrabSprite(0,0,0,mix,miy) 
DisplaySprite(0,mix,0) 
DisplaySprite(0,0,miy) 
DisplaySprite(0,mix,miy) 
If crono>=1000 
StartDrawing(ScreenOutput()) 
For i=0 To dh Step 16
Box(0,i,dw,crono-1000,0) 
Next 
StopDrawing() 
If crono=1016
Goto SPH
EndIf 
EndIf 
FlipBuffers()
Delay(2)
;*******************************************************    fin affichage 
ok:
ExamineKeyboard() 
Until xmouse<>xmouse2 Or ymouse<>ymouse2 Or KeyboardPushed(#PB_Key_All) 
End 
Dernière modification par SPH le lun. 05/juin/2006 12:53, modifié 1 fois.
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Message par djes »

Je me souviens, il y a quelques années, maître toto regardait mes codes et me disait : pas assez optimisé! Alors il reprenait tout, et mon truc de 500 cycles se réduisait, se réduisait, jusqu'à n'en faire plus que 30...

Vu que tu es bien parti pour devenir un futur guru de l'asm, qq pistes pour faire plus rapide :
La fonction RGB appelée je ne sais combien de fois : une petite macro la remplacerait avantageusement (attention à l'ordre des composantes quand même) ou même une simple variable, vu que tu réutilises dix foix la même valeur!
Les randoms et les multiplications/divisions partout dans la boucle principale...
Les tests par rapport à la valeur de swp. En assembleur, on peut faire un saut relatif. Il suffit d'aligner son code :)
Y'en a d'autres, mais tu vas les trouver tout seul, je te fais confiance
Répondre