PurePunch contest #1

Share your advanced PureBasic knowledge/code with the community.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

liam wrote:wow, i cant believe you can do so much with such little code in PB!
you guys are sick! :shock:
Just try! You'll see it's not so difficult :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Awesome thread :o :!:
Please make it sticky :)

I hope to add my bits soon 8)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Psychophanta wrote:Awesome thread :o :!:
Please make it sticky :)

I hope to add my bits soon 8)
Hope too :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Plasma, based in an example from PB team, but arranged by me in 2 important aspects:
- not to have a 'StartDrawing()-StopDrawing()' stuff inside main loop.
- not to have to flip buffers in the main loop.
Here it is:

Code: Select all

DisableDebugger:InitSprite():InitKeyboard():Dim CosTable.l(1599):Dim ColorTable.l(255):For i.w=0 To 1599:CosTable(i)=Sin(9/8*i*#PI/180.)*32+32:Next:OpenScreen(800,600,32,"Plasma") 
StartDrawing(ScreenOutput()):*Buffer=DrawingBuffer():*Buffer2=*Buffer:Pitch=DrawingBufferPitch():For i=0 To 255:ColorTable(i)=i:Next:StopDrawing():FlipBuffers() 
Repeat:ExamineKeyboard():If *Buffer2<>*Buffer:StartDrawing(ScreenOutput()):*Buffer=DrawingBuffer():*Buffer2=*Buffer:StopDrawing():EndIf
For y.l=0 To 599:pos1.l=CosTable(y+wave):*Line.long=*Buffer+Pitch*y:For x.l=0 To 799:*Line\l=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1):*Line+4:Next:Next:Wave+6:If Wave>320:Wave=0:EndIf 
Delay(16):Until KeyboardPushed(#PB_Key_Escape) 
:)
Last edited by Psychophanta on Mon Dec 01, 2008 2:51 pm, edited 1 time in total.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

I have an invalid memory address here...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

djes wrote:I have an invalid memory address here...
Damn!, strange; where? can you give me the line?
Mmm... not the line, but the command :P
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Psychophanta wrote:Plasma, based in an example from PB team, but arranged by me in 2 important aspects:
- not to have a 'StartDrawing()-StopDrawing()' stuff inside main loop.
- not to have to flip buffers in the main loop.
Sorry but that's exactly what makes it crash here :)
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Oh! here it works like a charm!
May be pure luck or what?

I really doubt any of those arrangements are the cause of a crash :roll:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Psychophanta wrote:Oh! here it works like a charm!
May be pure luck or what?

I really doubt any of those arrangements are the cause of a crash :roll:
Well, putting the StartDrawing()/DrawingBuffer() bit _inside_ the loop
works. Your modification however does not (invalid memory access).
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Just reported it in the coding questions:
http://www.purebasic.fr/english/viewtop ... 091#269091
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thanks djes
it should work now for everyone
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

In fact... no! I've modified to make it work... But I've lost your optimisation on the way :cry:

Code: Select all

InitSprite()
InitKeyboard()

If OpenScreen(800,600,32,"Plasma")=0
  Debug "Can't create screen"
  End
EndIf

StartDrawing(ScreenOutput())
If DrawingBufferPixelFormat()&(#PB_PixelFormat_32Bits_RGB|#PB_PixelFormat_32Bits_RGB)=0
  Debug "No 32 bits screen mode available"
  End
EndIf
StopDrawing()

Dim CosTable.l(1599)
Dim ColorTable.l(255)

For i.w=0 To 1599
  CosTable(i)=Sin(9/8*i*#PI/180.)*32+32
Next

If DrawingBufferPixelFormat()=#PB_PixelFormat_32Bits_RGB
  For i=0 To 255
    ColorTable(i)=i
  Next
Else
  For i=0 To 255
    ColorTable(i)=i<<16
  Next
EndIf

Repeat

  ExamineKeyboard()

  StartDrawing(ScreenOutput())
 
  *Buffer=DrawingBuffer()
  Pitch=DrawingBufferPitch()

  For y.l=0 To 599
    pos1.l=CosTable(y+wave)
    *Line.long=*Buffer
    For x.l=0 To 799
      *Line\l=ColorTable(CosTable(x+Wave)+CosTable(x+y)+pos1)
      *Line+4
    Next
    *Buffer+Pitch
  Next

  Wave+6
  If Wave>320
    Wave=0
  EndIf

  StopDrawing()

  FlipBuffers(1)

Until KeyboardPushed(#PB_Key_Escape) 

End
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Very bad, because that is the same as the example by PB Team.
So ATM nothing new. :(
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Yes :cry: ... Anyway, there's still a lot of optimisations to do :P
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Licorn horn (only with DirectX9! Else a simple worm)

Code: Select all

;Should only work with PB4.30b5

SetPriorityClass_(  GetCurrentProcess_(), #HIGH_PRIORITY_CLASS)

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf

If InitSprite3D() = 0
  MessageRequester("Error", "Sprite3D system can't be initialized correctly", 0)
  End
EndIf

If OpenScreen(640, 480, 32, "Sprite")

  CreateSprite(0, 128, 128, #PB_Sprite_Texture)
  StartDrawing(SpriteOutput(0))
  a.f = 0
  For y = 0 To 127
    For x = 0 To 127
      vx.f = x - 64
      vy.f = y - 64
      dist.f = Sqr(vx * vx + vy * vy)
      If dist = 0 : dist = 0.0001 : EndIf
      If dist < 64
        vx   = vx / dist
        vy   = vy / dist
        c = 128 + 128 * ACos(vx * vy)
        Plot(x, y, RGB(c, $55, c/2))
      EndIf
    Next x
  Next y
  StopDrawing()
  CopySprite(0, 1)

  CreateSprite3D(0, 0)

  SetFrameRate(60)
  SetRefreshRate(60)

  frame_counter = 0

  Repeat
     
    ClearScreen(RGB($55, 0, $55))
   
    If Start3D()

      RotateSprite3D(0, frame_counter * 5, 0)

      For u=0 To 255 Step 1
        x = 150 * Sin((frame_counter * 2 + u) / 50)
        DisplaySprite3D(0, 256 + x, u, 255 * Sin(u * #PI / 256))
        ZoomSprite3D(0, 64, 32 + u/2)
        RotateSprite3D(0, 5, 1)
      Next u

      Stop3D()

    EndIf
   
;    Delay(15)
    FlipBuffers(1)
    frame_counter + 1
   
    ExamineKeyboard()

  Until KeyboardPushed(#PB_Key_Escape)
 
Else
  MessageRequester("Error", "Can't open a 640*480 - 32 bit screen !", 0)
EndIf

End
Post Reply