words as images

For everything that's not in any way related to PureBasic. General chat etc...
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

words as images

Post by applePi »

such as Gravity are written like this:
Image

http://blogs.scientificamerican.com/sym ... your-eyes/
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: words as images

Post by Little John »

:lol:

Code: Select all

#FontSize = 140
#Width  = 670
#Height = 220
#Radius = 5
#Holes = 300

Define.i i, event

If OpenWindow(0, 0, 0, #Width, #Height, "Mmmhh", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) = 0
   MessageRequester("Fatal error", "Program terminated.")
   End
EndIf
If LoadFont(1, "Arial", #FontSize) = 0
   MessageRequester("Couldn't load font", "Program terminated.")
   End
EndIf

If CreateImage(0, #Width, #Height) And StartDrawing(ImageOutput(0))
   DrawingFont(FontID(1)) 
   DrawText(10, 10, "Cheese", #Yellow)
   For i = 1 To #Holes
      Circle(Random(#Width-#Radius,#Radius), Random(#Height-#Radius,#Radius), #Radius, 0) 
   Next
   StopDrawing() 
   ImageGadget(0, 0, 0, #Width, #Height, ImageID(0))
EndIf

Repeat
   event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: words as images

Post by applePi »

thats great Little John , thank you
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: words as images

Post by Demivec »

Code: Select all

#FontSize1 = 100
#FontSize2 = 90
#FontSize3 = 120
#width  = 460
#height = 250

Procedure handleError(value, msg.s)
  If value = 0: MessageRequester("Fatal error", msg): End: EndIf
EndProcedure

handleError(OpenWindow(0, 0, 0, #width, #height, "pop pop", #PB_Window_SystemMenu | #PB_Window_ScreenCentered),"Couldn't open window.")
handleError(LoadFont(1, "Arial", #FontSize1), "Couldn't load font.")
handleError(LoadFont(2, "Arial", #FontSize2), "Couldn't load font.")
handleError(LoadFont(3, "Arial", #FontSize3), "Couldn't load font.")

Define.i i, Event
If CreateImage(0, #width, #height) And StartDrawing(ImageOutput(0))
    Box(0, 0, #width, #height, RGB(231, 231, 231))
    FrontColor($000000)
    Box(0,132, #width, #height)
    Ellipse(228, 123, 200, 50, RGB(231, 231, 231))
    DrawingFont(FontID(1)) 
    DrawRotatedText(-5, 136, "b", 75)
    DrawRotatedText(50, 50, "u", 50)
    DrawRotatedText(160, 61, "b", 60)
    DrawRotatedText(220, 188, "l", 97)
    DrawRotatedText(312, 198, "s", 116)    
    DrawingFont(FontID(2)) 
    DrawRotatedText(240, 157, "e", 90)
    DrawingFont(FontID(3))
    DrawRotatedText(97, 182, "b", 94) 
  StopDrawing() 
  ImageGadget(0, 0, 0, #width, #height, ImageID(0))
EndIf

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: words as images

Post by skywalk »

Words worth a thousand pictures :wink:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: words as images

Post by Little John »

@applePi:
I thank you for this nice thread! This is really fun.

Maybe the following one is too simple. :|

Code: Select all

#FontSize = 40
#Width  = 270
#Height = 220

Define.i event

If OpenWindow(0, 0, 0, #Width, #Height, "a²+b² = c²", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) = 0
   MessageRequester("Fatal error", "Program terminated.")
   End
EndIf
If LoadFont(1, "Arial", #FontSize) = 0
   MessageRequester("Couldn't load font", "Program terminated.")
   End
EndIf

If CreateImage(0, #Width, #Height) And StartDrawing(ImageOutput(0))
   DrawingFont(FontID(1))
   DrawRotatedText( 10, 120, "P y",      60)
   DrawRotatedText(120,  20, "t h a g", -30)
   DrawRotatedText( 60, 130, "o r a s",   0)
   StopDrawing()
   ImageGadget(0, 0, 0, #Width, #Height, ImageID(0))
EndIf

Repeat
   event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: words as images

Post by Little John »

Code: Select all

#FontSize = 40
#Width  = 600
#Height = 500
#ImgWidth  = 60
#ImgHeight = 60
#MaxStep = 4
#Wind = 3

CompilerIf Not Defined(Point, #PB_Structure)
   Structure POINT
      x.l
      y.l
   EndStructure
CompilerEndIf


Procedure.i CreateBalloons (text$)
   Protected i.i, ret.i
   
   If LoadFont(1, "Arial", #FontSize) = 0
      ProcedureReturn 0   ; error
   EndIf
   
   ret = Len(text$)
   For i = 1 To ret
     CompilerIf #PB_Compiler_Version < 520
      If CreateImage(i, #ImgWidth, #ImgHeight, 32|#PB_Image_Transparent) And StartDrawing(ImageOutput(i))
     CompilerElse
      If CreateImage(i, #ImgWidth, #ImgHeight, 32, #PB_Image_Transparent) And StartDrawing(ImageOutput(i))
     CompilerEndIf
         DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
         DrawingFont(FontID(1))
         FrontColor(RGBA(Random(255),Random(255),Random(255),255))
         DrawText(0, 0, Mid(text$,i,1))
         StopDrawing()
      EndIf
   Next
     
   FreeFont(1)
   ProcedureReturn ret
EndProcedure


Procedure DrawBalloons (images.i)
   Static Dim posn.Point(0)
   Protected i.i
   
   If ArraySize(posn()) = 0
      Dim posn.Point(images)
      For i = 1 To images
         posn(i)\x = i*#ImgWidth + 10
         posn(i)\y = #Height - #FontSize*2
      Next
   Else
      For i = 1 To images
         posn(i)\x + Random(#MaxStep + #Wind) - #MaxStep/2
         posn(i)\y - Random(#MaxStep, #MaxStep/2)
      Next
   EndIf
   
   If StartDrawing(ImageOutput(0))
      Box(0, 0, #Width, #Height, 0)
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      For i = 1 To images
         DrawImage(ImageID(i), posn(i)\x, posn(i)\y)
      Next
      StopDrawing()
   EndIf
   SetGadgetState(0, ImageID(0))
EndProcedure


Define count.i

If OpenWindow(0, 0, 0, #Width, #Height, "", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) = 0
   MessageRequester("Fatal error", "Program terminated.")
   End
EndIf
count = CreateBalloons("balloons")
If count = 0
   MessageRequester("Couldn't create balloons", "Program terminated.")
   End
EndIf
CreateImage(0, #Width, #Height)
ImageGadget(0, 0, 0, #Width, #Height, 0)

AddWindowTimer(0, 0, 50)

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_Timer
         DrawBalloons(count)
         
      Case #PB_Event_CloseWindow
         Break
   EndSelect
ForEver
Last edited by Little John on Sat Jun 29, 2013 2:11 pm, edited 3 times in total.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: words as images

Post by davido »

Hi Little John,

Had an image error regarding depth.

I tried changing line 19 to: CreateImage(i, #ImgWidth, #ImgHeight, 32) And StartDrawing(ImageOutput(i))
It then appeared to work, with the 'BALLOON' vanishing through the top of the window!

I'm using PB5.20B4-64 bit on Windows 7-64 bit.

Thanks for all the nice demos. :D
DE AA EB
GoodNPlenty
Enthusiast
Enthusiast
Posts: 112
Joined: Wed May 13, 2009 8:38 am
Location: Arizona, USA

Re: words as images

Post by GoodNPlenty »

davido wrote:Hi Little John,
Had an image error regarding depth.

I tried changing line 19 to: CreateImage(i, #ImgWidth, #ImgHeight, 32) And StartDrawing(ImageOutput(i))
It then appeared to work, with the 'BALLOON' vanishing through the top of the window!
It should be

Code: Select all

CreateImage(i, #ImgWidth, #ImgHeight, 32, #PB_Image_Transparent
instead of

Code: Select all

CreateImage(i, #ImgWidth, #ImgHeight, 32|#PB_Image_Transparent
if you use

Code: Select all

CreateImage(i, #ImgWidth, #ImgHeight, 32)
you will have blocked letters.

This should be correct for line 19.

Code: Select all

 If CreateImage(i, #ImgWidth, #ImgHeight, 32, #PB_Image_Transparent) And StartDrawing(ImageOutput(i))
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: words as images

Post by Little John »

Hi davido,

thank you for reporting the bug!
The code was for the old fashioned ;-) PB version 5.11.
I've corrected it now, thanks.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2148
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: words as images

Post by Andre »

Nice effects! :D

@Little John: for your last CreateBalloons() example there is needed the following additional code on MacOS (and probably Linux) to work also with this PB versions:

Code: Select all

If Not Defined(Point, #PB_Structure)
  Structure POINT
    x.i
    y.i
  EndStructure
EndIf
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: words as images

Post by Little John »

Many thanks, André !
Code corrected.
Little John
Addict
Addict
Posts: 4805
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: words as images

Post by Little John »

This is really a good field for kidding around. :D

Code: Select all

#FontSize = 40
#Width  = 400
#Height = 200
#ImgWidth  = 180
#ImgHeight =  60
#Step = 4
#Edge = 180
#Falling = 40


Procedure CreateWordImage (text$)
   If LoadFont(1, "Arial", #FontSize)
      If CreateImage(1, #ImgWidth, #ImgHeight) And StartDrawing(ImageOutput(1))
         DrawingFont(FontID(1))
         DrawText(0, 0, text$)
         StopDrawing()
         FreeFont(1)
         ProcedureReturn 1  ; success
      EndIf
      FreeFont(1)
   EndIf
   
   ProcedureReturn 0        ; error
EndProcedure


Procedure DrawWordImage ()
   Static x.i = 0
   Static y.i = #Height - #FontSize*2
   Static stepp = #Step
   
   If x < #Edge
      x + #Step
      y + stepp
      stepp = -stepp
   Else
      y + #Falling
   EndIf
   
   If StartDrawing(ImageOutput(0))
      Box(0, 0, #Width, #Height, 0)
      DrawImage(ImageID(1), x, y)
      StopDrawing()
   EndIf
   SetGadgetState(0, ImageID(0))
EndProcedure


If OpenWindow(0, 0, 0, #Width, #Height, "Oops!", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) = 0
   MessageRequester("Fatal error", "Program terminated.")
   End
EndIf
If CreateWordImage("trapped") = 0
   MessageRequester("Couldn't create image of the word", "Program terminated.")
   End
EndIf
CreateImage(0, #Width, #Height)
ImageGadget(0, 0, 0, #Width, #Height, 0)

AddWindowTimer(0, 0, 50)

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_Timer
         DrawWordImage()
         
      Case #PB_Event_CloseWindow
         Break
   EndSelect
ForEver
Post Reply