Pretty cool stuff! Thanks for sharing puzzler2018.
Immediately gave it a try. Very flexible and gives quite a nice effect.
(This actually deserves it's own thread, in case someone else is looking).
// Project: Create Texture In Code(procedural).
// Created: 2017-12-16
// *Credits go to puzzler2018 for the texturing function.
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "CreateTexture" )
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
//textureimage = createtexture(255,20, makecolor(50,255,255) ,50)
Box1=CreateObjectBox(10,10,10)
textureimage1 = createtexture(32,32, makecolor(255,255,0) ,255) // original example
SetObjectImage(Box1,textureimage1,0)
SetObjectPosition(Box1,0,-15,25)
Box2=CreateObjectBox(10,10,10)
textureimage2 = createtexture(20,255, makecolor(50,255,255) ,50) // marbleish
SetObjectImage(Box2,textureimage2,0)
SetObjectPosition(Box2,-10,-15,25)
Box3=CreateObjectBox(10,10,10)
textureimage3 = createtexture(255,20, makecolor(102, 51, 0) ,50) // wood brown
SetObjectImage(Box3,textureimage3,0)
SetObjectPosition(Box3,10,-15,25)
Box4=CreateObjectBox(10,10,10)
textureimage4 = createtexture( 100, 100, makecolor(0,0,255), 100) // blue
SetObjectImage(Box4,textureimage4,0)
SetObjectPosition(Box4,20,-15,25)
Box5=CreateObjectBox(10,10,10)
textureimage5 = createtexture(320,320, makecolor(255,255,200) ,255) // granite
SetObjectImage(Box5,textureimage5,0)
SetObjectPosition(Box5,-20,-15,25)
do
Print( ScreenFPS() )
Sync()
loop
// 102, 51, 0
// 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