Seite 1 von 1

Leuchteffekt (kreisförmig)

Verfasst: 26.06.2007 22:27
von Kekskiller
Kleine Anregung, wie man einfach und relativ fix Leuchteffekte in Kreis-Form hinbekommen kann:

Code: Alles auswählen

OpenWindow(0, 0,0, 800,600, "dot glow test", #PB_Window_ScreenCentered|#PB_Window_TitleBar|#PB_Window_SystemMenu)

Global pxsize.w ;größe eines pixels beim einzeichnen

Global h.w, w.w ;größe des leuchtradius
Global zx.l, zy.l ;counter

Global *sintable_x.float ;sinustabelle auf x
Global *sintable_y.float ;sinustabelle auf y
Global *st_x.float
Global *st_y.float

Global degstep.f ;winkel-schritt, der pro pixel beim vorberechnen der sinus-tabelle gemacht wird
Global alpha.f
Global pxcolor.l, r.c, g.c, b.c

Global event.l

;------------------------------

w = 21
h = 21
pxsize = 5
pxcolor = $ff00

;{ create table per runtime
  
  If *sintable_x > 0: FreeMemory(*sintable_x): *sintable_x = 0 :EndIf
  If *sintable_y > 0: FreeMemory(*sintable_y): *sintable_y = 0 :EndIf
  
  *sintable_x = AllocateMemory(w * SizeOf(float))
  *sintable_y = AllocateMemory(h * SizeOf(float))
  
  *st_x = *sintable_x
  degstep = #PI / (w + 1)
  For zx = 1 To w
    *st_x\f = Sin(zx * degstep) - 0.5
    *st_x + SizeOf(float)
  Next
  
  *st_y = *sintable_y
  degstep = #PI / (h + 1)
  For zy = 1 To h
    *st_y\f = Sin(zy * degstep) - 0.5
    *st_y + SizeOf(float)
  Next
  
;}

Repeat
  event = WaitWindowEvent()
  If event = #PB_Event_Repaint
  
  ;{ draw
    
    StartDrawing(WindowOutput(0))
    Box(0,0, WindowWidth(0),WindowHeight(0), $000000)
    
    *st_y = *sintable_y
    For zy = 1 To h
      
      *st_x = *sintable_x
      For zx = 1 To w
        
;         If *st_x\f > 1.0 Or *st_y\f > 1.0
        alpha = *st_x\f + *st_y\f
        
        If alpha > 0.0
          r = Red  (Point(zx,zy)) * (1.0 - alpha) + Red  (pxcolor) * alpha
          g = Green(Point(zx,zy)) * (1.0 - alpha) + Green(pxcolor) * alpha
          b = Blue (Point(zx,zy)) * (1.0 - alpha) + Blue (pxcolor) * alpha
          Box(zx*pxsize,zy*pxsize,pxsize,pxsize, r + g << 8 + b << 16)
        EndIf
        
        *st_x + SizeOf(float)
      Next
      
      *st_y + SizeOf(float)
    Next
    
    StopDrawing()
    
  ;}
  
  EndIf
Until event = #PB_Event_CloseWindow
- CPU-arme Ermittlung vom Alpha-Wert
- lässt sich leicht abwandeln und für andere Zwecke missbrauchen
- Leicht einzubinden

:allright:

Nagut, ich geb zu dass der Kreis nicht ganz rund ist, aber bei Leuchteffekten ist das ja relativ unwichtig, wie ich finde :mrgreen: ...

Verfasst: 07.10.2007 13:45
von Max_der_Held
wow.. schöner effekt :mrgreen:
vor allem, wenn ma pxsize auf 1 und w , h auf 600 setzt setzt
:allright:

( würds mit directdrawing schnellergehn? oder gehts dann nur beim screen...)