Very good. Really love it, so pulled a piece out of my program and posted here(as it's using your function).
// Project: Texture On Shape Test Demo
// Created: 2017-12-19
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Texture /Shape Demo " )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
rock=CreateObjectBox(10,10,10)
rocktexture= createtexture(32,32, makecolor(255,255,0) ,255)
SetObjectImage(rock,rocktexture,0)
SetCameraLookAt(1,getobjectx(rock),getobjecty(rock),getobjectz(rock),0)
angx#=0 : angy#=0 : angz#=0
count=0
interval# = timer()+2
run=1
do
if run
SetObjectRotation(rock,angx#,angy#,angz#)
inc angx#,1
inc angy#,1
inc angz#,1
if timer() > interval# or GetRawKeyPressed(32) // generare new texture..
deleteimage (rocktexture)
// CreateTexture ( textureWidth#, textureHeight#, makecolor(red, green, blue), density)
textureWidth# = Random(1,255)
textureHeight# = Random(1,255)
red = Random(0,255)
green = Random(0,255)
blue = Random(0,255)
density = Random(1,255)
rocktexture= createtexture ( textureWidth#, textureHeight#, makecolor( red , green, blue ) , density )
//rocktexture= createtexture ( Random(1,255), Random(1,255), makecolor( Random(0,255), Random(0,255), Random(0,255) ) , Random(1,255) )
SetObjectImage(rock,rocktexture,0)
interval# =timer()+2
endif
endif
If GetRawKeyState(9) // Tab = switch object shape..
r=Random(1,4)
select r
case 1:
DeleteObject(rock)
rock=CreateObjectBox( random(1,10), random(1,10) , random(1,10) )
endcase
case 2:
DeleteObject(rock)
rock=CreateObjectCone(random(1,10),random(1,10),random(1,12))
endcase
case 3:
DeleteObject(rock)
rock=CreateObjectCylinder(random(1,28),random(1,6),random(1,12))
endcase
case default:
DeleteObject(rock)
//( diameter, rows, columns )
diameter#= random(2,10)
rows#=random(.1,25)
colums#=random(1,32)
rock=CreateObjectsphere(diameter#,rows# ,colums# )
endcase
endselect
SetObjectImage(rock,rocktexture,0)
Endif
If GetRawKeyState(27) // Esc = end app..
exit
Endif
If GetRawKeyState(72) // H = hold..
run=1-run
sleep(200)
Endif
Print ("Press [Space] or wait 2 seconds for texture to change..")
Print ("Press [H] to toggle hold texture change.")
Print ("Press [Tab] to change object shape.")
Print ("")
Print( "FPS: " + str(ScreenFPS() ))
//Print( "timer interval: "+ Str(interval#) )
//Print( "timer: "+ Str(timer()) )
Print("time remaining: " + Str( trunc((interval#-timer() )*10)) )
Print("")
Print("")
Print("")
Print("")
Print("")
Print("")
Print("")
Print("")
Print("")
Print("")
Print( "textureWidth# : " + Str(textureWidth#) )
Print( "textureHeight#: " + Str(textureHeight#) )
Print( "red : " + Str(red) )
Print( "green : " + Str(green) )
Print( "blue : " + Str(blue) )
Print( "density : " + Str(density) )
Sync()
loop
end
// Function to create a texture
//
// Inputs - Sizex - size of the texture to create - width
// Sizey - size of the texture to create - height
// Color - is the main color of the image
// Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
//
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100, makecolor(0,0,255), 100)
// This could create a DEEP water effect texture?
function createtexture(sizex# as float, sizey# as float, color, density as integer)
swap()
drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
render()
img = getimage(0,0,sizex#, sizey#)
memblockid = CreateMemblockFromImage (img)
imgwidth = GetMemblockInt(memblockid, 0)
imgheight = GetMemblockInt(memblockid, 4)
size=GetMemblockSize(memblockid)
for offset=12 to size-4 step 4
r=GetMemblockByte(memblockid, offset)
g=GetMemblockByte(memblockid, offset+1)
b=GetMemblockByte(memblockid, offset+2)
a=GetMemblockByte(memblockid, offset+3)
strength=random(1,density)
SetMemblockByte (memblockid, offset, r-strength)
SetMemblockByte (memblockid, offset+1, g-strength)
SetMemblockByte (memblockid, offset+2, b-strength )
SetMemblockByte (memblockid, offset+3, a-strength)
next
deleteimage (img)
img = CreateImageFromMemblock(memblockid)
DeleteMemblock(memblockid)
endfunction img
[EDIT: Still can't believe what variety of pretty textures your function can generate. Would be even more useful to display the parameters and if a nice texture comes up then, hold note down or save to a data file]
[EDIT2: OK. did just that. Now displays all parameters and can press 'H' to hold so can note them down.]