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

Share your advanced PureBasic knowledge/code with the community.
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

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

Post 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]
Last edited by Nituvious on Tue Jan 26, 2010 6:16 pm, edited 2 times in total.
▓▓▓▓▓▒▒▒▒▒░░░░░
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

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

Post 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?
jamba
Enthusiast
Enthusiast
Posts: 144
Joined: Fri Jan 15, 2010 2:03 pm
Location: Triad, NC
Contact:

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

Post 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
-Jon

Fedora user
But I work with Win7
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

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

Post 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. :(
▓▓▓▓▓▒▒▒▒▒░░░░░
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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).
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

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

Post 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.
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

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

Post 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?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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:
User avatar
JackWebb
Enthusiast
Enthusiast
Posts: 109
Joined: Wed Dec 16, 2009 1:42 pm
Location: Tampa Florida

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

Post 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
Make everything as simple as possible, but not simpler. ~Albert Einstein
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

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

Post 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
▓▓▓▓▓▒▒▒▒▒░░░░░
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

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

Post 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
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Post Reply