Page 1 sur 1

Plot tunnel

Publié : jeu. 09/mai/2019 23:16
par SPH
Salut, 8)

voici un tunnel en points qui ne me satisfait qu'a moitié :

Code : Tout sélectionner

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Erreur", "Impossible d'initialiser l'écran.")
  End
EndIf


ExamineDesktops()
ddw=DesktopWidth(0)
ddh=DesktopHeight(0)

ddw2=1024
ddh2=768

ddh3.f=(ddh/ddh2)

If OpenScreen(ddw,ddh,32,"SPH Demo")=0
  MessageRequester("Erreur", "Impossible d'ouvrir l'écran.")
  End
EndIf



ClearScreen(0)
StartDrawing(ScreenOutput())

For i=0 To ddw-2 Step 5
  For u=0 To ddh-2 Step 5
    Plot(i,u,RGB(Random(40),0,Random(40)))
  Next
Next

For i=1 To 30000
  Plot(Random(ddw-1),Random(ddh-1),0)
  Plot(Random(ddw-1),Random(ddh-1),RGB(Random(Random(99)),0,Random(Random(99))))
Next


For i=1 To 700
  rgb=Random(110)
  Plot(Random(ddw-1),Random(ddh-1),RGB(rgb,rgb,rgb))
Next
For i=1 To 20
  rgb=Random(255)
  xsph=Random(ddw-5)
  ysph=Random(ddh-5)
  Plot(1+xsph,1+ysph,RGB(rgb,rgb,rgb))
  Plot(xsph,1+ysph,RGB(rgb/2,rgb/2,rgb/2))
  Plot(2+xsph,1+ysph,RGB(rgb/2,rgb/2,rgb/2))
  Plot(1+xsph,ysph,RGB(rgb/2,rgb/2,rgb/2))
  Plot(1+xsph,2+ysph,RGB(rgb/2,rgb/2,rgb/2))
Next

StopDrawing() 

GrabSprite(1,0,0,ddw,ddh)





Structure pixel 
  posx.f
  posy.f
  xx.f
  yy.f
  centrex.l
  centrey.l
  rayon.f
  couleur.l
EndStructure 

NewList pixel.pixel() ; pour pas s'y perdre, vaux mieux donner le meme nom a la structure qu'a la liste

time=0
centrex=ddw2/2
centrey=ddh2/2
centrex=ddw/2
centrey=ddh/2
angle.f=0
rnd_angle.f=20
rnd_randon=200
vitessex.f=0.02
vitessey.f=0.02
nbb=0

;############
;############
;############
;############
;############
;############
xxx.f=1
yyy.f=3

oldxxx.f=xxx
oldyyy.f=yyy

xxx2.f=2.2
yyy2.f=1.4

oldxxx2.f=xxx2
oldyyy2.f=yyy2

rota.f=0
oldrota.f=rota

Repeat
  
  ExamineKeyboard() 
  
  DisplaySprite(1,0,0)
  
  ;********************************************
  
  For i=1 To 10
    AddElement(pixel())
    pixel()\centrex=centrex
    pixel()\centrey=centrey
    rayon.f=5+Random(500)
    angle=Random(6559)
    x = Cos(angle)*rayon
    y = Sin(angle)*rayon
    pixel()\posx = x
    pixel()\posy = y
    z=Random(100)+20
    pixel()\xx = x/z
    pixel()\yy = y/z
    pixel()\couleur = 130+Random(Random(10000))
  Next
  
  ;********************************************
  
  
  nbb+1
  
  hdc=StartDrawing(ScreenOutput()) ;*********************** S T A R T
                                   ;LineXY(30,0,100,100,RGB(255,255,0))
  
  ;********** A partir d'ici, tout est "LinkedList"
  
  ForEach pixel.pixel() ; tant qu'il y a des etoiles on les affiches
    
    With pixel() 
      
      
      x=\centrex+\posx+\xx+Cos(nbb/380)*Cos(nbb/200)*200
      y=\centrey+\posy+\yy+Sin(nbb/240)*Cos(nbb/200)*150
      \xx*(1+vitessex*2)
      \yy*(1+vitessey*2)
      
      If x>ddw-2 Or x<1 Or y>ddh-2 Or y<1
        DeleteElement(pixel()) ; on la tue
        
      Else ; sinon 
        
        \couleur*(1+vitessex)
        If \couleur>65535
          \couleur=65535
        EndIf
        
        If \couleur<32768
          rvb=\couleur/129
          Plot(x,y,RGB(rvb,rvb,rvb)) ; on l'affiche
        Else
          Plot(x,y,RGB(255,255,255)) ; on l'affiche
          rvb=(\couleur-32768)/130
          Plot(x+1,y,RGB(rvb,rvb,rvb)) ; on l'affiche
          Plot(x-1,y,RGB(rvb,rvb,rvb)) ; on l'affiche
          Plot(x,y+1,RGB(rvb,rvb,rvb)) ; on l'affiche
          Plot(x,y-1,RGB(rvb,rvb,rvb)) ; on l'affiche
          rvb/2
          Plot(x+1,y+1,RGB(rvb,rvb,rvb)) ; on l'affiche
          Plot(x-1,y-1,RGB(rvb,rvb,rvb)) ; on l'affiche
          Plot(x-1,y+1,RGB(rvb,rvb,rvb)) ; on l'affiche
          Plot(x+1,y-1,RGB(rvb,rvb,rvb)) ; on l'affiche
        EndIf
      EndIf
    EndWith
  Next ; ce "foreach:next" s'addapte donc toujours au vrai nombre d'etoiles
  
  r=30
  rgb=5
  rgb2=0
  rr.f=1.005
  
  Repeat
    cmb=0
    
    xxx+1.05
    yyy+2.3
    xxx2+1.5
    yyy2+2.1
    
    xxxx=Cos(Radian(xxx))*(ddw/5)+Cos(Radian(xxx2))*(ddw/5)
    yyyy=Sin(Radian(yyy))*(ddh/5)+Cos(Radian(yyy2))*(ddh/5)
    
    For u=0 To 355 Step 10
      
      x=Cos(Radian(u)+rota)*r
      y=Sin(Radian(u)+rota)*r
      
      ddw4=ddw/2+x+xxxx
      ddh4=ddh/2+y+yyyy
      xxx+0.1
      yyy+0.05
      
      If ddw4>0 And ddw4<ddw-2 And ddh4>0 And ddh4<ddh-2
        Plot(ddw4,ddh4,RGB(rgb,rgb,rgb))
        If rgb2>0
          Plot(ddw4+1,ddh4+1,RGB(rgb2,rgb2,rgb2))
          Plot(ddw4,ddh4+1,RGB(rgb2,rgb2,rgb2))
          Plot(ddw4+1,ddh4,RGB(rgb2,rgb2,rgb2))
        EndIf  
      Else
        cmb+1    
      EndIf
      
    Next
    rgb+24
    If rgb>=255
      rgb=255
      rgb2+20
      If rgb2>=255
        rgb2=255
      EndIf
      
    EndIf
    
    rr*1.005
    r*rr
    r*1.1
    rota+2
  Until cmb>=36
  
  rota=oldrota+0.2
  oldrota=rota
  
  xxx=oldxxx+0.5
  yyy=oldyyy+0.44
  oldxxx=xxx
  oldyyy=yyy
  
  xxx2=oldxxx2+0.31
  yyy2=oldyyy2+0.41
  oldxxx2=xxx2
  oldyyy2=yyy2
  
  
  
  StopDrawing() 
  
  
  FlipBuffers() 
  
Until KeyboardPushed(#PB_Key_Escape)
End

Re: Plot tunnel

Publié : ven. 10/mai/2019 12:05
par Guillot
pas dégeux

tu lui reproche qui ?

Re: Plot tunnel

Publié : ven. 10/mai/2019 12:15
par SPH
Guillot a écrit :pas dégeux

tu lui reproche qui ?
On n'avance pas

Re: Plot tunnel

Publié : ven. 10/mai/2019 12:21
par falsam
On peut lui reprocher sa façon personnel de coder ^^ (je n'en dirais pas plus car il le sait et il ne changera pas)

Pour le reste une fois l'exécutable crée sans debug, c'est plutôt fluide et agréable à voir.

Re: Plot tunnel

Publié : ven. 10/mai/2019 15:11
par venom
Avec ou sans debug c'est fluide. Le souci je pense (après ça n’est peut être pas l'effet rechercher). C'est que les étoiles ne suivent pas bien le changement de direction du tunnel.
Je pense que sph souhaite qu'on a l'impression d'avancer dans ce dernier.

HS: par contre oui coder avec des xxx yyy oldxxx xsph. franchement sa pique les yeux :lol: :wink:

Si non joli rendu.






@++

Re: Plot tunnel

Publié : ven. 10/mai/2019 15:54
par SPH
:P

Re: Plot tunnel

Publié : ven. 10/mai/2019 16:15
par Marc56
C'est du SPH' Basic :D
Ni POO ni même procédure :!:
Si le compilateur l'autorisait, je pense qu'il y aurait des numéros de lignes et des LET A=1 :P
Du vrai Basic old school :) (c'est à dire des trucs fiables)
GWBASIC++ :mrgreen:
Mais ça marche vite et bien :!: Chapeau 8)

:wink:

Re: Plot tunnel

Publié : ven. 10/mai/2019 16:24
par falsam
Je suis étonné : Même pas un Gosub dans son code ! Comme quoi il peut s'en passer :mrgreen:

Re: Plot tunnel

Publié : ven. 10/mai/2019 16:50
par TazNormand
Salut @Tou(te)s,

@SPH : si tu veux un effet "d'avancement", m'est avis que ton "canon" à étoile devrait "suivre" le centre de ton tunnel, à l'endroit le plus éloigné de celui-ci.
ça veut dire plutôt utiliser des sprites que des "plot" pour afficher les étoiles.

Re: Plot tunnel

Publié : mer. 15/mai/2019 23:23
par crisot
Un jour faudra quand même que tu te mette à la 3D... :)

Re: Plot tunnel

Publié : mer. 15/mai/2019 23:36
par SPH
crisot a écrit :Un jour faudra quand même que tu te mette à la 3D... :)
Je suis justement en pleine conversion 8)

Re: Plot tunnel

Publié : lun. 27/mai/2019 18:45
par G-Rom
Tiens SPH, pour toi :

Code : Tout sélectionner


Structure vector3f
  x.f
  y.f
  z.f
EndStructure

Structure vector2f
  x.f
  y.f
EndStructure

Prototype Update(deltatime.f)
Prototype Render()


Structure Application  
  DesktopResolution.vector2f
  run.a
  *screenBuffer
  deltaClock.i
  deltaTime.d
  spriteID.l
EndStructure

#BUFFER_WIDTH = 640
#BUFFER_HEIGHT = 480
#BUFFER_SIZE  = #BUFFER_WIDTH * #BUFFER_HEIGHT * 4

Global demo.Application

Global Dim stars.vector3f(4000)
Global Dim circles.vector3f(40) 

Macro putPixel(x,y,color)
  If x>0 And x<#BUFFER_WIDTH And y>0 And y<#BUFFER_HEIGHT
    CopyMemory(@color,demo\screenBuffer + ((x*4) + #BUFFER_WIDTH * (y*4))  ,4)
  EndIf
EndMacro

Procedure InitializeApplication()
  InitSprite() : InitKeyboard()
  ExamineDesktops()
  demo\DesktopResolution\x = DesktopWidth(0)
  demo\DesktopResolution\y = DesktopHeight(0)
  demo\run                 = #True 
  OpenScreen(demo\DesktopResolution\x,demo\DesktopResolution\y,32,"demo",#PB_Screen_NoSynchronization)
  demo\screenBuffer = AllocateMemory(#BUFFER_SIZE)
  demo\spriteID     = CreateSprite(#PB_Any,#BUFFER_WIDTH,#BUFFER_HEIGHT)
  
  For i = 0 To 4000-1
    stars(i)\x = Random(1000)-Random(1000)
    stars(i)\y = Random(1000)-Random(1000)
    stars(i)\z = Random(1000)
  Next 
    
  For i = 0 To 40-1
    circles(i)\x = Cos( (i * 360 / 20) * #PI/180) * 100
    circles(i)\y = Sin( (i * 360 / 20) * #PI/180) * 200
    circles(i)\z = 10 + (i*10)
  Next
  
  demo\deltaClock = ElapsedMilliseconds()

EndProcedure

Procedure.a ApplicationRunning()
  ProcedureReturn demo\run
EndProcedure

Procedure ApplicationUpdate()
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    demo\run = #False 
  EndIf 
  
  demo\deltaTime  = (ElapsedMilliseconds() - demo\deltaClock) / 1000
  demo\deltaClock = ElapsedMilliseconds()
  
EndProcedure

Procedure ApplicationRender()
  ClearScreen(0) ; on efface l'écran
  FillMemory(demo\screenBuffer,#BUFFER_SIZE,0,#PB_Long) ; le buffer a pixels
  
  ; la ou on regarde
  xx.f = (#BUFFER_WIDTH/2)  + (#BUFFER_WIDTH/4) * Cos(ElapsedMilliseconds()/5000)
  yy.f = (#BUFFER_HEIGHT/2) + (#BUFFER_HEIGHT/4) * Sin(ElapsedMilliseconds()/1000)  
  
  ; etoiles
  For i = 0 To 4000-1
    x.f = ((100*stars(i)\x) / stars(i)\z) + xx
    y.f = ((100*stars(i)\y) / stars(i)\z) + yy
    factor.f = (1 - (stars(i)\z / 1000))/2
    color = RGB(155*factor,155*factor,155*factor)
    putPixel( Int(x),Int(y), color)
    stars(i)\z - 35 * demo\deltaTime
    If stars(i)\z < 0
      stars(i)\z = 1000
    EndIf 
  Next 
  
  
  ; cercles
  For i = 0 To 40-1
    x.f = ((8*circles(i)\x) / circles(i)\z)
    y.f = ((8*circles(i)\y) / circles(i)\z)

    For c = 0 To 360 Step 2
      
      If circles(i)\z > 0
        radius.f = 2000/circles(i)\z  ;-((1-(circles(i)\z / (100 + (20 * 100))))*320)
      Else
        radius.f = 0
      EndIf 

      factor.f = (radius / 1000) * 6
      
      If factor > 1
        factor = 1
      EndIf 
      If factor<0
        factor = 0
      EndIf 
      xa.f = ((x + radius * Cos(c * #PI/180)) + xx) 
      ya.f = ((y + radius * Sin(c * #PI/180)) + yy)
      color = RGB(255*factor,200*factor,150*factor)
      putPixel(Int(xa),Int(ya),color)

    Next
    circles(i)\z - 50 * demo\deltaTime
    If circles(i)\z < 0
      circles(i)\z = 10 + (40*10)
    EndIf
  Next
  
  ; copie des pixels sur le sprite PB
  StartDrawing(SpriteOutput(demo\spriteID))
  *pixels = DrawingBuffer()
  CopyMemory(demo\screenBuffer,*pixels,#BUFFER_SIZE)
  StopDrawing()
  
  ; on affiche et transforme le sprite à la taille de la résolution de l'écran
  DisplaySprite(demo\spriteID,0,0)  
  TransformSprite(demo\spriteID,0,0,demo\DesktopResolution\x,0,demo\DesktopResolution\x,demo\DesktopResolution\y,0,demo\DesktopResolution\y)

  FlipBuffers()
EndProcedure




InitializeApplication()

While ApplicationRunning()
  ApplicationUpdate()
  ApplicationRender()
Wend
pour une pseudo 3D , tu peu utilisé cette "formule" :
x' = ( FOCALE * x ) / z
y' = ( FOCALE * y ) / z
Ou "focale" , plus est proche de 0 , plus l'effet grand angle sera prononcé. quand z est < 0 , "l'objet est derrière toi".
c'est plus une technique "oldschool" que de l'utilisation de la 3D moderne.