Advantages:
Same texture maked two times are diferent.
Small code to generate big textures.
Antialias for all elements.
Texture and normal map are generated.
Admit texts, boxes, circles, ellipses, blocks, stones and more.
PB native (must work in Linux and mac)
Low price 0.0€

No sugar content..

Disvantages:
Need speedy pc if you generate many textures.
Watch examples to get an idea how work it.
I hope you enjoy this code.
If you improve this, please share the code.
Code: Select all
; Vectorial texture and normal map creator [minimy2025]
Procedure showImage(img)
If IsImage(img)
SetWindowColor(OpenWindow(#PB_Any,0,0,ImageWidth(img),ImageHeight(img),"Test imagen: "+Str(img)) , $ff0000)
ImageGadget(#PB_Any,0,0,ImageWidth(img),ImageHeight(img),ImageID(img))
EndIf
EndProcedure
;{ data
Procedure ImgToNormalMap(image, strength.f=1.0, invertX.b=#False, invertY.b=#False)
Protected.f deltaX,deltaY
Protected.l gleft,gRight,gUp,gDown
Protected.c x,y
Protected.a r,g,b
Protected normalMapID
Protected.c width = ImageWidth(image)
Protected.c height = ImageHeight(image)
Protected.f nx,ny,nz,length
Protected.l Dim px(width,height)
StartDrawing(ImageOutput(image))
For y = 1 To height - 2
For x = 1 To width - 2
If invertX
gleft= Point(x+1,y): gRight= Point(x-1,y)
Else
gleft= Point(x-1,y): gRight= Point(x+1,y)
EndIf
deltaX = ((Red(gRight) + Green(gRight) + Blue(gRight)) / 3.0) - ((Red(gLeft) + Green(gLeft) + Blue(gLeft)) / 3.0)
If invertY
gUp= Point(x,y+1): gDown= Point(x,y-1)
Else
gUp= Point(x,y-1): gDown= Point(x,y+1)
EndIf
deltaY = ((Red(gDown) + Green(gDown) + Blue(gDown)) / 3.0) - ((Red(gUp) + Green(gUp) + Blue(gUp)) / 3.0)
nx = deltaX * strength: ny = deltaY * strength: nz = 1.0
length = Sqr(nx*nx + ny*ny + nz*nz): nx = nx / length: ny = ny / length: nz = nz / length
; r = Int((nx + 1) * 127.5):g = Int((ny + 1) * 127.5): b = Int((nz + 1) * 127.5)
r = (nx + 1) * 127.5:g = (ny + 1) * 127.5: b = (nz + 1) * 127.5
px(x,y)= RGB(r, g, b)
Next x
Next y
StopDrawing()
normalMapID = CreateImage(#PB_Any, width, height, 32)
StartDrawing(ImageOutput(normalMapID))
For y = 1 To height - 2
For x = 1 To width - 2
Plot(x,y,px(x,y))
Next x
Next y
StopDrawing()
FreeArray(px())
ProcedureReturn normalMapID
EndProcedure
Structure dvtItem_stru
type.a
x.f
y.f
w.f
h.f
color.l
level.b
txt.s
p1.i ;parametros multifunción
p2.i
fontName.s
fontSize.c
font.i ;uso interno, luego se eliminan
randSeed.i
EndStructure
Structure dvtData_stru
name.s
width.c
height.c
bumpForce.f
texture.i
normal.i
imgTexture.i
imgBump.i
List o.dvtItem_stru()
EndStructure
Global NewList dvt.dvtData_stru()
;}
Procedure dvtData(t.s, freeimg.b=#True)
Protected.s txt, ts,os, comand
Protected tt,tn,ot,on, f, kx,ky
Protected.f scale
;dibujado
Protected mode, n,loopN= 1, p,k,na
Protected.f x,y,w,h, ox,oy,oh,ow
Protected img,bum,nor,noi
Protected.f bx,by,bw,bh, rc, sep, nx,ny,nw,nh, ang
tt= CountString(t,"#")
For tn= 1 To tt
ts= StringField(t,tn,"#")
ot= CountString(ts,"|")
AddElement(dvt())
os= StringField(ts,1,"|")
scale= ValF(StringField(os,5,",")):If scale=0:scale=1:EndIf
dvt()\name= StringField(os,1,",")
dvt()\width= Val(StringField(os,2,",")) * scale
dvt()\height= Val(StringField(os,3,",")) * scale
dvt()\bumpForce= ValF(StringField(os,4,",")): If dvt()\bumpForce=0:dvt()\bumpForce=0.8:EndIf
For on= 2 To ot
os= StringField(ts,on,"|")
comand= UCase(StringField(os,1,","))
AddElement(dvt()\o())
Select comand
Case "BOX"
dvt()\o()\type= 0
Case "ROUNDBOX"
dvt()\o()\type= 1
Case "ELLIPSE"
dvt()\o()\type= 2
Case "LINE"
dvt()\o()\type= 3
Case "TEXT"
dvt()\o()\type= 4
Case "SHAPE"
dvt()\o()\type= 5
Case "TEXTBOX"
dvt()\o()\type= 6
Case "BRIK"
dvt()\o()\type= 7
Case "WOOD"
dvt()\o()\type= 8
Case "SPLASH"
dvt()\o()\type= 9
Case "DIRTY"
dvt()\o()\type= 10
Case "DIRTYPOINT"
dvt()\o()\type= 11
Case "RAYS"
dvt()\o()\type= 12
Case "LEAFS"
dvt()\o()\type= 13
Case "NOISE"
dvt()\o()\type= 14
Case "RADIALBOX"
dvt()\o()\type= 15
Case "GLASS"
dvt()\o()\type= 16
Case "STONE"
dvt()\o()\type= 17
Case "RADIALROUNDBOX"
dvt()\o()\type= 18
Case "LOOP"
dvt()\o()\type= 100
EndSelect
dvt()\o()\x= Val(StringField(os,2,","))
dvt()\o()\y= Val(StringField(os,3,","))
dvt()\o()\w= Val(StringField(os,4,","))
dvt()\o()\h= Val(StringField(os,5,","))
dvt()\o()\color= Val(StringField(os,6,","))
dvt()\o()\level= Val(StringField(os,7,","))
dvt()\o()\txt= StringField(os,8,",")
dvt()\o()\p1= Val(StringField(os,9,","))
dvt()\o()\p2= Val(StringField(os,10,","))
dvt()\o()\fontName= StringField(os,11,",")
dvt()\o()\fontSize= Val(StringField(os,12,","))
; If UCase(StringField(os,10,","))="R":dvt()\o()\p2=Random(Val( Right(StringField(os,10,","), Len(StringField(os,10,","))-1 ))):EndIf
; If UCase(StringField(os,10,","))="R-":dvt()\o()\p2=-Random(Val(StringField(os,10,","))):EndIf
If Left(StringField(os,6,","),1)= "R"
dvt()\o()\color= Random( Val(Right(StringField(os,6,","), Len(StringField(os,6,","))-1)),1)
EndIf
If dvt()\o()\type <> 7
If dvt()\o()\type= 0
If Left(UCase(StringField(os,9,",")),1)="R" And Left(UCase(StringField(os,9,",")),2)<>"LR"
dvt()\o()\p1=Random(Val( Right(StringField(os,9,","), Len(StringField(os,9,","))-1 )))
EndIf
If Left(UCase(StringField(os,9,",")),1)="L" And Left(UCase(StringField(os,9,",")),2)<>"LR"
dvt()\o()\p1=-Random(Val( Right(StringField(os,9,","), Len(StringField(os,9,","))-1 )))
EndIf
If Left(UCase(StringField(os,9,",")),2)="LR"
kx= Val( Right(StringField(os,9,","), Len(StringField(os,9,","))-2 ))
dvt()\o()\p1=Random(kx * 2)-kx
EndIf
EndIf
dvt()\o()\x * scale
dvt()\o()\y * scale
dvt()\o()\w * scale
dvt()\o()\h * scale
If dvt()\o()\type= 4 Or dvt()\o()\type= 6
dvt()\o()\fontSize * scale
EndIf
If dvt()\o()\type= 15
kx= Val(StringField(dvt()\o()\txt,1,";")) * scale
ky= Val(StringField(dvt()\o()\txt,2,";")) * scale
dvt()\o()\txt= Str(kx)+";"+Str(ky)
EndIf
Else
dvt()\o()\h * scale
EndIf
If dvt()\o()\fontName And dvt()\o()\fontSize
f= LoadFont(#PB_Any, dvt()\o()\fontName, dvt()\o()\fontSize, #PB_Font_HighQuality)
If IsFont(f)
dvt()\o()\font= f
EndIf
EndIf
Next on
Next tn
ForEach dvt()
img=CreateImage(#PB_Any,dvt()\width,dvt()\height,32)
bum=CreateImage(#PB_Any,dvt()\width,dvt()\height,32)
For mode= 0 To 1
If mode
StartVectorDrawing(ImageVectorOutput(bum))
Else
StartVectorDrawing(ImageVectorOutput(img))
EndIf
ForEach dvt()\o()
With dvt()\o()
;comandos
If \type= 100 ;LOOP
loopN= \color
x= \x: y= \y: w= \w: h= \h
Else
If loopN>1
ox= \x: oy= \y: ow= \w: oh= \h
EndIf
;objetos
For n=1 To loopN
If mode
c= \level * 17
ink= RGBA(c,c,c,255)
Else
ink= dvt()\o()\color
EndIf
If mode=0 Or (mode And \level>0)
Select \type
;{ BOX
Case 0 ;BOX p2(=0 fill >0 stroke)
RotateCoordinates(\x+(\w/2),\y+(\h/2),\p1)
VectorSourceColor(ink)
AddPathBox(\x,\y,\w,\h)
If \p2:StrokePath(\p2) : Else: FillPath(): EndIf
RotateCoordinates(\x+(\w/2),\y+(\h/2),\p1 * -1)
;}
;{ ROUNDBOX
Case 1 ;ROUNDBOX p1(px round corner) p2(=0 fill >0 stroke)
txt= "M "+Str(\x+\p1+\p1)+" "+Str(\y)+" L "+Str(\x+\w-(\p1+\p1))+" "+Str(\y)+" "+
"C "+Str(\x+\w-(\p1+\p1))+" "+Str(\y)+" "+Str(\x+\w)+" "+Str(\y)+" "+Str(\x+\w)+" "+Str(\y+\p1+\p1)+" L "+Str(\x+\w)+" "+Str(\y+\h-(\p1+\p1))+" "+
"C "+Str(\x+\w)+" "+Str(\y+\h-(\p1+\p1))+" "+Str(\x+\w)+" "+Str(\y+\h)+" "+Str(\x+\w-(\p1+\p1))+" "+Str(\y+\h)+" L "+Str(\x+\p1+\p1)+" "+Str(\y+\h)+" "+
"C "+Str(\x+\p1+\p1)+" "+Str(\y+\h)+" "+Str(\x)+" "+Str(\y+\h)+" "+Str(\x)+" "+Str(\y+\h-(\p1+\p1))+" L "+Str(\x)+" "+Str(\y+\p1+\p1)+" "+
"C "+Str(\x)+" "+Str(\y+\p1+\p1)+" "+Str(\x)+" "+Str(\y)+" "+Str(\x+\p1+\p1)+" "+Str(\y)+" "
VectorSourceColor(ink)
AddPathSegments(txt)
If \p2:StrokePath(\p2) : Else: FillPath(): EndIf
;}
;{ ELLIPSE
Case 2 ;ELLIPSE p2(=0 fill >0 stroke)
VectorSourceColor(ink)
AddPathEllipse(\x,\y,\w,\h)
If \p2:StrokePath(\p2) : Else: FillPath(): EndIf
;}
;{ LINE
Case 3 ;LINE
VectorSourceColor(ink): MovePathCursor(\x,\y): AddPathLine(\w,\h): StrokePath(\p2)
;}
;{ TEXT
Case 4 ;TEXT p1(angle) p2(=0 fill >0 stroke)
RotateCoordinates(\x,\y,\p1)
VectorFont(FontID(\font))
VectorSourceColor(ink)
MovePathCursor(\x,\y)
AddPathText(\txt)
If \p2:StrokePath(\p2) : Else: FillPath(): EndIf
RotateCoordinates(\x,\y,\p1 * -1)
;}
;{ SHAPE
Case 5 ;SHAPE p2(=0 fill >0 stroke)
VectorSourceColor(ink)
AddPathSegments(\txt)
If \p2:StrokePath(\p2) : Else: FillPath(): EndIf
;}
;{ TEXTBOX
Case 6 ;TEXTBOX p1(angle)
RotateCoordinates(\x,\y,\p1)
VectorFont(FontID(\font))
VectorSourceColor(ink)
MovePathCursor(\x,\y)
DrawVectorParagraph(\txt,\w,\h)
RotateCoordinates(\x,\y,\p1 * -1)
;}
;{ BRIK
Case 7 ;BRIK
If Not mode
\randSeed= Random(9999)
EndIf
RandomSeed(\randSeed)
VectorSourceColor($ff888888): FillVectorOutput();AddPathBox(0,0,dvt()\width,dvt()\height): FillPath()
bn=0: bx=0: by=0: bw=dvt()\width/\x: bh=dvt()\height/\y
sep= \w
While by < dvt()\height
If \p1: ang.f= Sin(bx+by)*2: RotateCoordinates(bx+(bw/2),by+(bh/2),ang): EndIf
VectorSourceColor(ink): AddPathBox(bx,by,bw-sep,bh-sep): FillPath()
If Not mode:VectorSourceColor(RGBA(0,0,0,Random(150))): AddPathBox(bx,by,bw-sep,bh-sep): StrokePath(4):EndIf ;border
rc=Random(255):oc=RGBA(rc,rc,rc,Random(50)):VectorSourceColor(oc): AddPathBox(bx,by,bw-sep,bh-sep): FillPath()
If \p1: RotateCoordinates(bx+(bw/2),by+(bh/2),ang * -1): EndIf
bx+bw
If bx>dvt()\width
by+bh: bn+1
If bn%2=0
bx=0
Else
bx=-(bw)/2
EndIf
EndIf
Wend
If \p2;noise
Select \p2
Case 1
noi= (dvt()\width * dvt()\height) /64
While noi>0
If Random(2)
VectorSourceColor(RGBA(0,0,0,Random(50))): AddPathCircle(Random(dvt()\width),Random(dvt()\height), Random(3,1)/4): FillPath()
VectorSourceColor(RGBA(255,255,255,Random(50))): AddPathCircle(Random(dvt()\width),Random(dvt()\height), Random(3,1)/4): FillPath()
EndIf
noi-1
Wend
Case 2
bx=0:by=0
While by<dvt()\height
bx+ Random(40,3):If bx > dvt()\width: bx=-5:by+Random(10,1):EndIf
If Random(1): VectorSourceColor($08000000): Else: VectorSourceColor($08ffffff) :EndIf
MovePathCursor(bx,by)
AddPathLine(bx+Random(40,3),by):StrokePath(1)
Wend
EndSelect
EndIf
;}
;{ WOOD
Case 8 ;WOOD
SaveVectorState()
RotateCoordinates(\x+(\w/2),\y+(\h/2), \p1)
AddPathBox(\x,\y,\w,\h)
ClipPath()
If Not mode
VectorSourceColor(ink): FillVectorOutput();AddPathBox(0,0,dvt()\width,dvt()\height): FillPath()
bx= (dvt()\width*0.1)+ Random(dvt()\width-(dvt()\width*0.2))
by= (dvt()\height*0.1)+ Random(dvt()\height-(dvt()\height*0.2)): noi= dvt()\width
While noi > 10
VectorSourceColor(ink)
AddPathEllipse(bx,by,noi,noi):FillPath()
If Random(1)
VectorSourceColor(RGBA(0,0,0,Random(40)))
Else
VectorSourceColor(RGBA(255,255,255,Random(40)))
EndIf
AddPathEllipse(bx,by,noi,noi):FillPath()
noi- Random(20,5)
Wend
If Random(1)
VectorSourceColor(RGBA(0,0,0,Random(15)))
Else
VectorSourceColor(RGBA(255,255,255,Random(15)))
EndIf
AddPathBox(\x,\y,\w,\h): FillPath()
Else
c= \level * 17
ink= RGBA(c,c,c,255)
VectorSourceColor(ink)
AddPathBox(\x,\y,\w,\h)
FillPath()
EndIf
RestoreVectorState()
;}
; -------- OVERLAY FX
;{ SPLASH
Case 9 ; SPLASH
If Not mode
\randSeed= Random(9999)
If \p1:\x=Random(dvt()\width):EndIf
If \p1:\y=Random(dvt()\height):EndIf
If \p2:\w=Random(dvt()\width,dvt()\width*0.2):EndIf
If \p2:\h=Random(dvt()\height,dvt()\height*0.2):EndIf
EndIf
RandomSeed(\randSeed)
For p= 1 To 5
bx= \x+(\w/2)
by= \y+(\h/2)
bw= \w * 0.2
bh= Random(360)
sep= bw
While bw>1
If Random(1)
VectorSourceColor(ink)
AddPathCircle(bx,by,bw)
FillPath()
If Random(1)
If Not mode And bw>5
VectorSourceColor($11000000)
AddPathCircle(bx,by,bw-3)
FillPath()
VectorSourceColor(ink)
AddPathCircle(bx-2,by+2,bw-3)
FillPath()
EndIf
EndIf
EndIf
bx= (\x+(\w/2)) + Cos(Radian(bh)) * sep
by= (\y+(\h/2)) + Sin(Radian(bh)) * sep
bw - Random(8)
sep+ Random(15)
Wend
Next p
;}
;{ DIRTY
Case 10 ; DIRTY
If Not mode
If \p1=0:\p1=10:EndIf
For noi= 1 To \p1
bx= Random(dvt()\width)
by= Random(dvt()\height)
bw= Random(dvt()\width/2,dvt()\width/6)
VectorSourceCircularGradient(bx, by, bw);, -50, -50)
VectorSourceGradientColor(\color, 0.0)
VectorSourceGradientColor(RGBA(Red(\color),Green(\color),Blue(\color),0), 1.0)
FillVectorOutput()
Next noi
EndIf
;}
;{ DIRTYPOINT
Case 11 ; DIRTYPOINT
VectorSourceCircularGradient(\x,\y,\w);, -50, -50)
VectorSourceGradientColor(ink, 0.0)
VectorSourceGradientColor(RGBA(Red(ink),Green(ink),Blue(ink),0), 1.0)
FillVectorOutput()
;}
;{ RAYS
Case 12 ; RAYS
If Not mode
\randSeed= Random(9999)
EndIf
RandomSeed(\randSeed)
bx= Random(dvt()\width)
by= Random(dvt()\height)
bh= Random(360)
VectorSourceColor(ink)
For noi= 1 To 15
; RandomSeed(\randSeed+noi)
bw= Random(dvt()\width*0.075,dvt()\width*0.025) ;radio
nx= bx + (Cos(Radian(bh)) * bw)
ny= by + (Sin(Radian(bh)) * bw)
MovePathCursor(bx,by): AddPathLine(nx,ny):StrokePath(\p1)
bx=nx: by=ny
bh+ Random(60)-30
If Random(2)
nw=bx:nh=by
na=bh
rc= Random(10,1)
For k=1 To rc
na+ Random(90)-45
bw= Random(dvt()\width*0.1,dvt()\width*0.025) ;radio
nx= nw + (Cos(Radian(na)) * bw)
ny= nh + (Sin(Radian(na)) * bw)
MovePathCursor(nw,nh): AddPathLine(nx,ny):StrokePath(\p1)
nw=nx:nh=ny
Next k
EndIf
Next noi
;}
;{ LEAFS
Case 13 ; LEAFS
If Not mode
\randSeed= Random(9999)
; Else
; ink= $88ffffff
EndIf
RandomSeed(\randSeed)
bx= Random(dvt()\width)
by= Random(dvt()\height)
bh= Random(360)
For noi= 1 To 15
bw= Random(dvt()\width*0.075,dvt()\width*0.025) ;radio
nx= bx + (Cos(Radian(bh)) * bw)
ny= by + (Sin(Radian(bh)) * bw)
VectorSourceColor(ink)
MovePathCursor(bx,by): AddPathLine(nx,ny):StrokePath(\p1)
bx=nx: by=ny
bh+ Random(60)-30
If Random(2)
nw=bx:nh=by
na=bh
rc= Random(10,1)
For k=1 To rc
na+ Random(90)-45
bw= Random(dvt()\width*0.1,dvt()\width*0.025) ;radio
nx= nw + (Cos(Radian(na)) * bw)
ny= nh + (Sin(Radian(na)) * bw)
VectorSourceColor(ink)
MovePathCursor(nw,nh): AddPathLine(nx,ny):StrokePath(\p1)
;hoja
c= Random(40)-20
nx= nw + (Cos(Radian(na+c)) * bw/4)
ny= nh + (Sin(Radian(na+c)) * bw/4)
VectorSourceColor(ink)
MovePathCursor(nw,nh): AddPathLine(nx,ny):StrokePath(\p1*2,#PB_Path_RoundEnd)
If Random(1)
VectorSourceColor(RGBA(0,0,0,Random(50,10)))
Else
VectorSourceColor(RGBA(255,255,255,Random(50,10)))
EndIf
MovePathCursor(nw,nh): AddPathLine(nx,ny):StrokePath(\p1*2,#PB_Path_RoundEnd)
nw=nx:nh=ny
Next k
EndIf
Next noi
;}
;{ NOISE
Case 14 ; NOISE
If \w=0:\w=512:EndIf
If \h=0:\h=512:EndIf
SaveVectorState()
AddPathBox(\x,\y,\w,\h)
ClipPath()
bx=0:by=0
While by < dvt()\height
Select Random(2)
Case 0
VectorSourceColor(RGBA(255,255,255,Random(50,10)))
Case 1
VectorSourceColor(RGBA(0,0,0,Random(50,10)))
Case 2
VectorSourceColor(RGBA(Red(ink),Green(ink),Blue(ink),Random(50,10)))
EndSelect
If Random(1)
AddPathCircle(bx,by,Random(4,1)*0.5):FillPath()
EndIf
bx+Random(3):If bx > dvt()\width: by+Random(4,1): bx=0:EndIf
Wend
RestoreVectorState()
;}
;{ RADIALBOX
Case 15 ; RADIALBOX,384,224,64,32,"x;y",$ff0000ff,15,,10,20|"+
ang=0
bx= Val(StringField(\txt,1,";"))
by= Val(StringField(\txt,2,";"))
VectorSourceColor(ink)
AddPathBox(\x,\y,\w,\h)
FillPath()
For c= 0 To \p1
RotateCoordinates(bx,by,\p2)
AddPathBox(\x,\y,\w,\h)
FillPath()
Next c
; RotateCoordinates(bx,by,0)
ResetCoordinates()
;}
;{ RADIALROUNDBOX
Case 18 ; "RADIALROUNDBOX,16,240,64,32,$ff997755,15,256;256,8,20|"+ posición inicial x,y,w,h,color,nivel,centerx;centery,p1=pasos,p2=grados añadidos
ang=0
bx= Val(StringField(\txt,1,";"))
by= Val(StringField(\txt,2,";"))
noi= \p1
\p1=5
txt= "M "+Str(\x+\p1+\p1)+" "+Str(\y)+" L "+Str(\x+\w-(\p1+\p1))+" "+Str(\y)+" "+
"C "+Str(\x+\w-(\p1+\p1))+" "+Str(\y)+" "+Str(\x+\w)+" "+Str(\y)+" "+Str(\x+\w)+" "+Str(\y+\p1+\p1)+" L "+Str(\x+\w)+" "+Str(\y+\h-(\p1+\p1))+" "+
"C "+Str(\x+\w)+" "+Str(\y+\h-(\p1+\p1))+" "+Str(\x+\w)+" "+Str(\y+\h)+" "+Str(\x+\w-(\p1+\p1))+" "+Str(\y+\h)+" L "+Str(\x+\p1+\p1)+" "+Str(\y+\h)+" "+
"C "+Str(\x+\p1+\p1)+" "+Str(\y+\h)+" "+Str(\x)+" "+Str(\y+\h)+" "+Str(\x)+" "+Str(\y+\h-(\p1+\p1))+" L "+Str(\x)+" "+Str(\y+\p1+\p1)+" "+
"C "+Str(\x)+" "+Str(\y+\p1+\p1)+" "+Str(\x)+" "+Str(\y)+" "+Str(\x+\p1+\p1)+" "+Str(\y)+" "
VectorSourceColor(ink)
AddPathSegments(txt)
FillPath()
For c= 0 To noi
RotateCoordinates(bx,by,\p2)
; AddPathBox(\x,\y,\w,\h)
AddPathSegments(txt)
FillPath()
Next c
; RotateCoordinates(bx,by,0)
ResetCoordinates()
\p1=noi
;}
;{ GLASS
Case 16 ;GLASS
VectorSourceColor(ink)
AddPathBox(\x,\y,\w,\h):FillPath()
SaveVectorState()
AddPathBox(\x,\y,\w,\h)
ClipPath()
For noi= 0 To 5
bx= \x+Random(\w)
by= \y+Random(\h)
bw= Random(360)
RotateCoordinates(bx,by,bw)
txt= "M "+Str(bx-Random(\w*0.4,\w*0.2))+" "+Str(by-Random(\h*0.4,\h*0.2))+" "+
"L "+Str(bx+Random(\w*0.4,\w*0.2))+" "+Str(by-Random(\h*0.4,\h*0.2))+" "+
"L "+Str(bx+Random(\w*0.4,\w*0.2))+" "+Str(by+Random(\h*0.4,\h*0.2))+" "+
"L "+Str(bx+Random(\w*0.4,\w*0.2))+" "+Str(by-Random(\h*0.4,\h*0.2))+" "+
"L "+Str(bx+Random(\w*0.4,\w*0.2))+" "+Str(by+Random(\h*0.4,\h*0.2))+" "+
"L "+Str(bx-Random(\w*0.4,\w*0.2))+" "+Str(by+Random(\h*0.4,\h*0.2))+" Z"
If noi= 0
VectorSourceColor($ff000000): AddPathSegments(txt): FillPath()
Else
If mode
VectorSourceColor(RGBA(100+noi*5,100+noi*5,100+noi*5,255)): AddPathSegments(txt): FillPath()
Else
VectorSourceColor(ink): AddPathSegments(txt): FillPath()
EndIf
If Random(1)
VectorSourceColor(RGBA(0,0,0,Random(50,10))): AddPathSegments(txt): FillPath()
Else
VectorSourceColor(RGBA(255,255,255,Random(50,10))): AddPathSegments(txt): FillPath()
EndIf
EndIf
RotateCoordinates(bx,by,bw * -1)
Next noi
RestoreVectorState()
;}
;{ STONE
Case 17 ;STONE
VectorSourceColor(ink)
; AddPathBox(0,0,VectorOutputWidth(),VectorOutputWidth())
FillVectorOutput()
bx= \x
by= \y
bw= \w
bh= \h
\w-2
\h-2
\p1= 5
\x= 0:\y=0
noi=1
While \y < dvt()\height
VectorSourceColor(ink)
txt= "M "+Str(\x+\p1+\p1)+" "+Str(\y)+" L "+Str(\x+\w-(\p1+\p1))+" "+Str(\y)+" "+
"C "+Str(\x+\w-(\p1+\p1))+" "+Str(\y)+" "+Str(\x+\w)+" "+Str(\y)+" "+Str(\x+\w)+" "+Str(\y+\p1+\p1)+" L "+Str(\x+\w)+" "+Str(\y+\h-(\p1+\p1))+" "+
"C "+Str(\x+\w)+" "+Str(\y+\h-(\p1+\p1))+" "+Str(\x+\w)+" "+Str(\y+\h)+" "+Str(\x+\w-(\p1+\p1))+" "+Str(\y+\h)+" L "+Str(\x+\p1+\p1)+" "+Str(\y+\h)+" "+
"C "+Str(\x+\p1+\p1)+" "+Str(\y+\h)+" "+Str(\x)+" "+Str(\y+\h)+" "+Str(\x)+" "+Str(\y+\h-(\p1+\p1))+" L "+Str(\x)+" "+Str(\y+\p1+\p1)+" "+
"C "+Str(\x)+" "+Str(\y+\p1+\p1)+" "+Str(\x)+" "+Str(\y)+" "+Str(\x+\p1+\p1)+" "+Str(\y)+" "
AddPathSegments(txt)
; FillPath()
FillPath(#PB_Path_Preserve)
Select Random(2)
Case 0
If Random(1)
VectorSourceColor($11000000)
Else
VectorSourceColor($11ffffff)
EndIf
Case 1
VectorSourceColor($22000000)
Case 2
VectorSourceColor($22ffffff)
EndSelect
; AddPathSegments(txt)
FillPath()
If mode
SaveVectorState()
AddPathSegments(txt)
ClipPath()
VectorSourceCircularGradient(\x+(\w/2),\y+(\h/2),\w)
VectorSourceGradientColor($88ffffff,0)
VectorSourceGradientColor($88ffffff,0.5)
VectorSourceGradientColor($00ffffff,1)
FillVectorOutput()
RestoreVectorState()
EndIf
\x+ bw
If \x > dvt()\width
\y+ bh;Random(\h,\h*0.1)
If noi % 2=0:\x= 0:Else: \x=-bw/2:EndIf
EndIf
noi+1
Wend
\x=bx:\y=by:\w=bw:\h=bh
;}
EndSelect
EndIf
\x+x:\y+y:\w+w:\h+h
Next n
If loopN>1
loopN= 1: x=0: y=0: w=0: h=0
\x=ox: \y=oy: \w=ow: \h=oh
EndIf
EndIf
EndWith
Next
StopVectorDrawing()
;{ crea texturas
If mode= 0
;textura
dvt()\texture= CreateTexture(#PB_Any,ImageWidth(img),ImageHeight(img))
StartDrawing(TextureOutput(dvt()\texture))
DrawImage(ImageID(img),0,0)
StopDrawing()
; showImage(img)
If freeimg
FreeImage(img)
Else
dvt()\imgTexture= img
EndIf
Else
;bump
nor= ImgToNormalMap(bum,dvt()\bumpForce,1,1)
; showImage(bum)
If freeimg
FreeImage(bum)
Else
dvt()\imgBump= nor
EndIf
bum= nor
dvt()\normal= CreateTexture(#PB_Any,ImageWidth(bum),ImageHeight(bum))
StartDrawing(TextureOutput(dvt()\normal))
DrawImage(ImageID(bum),-1,-1,OutputWidth()+2,OutputHeight()+2)
StopDrawing()
; showImage(bum)
FreeImage(bum)
EndIf
;}
Next mode
Next
ForEach dvt()
ForEach dvt()\o()
If IsFont(dvt()\o()\font): FreeFont( dvt()\o()\font ): EndIf
Next
Next
; ClearList(dvt())
EndProcedure
;{ DVT draw vector texture INFO
; Syntax:
; HEAD:
; texturename$,width,height,bumpforce (default=1)
; OBJECTS:
; type$,x,y,w,h,color,level,txt$,p1,p2,fontname$,fontsize|#
; --------------------------------------------------------------------
; |= separate items to draw, #= separate textures
; level param is how deeping is the elevation 0=bottom to 15 on the top
; OBJECTS TYPES:
; BOX,ROUNDBOX,ELLIPSE,LINE,TEXT,SHAPE,TEXTBOX,BRIK,WOOD,SPLASH,DIRTY,DIRTYPOINT,RAYS,LEAFS,NOISE,RADIALBOX,GLASS,STONE
; Info about extra params
; LOOP: x,y,w,h,nLoops nLopps=R10 random(10) (x,y,w,h added by cycle, can be negative and float number)
; BOX,ROUNDBOX,ELLIPSE,TEXT,SHAPE: p1=angle p2>0 stroke, 0=fillpath (p1 R=random right, L=random left, LR=random)
; LINE,x1,y1,x2,y2,color,level,_,_,stroke
; TEXT,TEXTBOX: p1= angle
; BRIK: p1=1 brik random angle, p2=1 noise - (full paint texture)
; SPLASH,x,y,w,h,color,level,_,randomXY,randomWH
; WOOD: color
; LEAFS,0,0,0,0,$ff445588,7,,1=ancho linea
; RADIALBOX,364,240,54,32,$ffbbbbbb,15,256;256,17,20 text="Xcenter;Ycenter"
; STONE,0,0,64,32,$ff997755,3 - _,_,brikW,brikH,color,deep
;}
CompilerIf #PB_Compiler_IsMainFile
;{ start 3D
InitEngine3D():InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0,0, 1200,700, "DVT draw vector texture bump [Space next texture]",#PB_Window_ScreenCentered)
; AntialiasingMode(#PB_AntialiasingMode_x6)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0),WindowHeight(0), 0, 0, 0)
CompilerIf #PB_Compiler_Version >= 620 ;this is for new PB. Thanks miso :)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Main", #PB_3DArchive_FileSystem)
Parse3DScripts()
CompilerElse
; Parse3DScripts()
CompilerEndIf
; WorldShadowsEx(1000,1024,3,0.00002)
WorldShadows(#PB_Shadow_Modulative,1000,RGB(128,128,128),2048)
; light = CreateLight(#PB_Any ,$ffffff, 15, 10, -20, #PB_Light_Point)
CreateLight(0 ,$ffffff, 0, 20, 0,#PB_Light_Directional):LightDirection(0 ,-1,-0.9,0.75)
AmbientColor($aaaaaa)
; AmbientColor($888888)
CreateCamera(0,0,0,100,100):MoveCamera(0,3,2.5,0,#PB_Absolute):CameraLookAt(0,0,1.2,0)
MoveCamera(0,0,0,1,#PB_Relative)
;}
;{ TEXTURAS VECTORIALES
f.s= ""
f+ "adoquines,512,512,1|"+
"STONE,0,0,64,32,$ff997755,1|"+
"TEXT,20,20,0,0,$ffffffff,-1,Press space,0,0,Impact,70|"+
"TEXT,20,120,0,0,$ffffffff,-1,PureBasic,0,0,Impact,70|"+
"#"
f+ "adoquines,512,512,1|"+
"STONE,0,0,64,32,$ff997755,1|"+
"NOISE,0,0,512,512,$11000000,-1|"+
"DIRTY,0,0,0,0,$55334455|"+
"DIRTY,0,0,0,0,$88223344|"+
"LOOP,0,0,0,0,5|"+
"LEAFS,0,0,0,0,$ff778899,13,,1|"+
"LEAFS,0,0,0,0,$ff009900,14,,6|"+
"LEAFS,0,0,0,0,$ff334455,15,,6|"+
"LOOP,0,0,0,0,10|"+
"LEAFS,0,0,0,0,$ff667788,13,,1|"+
"#"
f+ "muro gris,512,512,1|"+
"BRIK,8,16,6,0,$ff888888,8,,1,2|"+
"LOOP,0,128,0,0,4|"+
"BOX,0,2,64,60,$ff999999,13|"+
"LOOP,0,128,0,0,3|"+
"BOX,-32,66,64,60,$ff888888,13|"+
"LOOP,0,128,0,0,4|"+
"BOX,448,2,64,60,$ff999999,13|"+
"LOOP,0,128,0,0,3|"+
"BOX,480,66,64,60,$ff888888,13|"+
"DIRTY,0,0,0,0,$88223344|"+
"LOOP,0,0,0,0,5|"+
"LEAFS,0,0,0,0,$ff778899,13,,1|"+
"LEAFS,0,0,0,0,$ff009900,14,,6|"+
"LEAFS,0,0,0,0,$ff334455,15,,6|"+
"LOOP,0,0,0,0,10|"+
"LEAFS,0,0,0,0,$ff667788,13,,1|"+
"#"
;}
dvtData(f,0)
mesh_plano= CreatePlane(#PB_Any,100,100,1,1,1,1)
mate_plano= CreateMaterial(#PB_Any,#Null,$888888)
enti_plano= CreateEntity(#PB_Any,MeshID(mesh_plano),MaterialID(mate_plano))
texturas= ListSize(dvt())
Dim mates(texturas)
mesh= CreateCube(#PB_Any,1)
n=0
ForEach dvt()
mates(n)= CreateShaderMaterial(#PB_Any, #PB_Material_BumpShader)
MaterialShaderTexture(mates(n),TextureID(dvt()\texture),TextureID(dvt()\normal),0,0)
MaterialShaderParameter(mates(n),#PB_Shader_Fragment,"bumpy",#PB_Shader_Float,2,0,0,0)
SetMaterialColor(mates(n), #PB_Material_DiffuseColor,RGB(250,250,250))
SetMaterialColor(mates(n), #PB_Material_AmbientColor,RGB(160,160,160))
MaterialShininess(mates(n),125,$ffffff)
MaterialFilteringMode(mates(n),#PB_Material_Trilinear)
; MaterialFilteringMode(mates(n),#PB_Material_Anisotropic,8)
n+1
Next
; ClearList(dvt())
SelectElement(dvt(),0)
enti= CreateEntity(#PB_Any,MeshID(mesh),MaterialID(mates(0)),0,1.2,0)
w.f= TextureWidth(dvt()\texture) / 512
h.f= TextureHeight(dvt()\texture) / 512
ScaleEntity(enti,w,h,1,#PB_Absolute)
CreateLine3D(#PB_Any, -20,0,0,$0000ff, 20,0,0,$00ffff)
CreateLine3D(#PB_Any, 0,0,-20,$ff0000, 0,0,20,$ffff00)
sy.f=1
Procedure CameraUserControl(camera,speed.f=0.1,smooth.f=0.1,yfixed.f=1e10)
Static.f MouseX,Mousey,depx,depz,sdepx,sdepz, fdf.b
depx=-speed*(KeyboardPushed(#PB_Key_Left)-KeyboardPushed(#PB_Key_Right))
depz=-speed*(KeyboardPushed(#PB_Key_Down)-KeyboardPushed(#PB_Key_Up)-MouseWheel()*20)
If KeyboardReleased(#PB_Key_F12):fdf=1-fdf:If fdf:CameraRenderMode(0,#PB_Camera_Wireframe):Else:CameraRenderMode(0,#PB_Camera_Textured):EndIf:EndIf
MouseX = -MouseDeltaX() * 0.05
MouseY = -MouseDeltaY() * 0.05
RotateCamera(camera, MouseY, MouseX, 0, #PB_Relative)
sdepx+(depx-sdepx)*smooth
sdepz+(depz-sdepz)*smooth
MoveCamera (camera, sdepX, 0, -sdepz)
If yfixed<>1e10:MoveCamera(camera,CameraX(camera),yfixed,CameraZ(camera),#PB_Absolute):EndIf
EndProcedure
; ReleaseMouse(#True)
Repeat
While WindowEvent():Wend
ExamineMouse(): ExamineKeyboard()
If KeyboardReleased(#PB_Key_1)
sy-0.1:If sy<0.1:sy=0.1:EndIf
ScaleEntity(enti,1,sy,1,#PB_Absolute)
ElseIf KeyboardReleased(#PB_Key_2)
sy+0.1
ScaleEntity(enti,1,sy,1,#PB_Absolute)
EndIf
CameraUserControl(0, 0.001)
If KeyboardReleased(#PB_Key_Space)
p+1:If p>=texturas:p=0:EndIf
SelectElement(dvt(), p)
Debug Str(ListIndex(dvt()))+" "+dvt()\name
w.f= TextureWidth(dvt()\texture) / 512
h.f= TextureHeight(dvt()\texture) / 512
ScaleEntity(enti,w,h,1,#PB_Absolute)
SetEntityMaterial(enti,MaterialID(mates(p)))
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
CompilerEndIf