Create Fancy Image

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Create Fancy Image

Post 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
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Create Fancy Image

Post by eddy »

oops ... I fixed an infinite loop in the mode 8 :shock:
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create Fancy Image

Post by Kwai chang caine »

Nice 8)
ImageThe happiness is a road...
Not a destination
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Create Fancy Image

Post by Seymour Clufley »

That's really neat. Cheers eddy. :)
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Spaceman Spiff
User
User
Posts: 11
Joined: Mon Feb 15, 2010 9:13 pm

Re: Create Fancy Image

Post 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)
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Create Fancy Image

Post 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
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply