Page 1 of 1

Can this be made to work identically using OpenScreen() ?

Posted: Sun Jun 07, 2009 12:56 am
by akj
The code below gradually reveals a picture composed purely of dots.

How can it be converted to work (with minimal changes) using OpenScreen() rather than OpenWindowedScreen() ?

The sticking point is that FlipBuffers() seems to behave differently between the two screen modes, making conversion difficult.

I would be grateful for any advice.

Code: Select all

; Ikeda Attractor  AKJ  07-Jun-09
EnableExplicit
Define xoff=300, yoff=400, scale=170
Define.d c1=0.4, c2=0.9, c3=6.0, rho=1.0
Define i, j, k
Define.d temp, sin_temp, cos_temp, xt, y, x
initsprite(): initkeyboard()
OpenWindow(0,0,0,800,600,"Ikeda Attractor",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),5,5,800,600,0,0,0)
;!!! OpenScreen(800, 600, 32, "Ikeda Attractor")
ClearScreen(#Yellow)
StartDrawing(ScreenOutput())
x = 0.1: y= 0.1
For i = 0 To 300000
  temp = c1 - c3 / (1.0 + x * x + y * y)
  sin_temp = Sin(temp)
  cos_temp = Cos(temp)
  xt = rho + c2 * (x * cos_temp - y * sin_temp)
  y = c2 * (x * sin_temp + y * cos_temp)
  x = xt
  j = x * scale + xoff
  k = y * scale + yoff
  Plot(j, k, #Blue)
  If i%500=0
    StopDrawing(): FlipBuffers(): StartDrawing(ScreenOutput())
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_Escape): Break: EndIf
  EndIf
Next i
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10,10, "Press ESC to exit") ; Let user know the drawing is finished
StopDrawing()
FlipBuffers()
Repeat: ExamineKeyboard(): Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
End

Posted: Sun Jun 07, 2009 2:19 am
by SCRJ
You could render the stuff on a sprite instead on the screen...like this:

Code: Select all

; Ikeda Attractor  AKJ  07-Jun-09
EnableExplicit
Define xoff=300, yoff=400, scale=170
Define.d c1=0.4, c2=0.9, c3=6.0, rho=1.0
Define i, j, k
Define.d temp, sin_temp, cos_temp, xt, y, x
InitSprite(): InitKeyboard()

;OpenWindow(0,0,0,800,600,"Ikeda Attractor",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered) 
;OpenWindowedScreen(WindowID(0),5,5,800,600,0,0,0)

OpenScreen(800, 600, 32, "Ikeda Attractor")

ClearScreen(#Yellow)

CreateSprite(0, 800, 600)
StartDrawing(SpriteOutput(0))
  x = 0.1: y= 0.1
  For i = 0 To 300000
    temp = c1 - c3 / (1.0 + x * x + y * y)
    sin_temp = Sin(temp)
    cos_temp = Cos(temp)
    xt = rho + c2 * (x * cos_temp - y * sin_temp)
    y = c2 * (x * sin_temp + y * cos_temp)
    x = xt
    j = x * scale + xoff
    k = y * scale + yoff
    Plot(j, k, #Blue)
    If i%500=0
    StopDrawing()
    DisplaySprite(0, 0, 0)
    FlipBuffers()
    ;WindowEvent()
    StartDrawing(SpriteOutput(0))
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Escape)
        Break
      EndIf
    EndIf
  Next i
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(10,10, "Press ESC to exit") ; Let user know the drawing is finished
StopDrawing()


Repeat
  ;WindowEvent()
  
  ExamineKeyboard()
  
  DisplaySprite(0, 0, 0)
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape)

CloseScreen()
End

Posted: Mon Jun 08, 2009 8:38 am
by Trond
Replace FlipBuffers() with FlipBuffers(#PB_Screen_NoSynchronization) and it should behave the same in windowed and fullscreen mode if I remember correctly.

Posted: Mon Jun 08, 2009 9:48 am
by djes
You have to work with both the buffers. Try this :

Code: Select all

; Ikeda Attractor  AKJ  07-Jun-09
EnableExplicit
Define xoff=300, yoff=400, scale=170
Define.d c1=0.4, c2=0.9, c3=6.0, rho=1.0
Define i, j, k, db, u
Define.d temp, sin_temp, cos_temp, xt, y, x, ox, oy
InitSprite(): InitKeyboard()
;OpenWindow(0,0,0,800,600,"Ikeda Attractor",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
;OpenWindowedScreen(WindowID(0),5,5,800,600,0,0,0)
OpenScreen(800, 600, 32, "Ikeda Attractor")

ClearScreen(#Yellow)
FlipBuffers()
ClearScreen(#Yellow)

x = 0.1: y= 0.1
i=0 : u=0
db = 0

Repeat

  ExamineKeyboard()

  StartDrawing(ScreenOutput())

  DrawingMode(#PB_2DDrawing_Default)

  If db = 0
    ox = x
    oy = y
  Else
    x = ox
    y = oy
  EndIf

  For i=u To u+50
    temp = c1 - c3 / (1.0 + x * x + y * y)
    sin_temp = Sin(temp)
    cos_temp = Cos(temp)
    xt = rho + c2 * (x * cos_temp - y * sin_temp)
    y = c2 * (x * sin_temp + y * cos_temp)
    x = xt
    j = x * scale + xoff
    k = y * scale + yoff
    Plot(j, k, #Blue)
  Next i

  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(10,10, "Press ESC to exit") ; Let user know the drawing is finished

  StopDrawing()

  FlipBuffers()
  db=1-db

  If db=0
    u+50
  EndIf

Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
End