; ParticleColor Example
; ---------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6
CameraClsColor camera,8,12,24

floor=CreatePlane()
EntityColor floor,30,34,44

; A torch flame whose colours fade over each particle's lifetime
emitter=CreateParticleEmitter(800)
PositionEntity emitter,0,0.5,0
ParticleEmissionRate emitter,150
ParticleLifetime emitter,1,1.8
ParticleVelocity emitter,0,2,0,0.4,0.4,0.4
ParticleSize emitter,0.15,0.03,0.2
EntityBlend emitter,3

; Fire: bright yellow fading to transparent red
ParticleColor emitter,255,220,120,1,255,60,0,0
scheme$="1 fire"

While Not KeyDown(1)

    ; Keys 1-3 pick a start/end colour scheme (RGB 0-255, alpha 0-1)
    If KeyHit(2)
        ParticleColor emitter,255,220,120,1,255,60,0,0
        scheme$="1 fire (255,220,120,1 -> 255,60,0,0)"
    EndIf
    If KeyHit(3)
        ParticleColor emitter,80,160,255,1,255,80,200,0
        scheme$="2 magic (80,160,255,1 -> 255,80,200,0)"
    EndIf
    If KeyHit(4)
        ParticleColor emitter,60,255,80,1,255,255,60,0
        scheme$="3 toxic (60,255,80,1 -> 255,255,60,0)"
    EndIf

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    ; UpdateWorld also advances the particle simulation
    UpdateWorld
    RenderWorld

    Text 0,0,"Arrow keys: move camera   1/2/3: colour scheme   Esc: exit"
    Text 0,20,"ParticleColor scheme: "+scheme$

    Flip

Wend

End
