Page 1 of 3

PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 12:35 pm
by Nituvious
Well, while reading over Kale's book I come up with a community project idea for everyone to chip in on.
The idea stems from the internet forum phenomenon where forum goers submit tidbits based on rules provided in the initial post. This, combined in a programming forum would be a great source of learning and the opportunity to be apart of a nifty community project!

Rules and Regulations:
  • 1] Each user is limited 10 lines of code of unlimited length. You may make additional code submissions after two other users have contributed their code after yours. You do not have to use all 10 lines of code per submission.
    2] Each line should not contain more than one line separation(ex S$="yes" : B$="no"). This does not count against your 10 lines. Comments do not count as lines.
    3] All PureBasic functions, keywords etc are allowed(Even Ogre).
    4] Please comment code, since this is project is to learn from each other why leave your code without comments?
    5] No libraries or includes are allowed.
    6] You may change, edit and improve upon(or correct) a previous posters code submission for your "turn". Each line change/removed counts as one of your lines.
    7] Whenever you post a submission, you must post your code with the above posters code. So we don't have any rogue coders running lose! :mrgreen:
    8] And finally, the project must compile after each new code submission! As long as the project compiles, then your code qualifies! Other users may finish your code, or you may finish it once you're able to post again!

Now, to get it started!

Code: Select all

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;*********************************************

Enumeration
     #MainWindow = 0
     #TextGadgetOne
EndEnumeration

iWidth.l=300 : iHeight.l=200 ; Maybe someone can think up something cool to do with this :)
OpenWindow(#MainWindow,0,0,iWidth,iHeight,"PB Community: Evolving code",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#TextGadgetOne,70,85,200,20,"The PureBasic Community rocks!") ; It's true!

Repeat
     EventID = WaitWindowEvent(20)
Until EventID = #PB_Event_CloseWindow
[/size]

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 1:17 pm
by UserOfPure
Sorry, I don't get what you're trying to say. Am I supposed to modify your code into something smaller, or what?

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 1:40 pm
by jamba
UserOfPure wrote:Sorry, I don't get what you're trying to say. Am I supposed to modify your code into something smaller, or what?
I think the point is to add your own code so that it grows into something complex

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 3:24 pm
by Nituvious
You take what code is above, add code to it and pass it along to other users to build on it. I thought it was clear, oh well. :(

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 5:04 pm
by Trond
I don't think it's a good idea to allow images and sounds, it will just make it a hazzle.
Edit: If I remove one of your lines, how does that count for me? Do I get an extra line, nothing happens, or does it count towards one of my ten?

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 5:18 pm
by Trond
My contribution:

Code: Select all

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;*********************************************

Enumeration
     #MainWindow = 0
     #TextGadgetOne
EndEnumeration

iWidth.l=300 : iHeight.l=200 ; Maybe someone can think up something cool to do with this :)
OpenWindow(#MainWindow,0,0,iWidth,iHeight,"PB Community: Evolving code",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

CreateImage(0, iWidth, iHeight)
LoadFont(0, "Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)
StartDrawing(ImageOutput(0)) : Box(0, 0, iWidth, iHeight, 0)
  T.s = "The PureBasic Community rocks!" : DrawingFont(FontID(0))
  For I = Len(T) To 0 Step -1
    ci = 255-(I * 255./Len(T)) : c = RGB(ci, 255-ci, ci)
    DrawText(10, iHeight/2-20, Left(T, I), c, 0)
  Next
StopDrawing()
ImageGadget(#TextGadgetOne, 0, 0, 0, 0, ImageID(0))

Repeat
     EventID = WaitWindowEvent(20)
Until EventID = #PB_Event_CloseWindow
PS. PB 4.41 has some errors when drawing italic text, you'll see it if you change the colours to random (the gradient disguises the problem).

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 5:48 pm
by Nituvious
Trond wrote:I don't think it's a good idea to allow images and sounds, it will just make it a hazzle.
Edit: If I remove one of your lines, how does that count for me? Do I get an extra line, nothing happens, or does it count towards one of my ten?
Yes, it counts as one of your lines, and thanks for getting it going! :) Should I remove the image/sounds rule?
Okay, I edited the first post.

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 6:35 pm
by blueznl

Code: Select all

StartDrawing(ImageOutput(0)) : Box(0, 0, iWidth, iHeight, 0)
T.s = "The PureBasic Community rocks!" : DrawingFont(FontID(0))
Oh gawd, please don't use colons unless they make code EASIER to read! I mean, putting multiple statements on a single line as above is just to avoid the 'n' lines limit, isn't it?

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 8:35 pm
by Trond
I mean, putting multiple statements on a single line as above is just to avoid the 'n' lines limit, isn't it?
Of course. I never knew they had any other use. :mrgreen:

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 9:48 pm
by JackWebb
I get it, kind of like a story board. Nice idea, I think I got all the rules right.. Does this count?

Nice work as always by Trond.

Jack

Code: Select all

EnableExplicit

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;*********************************************

Enumeration
  #MainWindow
  #TextGadgetOne
EndEnumeration

Define iWidth.l  = 300
Define iHeight.l = 200 ; Maybe someone can think up something cool to do with this :)
Define T.s, I, ci, c
Define EventID

OpenWindow(#MainWindow, 0, 0, iWidth, iHeight, "PB Community: Evolving code", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CreateImage(0, iWidth, iHeight)
LoadFont(0, "Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)
StartDrawing(ImageOutput(0))
Box(0, 0, iWidth, iHeight, 0)

T.s = "The PureBasic Community rocks!"
DrawingFont(FontID(0))

For I = Len(T.s) To 0 Step - 1
  ci = 255 - (I * 255.) / Len(T.s)
  c = RGB(ci, 255 - ci, ci)
  DrawText(10, (iHeight / 2) - 20, Left(T.s, I), c, 0)
Next I

StopDrawing()
ImageGadget(#TextGadgetOne, 0, 0, 0, 0, ImageID(0))

Repeat
  EventID = WaitWindowEvent(20)
Until EventID = #PB_Event_CloseWindow

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 10:39 pm
by Nituvious
Since there are two contributions since my last post, I can make another contribution :mrgreen:

I think I added 8 lines and edited one.

Code: Select all

EnableExplicit

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;*********************************************

Enumeration
  #MainWindow
  #TextGadgetOne
EndEnumeration

Define iWidth.l  = 300
Define iHeight.l = 200 ; Maybe someone can think up something cool to do with this :)
Define T.s, I, ci, c
Define EventID
Define TextX.f = 0 : Define TextY.f = 0
OpenWindow(#MainWindow, 0, 0, iWidth, iHeight, "PB Community: Evolving code", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#MainWindow,RGB(0,0,0)) ; Give us a black background for our moving text
CreateImage(0, iWidth, iHeight)
LoadFont(0, "Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)
StartDrawing(ImageOutput(0))
Box(0, 0, iWidth, iHeight, 0)

T.s = "The PureBasic Community rocks!"
DrawingFont(FontID(0))

For I = Len(T.s) To 0 Step - 1
  ci = 255 - (I * 255.) / Len(T.s)
  c = RGB(ci, 255 - ci, ci)
  DrawText(10, (iHeight / 2) - 20, Left(T.s, I), c, 0)
Next I

StopDrawing()
ImageGadget(#TextGadgetOne, 0, 0, 0, 0, ImageID(0))

Repeat
     ; Silly Scrolling Marquee thingy
     If TextY.f > 130    ; Check position...
          TextY=-100     ; Set it a little out of bounds to make an illusion of a loop around
     EndIf               ; Endif?
     TextY+0.3           ; The speed of the "scrolling" effect
     ResizeGadget(#TextGadgetOne,TextX,TextY,1000,100) ; Self Explanatory :)
     Delay(20) ; A delay, makes the scroll a little more purty! hehe
     EventID = WaitWindowEvent(20)
Until EventID = #PB_Event_CloseWindow

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 11:02 pm
by c4s
Some code cleaning ;)

Code: Select all

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;*********************************************



EnableExplicit

Enumeration
	#Font
	#Image

  #WindowMain
  #GadgetImage
EndEnumeration

Define iWidth.l = 300
Define iHeight.l = 200 ; Maybe someone can think up something cool to do with this :)
Define Text.s = "The PureBasic Community rocks!"
Define TextX.f, TextY.f
Define I, ColorI, Color
Define EventID



LoadFont(#Font, "Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)

If CreateImage(#Image, iWidth, iHeight)
	StartDrawing(ImageOutput(#Image))
		DrawingFont(FontID(#Font))

		Box(0, 0, iWidth, iHeight, RGB(0, 0, 0))

		For I = Len(Text) To 0 Step -1
			ColorI = 255 - (I * 255) / Len(Text)
			Color = RGB(ColorI, 255 - ColorI, ColorI)
			DrawText(10, (iHeight / 2) - 20, Left(Text, I), Color, RGB(0, 0, 0))
		Next
	StopDrawing()
EndIf


OpenWindow(#WindowMain, #PB_Ignore, #PB_Ignore, iWidth, iHeight, "PB Community: Evolving code", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#WindowMain, RGB(0, 0, 0)) ; Give us a black background for our moving text

ImageGadget(#GadgetImage, 0, 0, 0, 0, ImageID(#Image))


Repeat
	; Silly Scrolling Marquee thingy
	If TextY > 130   ; Check position...
		TextY = -100   ; Set it a little out of bounds to make an illusion of a loop around
	Else
		TextY + 0.3    ; The speed of the "scrolling" effect
	EndIf
	ResizeGadget(#GadgetImage, #PB_Ignore, TextY, #PB_Ignore, #PB_Ignore)

	Delay(20)
	EventID = WaitWindowEvent(20)
Until EventID = #PB_Event_CloseWindow

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 11:35 pm
by Trond
Can we have a rule that the code should be indented by two?
Edit: c4s, you changed WAY more than ten lines with your cleanup.

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Tue Jan 26, 2010 11:56 pm
by Trond
I changed the scrolling effect to not bug at the start (I don't know why the old code would do that, bug this one certainly doesn't.)

Code: Select all

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;*********************************************



; EnableExplicit

Enumeration
   #Font
   #Image

  #WindowMain
  #GadgetImage
EndEnumeration

Define iWidth.l = 300
Define iHeight.l = 200 ; Maybe someone can think up something cool to do with this :)
Define Text.s = "The PureBasic Community rocks!"
Define TextX.f, TextY.f
Define I, ColorI, Color
Define EventID



LoadFont(#Font, "Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)

If CreateImage(#Image, iWidth, iHeight)
   StartDrawing(ImageOutput(#Image))
      DrawingFont(FontID(#Font))

      Box(0, 0, iWidth, iHeight, RGB(0, 0, 0))

      For I = Len(Text) To 0 Step -1
         ColorI = 255 - (I * 255) / Len(Text)
         Color = RGB(ColorI, 255 - ColorI, ColorI)
         DrawText(10, (iHeight / 2) - 20, Left(Text, I), Color, RGB(0, 0, 0))
      Next
   StopDrawing()
EndIf


OpenWindow(#WindowMain, #PB_Ignore, #PB_Ignore, iWidth, iHeight, "PB Community: Evolving code", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#WindowMain, RGB(0, 0, 0)) ; Give us a black background for our moving text

ImageGadget(#GadgetImage, 0, 0, 0, 0, ImageID(#Image))


Repeat
   ; Silly Scrolling Marquee thingy
  EventID = WaitWindowEvent(1)
  If ElapsedMilliseconds() > prevtickcount+10
    prevtickcount = ElapsedMilliseconds()
    y.i = (GetTickCount_() / 30) % (iHeight+40) ; 30 is the inverse speed of the scrolling effect
    ResizeGadget(#GadgetImage, #PB_Ignore, -iHeight/2-20+y, #PB_Ignore, #PB_Ignore)
  EndIf
  
Until EventID = #PB_Event_CloseWindow

Re: PureBasic Community: Evolving Code -- [Atleast read it :)]

Posted: Wed Jan 27, 2010 2:18 am
by citystate
Thought it might be nice to keep track of all the changes in the header comments - plus, my change: color cycling of the text (untested, but I think it should work :P )

Code: Select all

;*********************************************
; PureBasic Community: Evolving code
;    January 26, 2010
;    Nituvious - initial seed
;    Trond - changed textgadget to imagegadget
;    JackWebb - cleanup
;    Nituvious - scrolls the text
;    c4s - cleanup
;    Trond - bug fix
;    citystate - color cycling
;*********************************************

; EnableExplicit

Enumeration
  #Font
  #Image
  #WindowMain
  #GadgetImage
EndEnumeration

Define iWidth.l = 300
Define iHeight.l = 200 ; Maybe someone can think up something cool to do with this :)
Define Text.s = "The PureBasic Community rocks!"
Define TextX.f, TextY.f
Define I, ColorI, Color, count
Define EventID



LoadFont(#Font, "Verdana", 11, #PB_Font_Bold | #PB_Font_Italic)

If CreateImage(#Image, iWidth, iHeight)
   StartDrawing(ImageOutput(#Image))
      DrawingFont(FontID(#Font))

      Box(0, 0, iWidth, iHeight, RGB(0, 0, 0))

      For I = Len(Text) To 0 Step -1
         ColorI = 255 - (I * 255) / Len(Text)
         Color = RGB(ColorI, 255 - ColorI, ColorI)
         DrawText(10, (iHeight / 2) - 20, Left(Text, I), Color, RGB(0, 0, 0))
      Next
   StopDrawing()
EndIf


OpenWindow(#WindowMain, #PB_Ignore, #PB_Ignore, iWidth, iHeight, "PB Community: Evolving code", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#WindowMain, RGB(0, 0, 0)) ; Give us a black background for our moving text

ImageGadget(#GadgetImage, 0, 0, 0, 0, ImageID(#Image))


Repeat
; cycle the colors
   StartDrawing(ImageOutput(#Image))
      DrawingFont(FontID(#Font))
      Box(0, 0, iWidth, iHeight, RGB(0, 0, 0))
      For I = Len(Text) To 0 Step -1
         (ColorI = 255 - ((I + count) * 255) / Len(Text))%256
         Color = RGB(ColorI, 255 - ColorI, ColorI)
         DrawText(10, (iHeight / 2) - 20, Left(Text, I), Color, RGB(0, 0, 0))
      Next: count+1
   StopDrawing(): SetGadgetState(#GadgetImage,ImageId(#Image))
 

   ; Silly Scrolling Marquee thingy
  EventID = WaitWindowEvent(1)
  If ElapsedMilliseconds() > prevtickcount+10
    prevtickcount = ElapsedMilliseconds()
    y.i = (GetTickCount_() / 30) % (iHeight+40) ; 30 is the inverse speed of the scrolling effect
    ResizeGadget(#GadgetImage, #PB_Ignore, -iHeight/2-20+y, #PB_Ignore, #PB_Ignore)
  EndIf
 
Until EventID = #PB_Event_CloseWindow