Page 1 of 1

Create Fancy Image

Posted: Sun Feb 21, 2010 8:00 pm
by eddy
Here is a little image generator:

Code: Select all

EnableExplicit
Procedure CreateFancyImage(ID, w, h, mode=0)
   Protected img, x, y, c
   Protected result=CreateImage(ID, w, h, 32)
   If ID=#PB_Any : ID=result : EndIf
   StartDrawing(ImageOutput(ID))
      For y=0 To OutputHeight()-1
         For x=0 To OutputWidth()-1
            Select mode
               Case 0
                  ;// chain
                  c=Int(x*1.4)%200 ! Int(y*1.3)%233
               Case 1
                  ;// wall
                  c=Int(x*2)%30 | ~Int(y*1.3)%233 & $FF
               Case 2
                  ;// perspective
                  c=x%(y+1)
               Case 3
                  ;// pavement
                  c=x ! y
               Case 4
                  ;// noise screen
                  c=(x & $FF)*(y & $FF)
               Case 5
                  ;// castle
                  c=x-(y ! x & $FFFF)
               Case 6
                  ;// strips
                  c=y+(x % 100)
               Case 7
                  ;// strips hashed
                  c=(y+(x % 100) & $FF) ! ((x+y) & $FF)
               Case 8
                  ;// Left Arrow
                  Define xx=x%512
                  Define yy=y%512
                  c=Abs(xx-Abs(yy-256))
               Default
                  MessageRequester("CreateFancyImage", "mode "+Str(mode)+" not defined!")
                  End
            EndSelect
            Plot(x, y, RGB(c, 0, c/3))
         Next
      Next
   StopDrawing()
   ProcedureReturn result
EndProcedure
DisableExplicit

; ********************
; EXAMPLE @ eddy
; ********************

#imgsize=1024
CreateFancyImage(10, #imgsize, #imgsize, 0)
#w=800
#h=600
OpenWindow(0, 0, 0, #w, #h, "Click to switch image mode", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ScrollAreaGadget(1, 0, 0, #w, #h, ImageWidth(10), ImageHeight(10))
ImageGadget(0, 0, 0, 0, 0, ImageID(10))
CloseGadgetList()
Repeat
   e=WaitWindowEvent()
   If e=#PB_Event_Gadget
      mode=(mode+1)%9
      CreateFancyImage(10, #imgsize, #imgsize, mode)
      SetGadgetState(0, ImageID(10))
   EndIf
Until e=#PB_Event_CloseWindow

Re: Create Fancy Image

Posted: Sun Feb 21, 2010 8:52 pm
by eddy
oops ... I fixed an infinite loop in the mode 8 :shock:

Re: Create Fancy Image

Posted: Mon Feb 22, 2010 12:27 pm
by Kwai chang caine
Nice 8)

Re: Create Fancy Image

Posted: Mon Feb 22, 2010 6:02 pm
by Seymour Clufley
That's really neat. Cheers eddy. :)

Re: Create Fancy Image

Posted: Mon Feb 22, 2010 11:47 pm
by Spaceman Spiff
This is very FRACTALiffic! Thank you for the wonderful code!

I noticed you were working on a bitmap font display... is this for a 2D game engine?

8)

Re: Create Fancy Image

Posted: Tue Feb 23, 2010 2:22 am
by eddy
Spaceman Spiff wrote:This is very FRACTALiffic! Thank you for the wonderful code!

I noticed you were working on a bitmap font display... is this for a 2D game engine?

8)
yes this one : http://www.purebasic.fr/english/viewtop ... 12&t=38447