Seite 1 von 1

Farben über Farben

Verfasst: 14.03.2008 14:59
von Jilocasin
Naja, ich weiß nicht ob der Code es so arg bringt :D
Aber ich dachte ich stell ihn einfach mal ins Forum.. Codeoptimierungen können gerne vorgenommen werden..

(Am besten ohne Debugger starten, sonst isses zu langsam -.-)

Code: Alles auswählen

Procedure.f SinP(Angle.f)
  ProcedureReturn Sin(Angle) + 1
EndProcedure

Procedure.f Cos2(Angle.f)
  ProcedureReturn Cos(Angle * 6.28)
EndProcedure


InitSprite()


OpenWindow(0, 0, 0, 600, 600, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 256, 256, 1, 0, 0)
  SetFrameRate(75)
  
CreateImage(0, 256, 256)

Global hBG = ImageID(0)
hDC = StartDrawing(ImageOutput(0))
  Global *mem = AllocateMemory(256 * 256 * 4)
  
  Global bmi.BITMAPINFO
  bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
  bmi\bmiheader\biWidth = 256
  bmi\bmiheader\biHeight = 256
  bmi\bmiheader\biPlanes = 1
  bmi\bmiheader\biBitCount = 32
  bmi\bmiheader\biCompression = #BI_RGB
StopDrawing()





Procedure Generate()
  Random1.f = SinP(ElapsedMilliseconds() / 38560) * 5 + 0.01
  Random2.f = SinP(ElapsedMilliseconds() / 24250) * 5 + 0.01
  Random3.f = SinP(ElapsedMilliseconds() / 628200) * 0.75 + 0.2
  Random4.f = SinP(ElapsedMilliseconds() / 367500) * 0.75 + 0.2
  
  
  Wave = ElapsedMilliseconds() / 50
  MixWave.f = SinP(ElapsedMilliseconds() / 5000) / 2
  ColorWaveX.f = ElapsedMilliseconds() / 3600
  ColorWaveY.f = ElapsedMilliseconds() / 3200
  
  
  *pixels.LONG = *mem + 256 * y
  For y = 255 To 0 Step -1
    YCos.f = Cos2((y + Wave) / 100)
    
    For x = 0 To 255
      Color1 = Sin(Pow(x * Random1, Random3) + Pow(y * Random2, Random4)) * 127 + 127
      Color2 =  ( Cos2((x + Wave) / 100) + Cos2((x + y) / 100) + YCos ) * 32 + 128
      
      Color = Color1 * MixWave + Color2 * (1 - MixWave)
      
      *pixels\l = RGB(Color * (Sin(x / 40 + ColorWaveX) * Sin(y / 42 + 2 - ColorWaveY) / 2 + 0.5), Color * (Sin(x / 38 + 4 - ColorWaveX) * Sin(y / 45 + ColorWaveY) / 2 + 0.5), Color * (Sin(x / 34 + 2 + ColorWaveX) * Sin(y / 23 + 4 + ColorWaveY) / 2 + 0.5))
      
      *pixels + 4
    Next
  Next
  
  hDC = StartDrawing(ImageOutput(0))
    SetDIBits_(hDC, hBG, 0, 256, *mem, bmi, #DIB_RGB_COLORS)
  StopDrawing()
EndProcedure



Repeat
  EventID = WindowEvent()
  
  Generate()
  
  ClearScreen(0)
  
  StartDrawing(ScreenOutput())
    DrawImage(ImageID(0), 0, 0)
  StopDrawing()
  
  FlipBuffers()
Until EventID = #WM_CLOSE

Verfasst: 14.03.2008 15:02
von RSBasic
@Daniel
Sieht geil aus.

Re: Farben über Farben

Verfasst: 14.03.2008 15:04
von scholly
Jilocasin hat geschrieben:Naja, ich weiß nicht ob der Code es so arg bringt :D
:allright: Taugt IMHO u.a. um Texturen zu gewinnen.

Verfasst: 14.03.2008 15:05
von Fluid Byte
Also ich finds cool! 8)

Verfasst: 14.03.2008 15:07
von STARGÅTE
jo past ja hier hin