I thought that maybe we could post our texture generating functions here, and edit eachother's.
Heres a few functions I made for memblock editing:
function SetCurrentMemblock(memblockNum)
`Sets the current memblock for editing
global MEM_ATT_MBN : MEM_ATT_MBN = memblockNum
global MEM_ATT_WIDTH : MEM_ATT_WIDTH = memblock dword(memblockNum,0)
global MEM_ATT_HEIGHT : MEM_ATT_HEIGHT = memblock dword(memblockNum,4)
endfunction
function MemblockDotRGB(x,y,red,green,blue)
`Writes a dot to a memblock taking invidual
`RGB values. ------------------------------
memPos = (y*MEM_ATT_WIDTH*4)+(x*4)
write memblock byte MEM_ATT_MBN,memPos+12,blue
write memblock byte MEM_ATT_MBN,memPos+13,green
write memblock byte MEM_ATT_MBN,memPos+14,red
endfunction
function CopyMemblockToScreen(memNum)
`Copys a memblock to the screen
lock pixels
ptrTo = get pixels pointer()
ptrFrom = get memblock ptr(memNum)+12
copy memory ptrTo,ptrFrom,get memblock size(1)-12
unlock pixels
endfunction
function FillMemblock(memNum,value)
`Fills a memblock with a chosen greyscale colour
`between 0 and 255. ----------------------------
fill memory get memblock ptr(memNum)+12,value,get memblock size(1)-12
endfunction
function MEM_point(x,y)
`Retreives the RGB value from an image memblock
memPos = (y*MEM_ATT_WIDTH*4)+(x*4)
r = memblock byte(MEM_ATT_MBN,memPos+12)
g = memblock byte(MEM_ATT_MBN,memPos+13)
b = memblock byte(MEM_ATT_MBN,memPos+14)
value=rgb(b,g,r)
endfunction value
function MemblockPointRGB(x,y)
`Retreives the individuals RGB values from
`an image memblock and puts them in global
`variables. ------------------------------
`NOTE: You will need to make MEM_POINTRED, MEM_POINTGREEN
`and MEM_POINTBLUE global variables at the top of your
`code, as thats where the values are stored.
memPos = (y*MEM_ATT_WIDTH*4)+(x*4)
MEM_POINTBLUE = memblock byte(MEM_ATT_MBN,memPos+12)
MEM_POINTGREEN = memblock byte(MEM_ATT_MBN,memPos+13)
MEM_POINTRED = memblock byte(MEM_ATT_MBN,memPos+14)
endfunction
function MemblockCircle(xPos,yPos,size,RGBvalue)
`Draws an outlined circle in a memblock
for xLoop=0 to 360
x=xPos+cos(xLoop)*size
y=yPos+sin(xLoop)*size
if x>0 and x=<MEM_ATT_WIDTH-1 and y>0 and y=<MEM_ATT_HEIGHT-1
memPos = (y*MEM_ATT_WIDTH*4)+(x*4)
write memblock byte MEM_ATT_MBN,memPos+12,rgbb(RGBvalue)
write memblock byte MEM_ATT_MBN,memPos+13,rgbg(RGBvalue)
write memblock byte MEM_ATT_MBN,memPos+14,rgbr(RGBvalue)
endif
next xLoop
endfunction
function MemblockCircleFilled(xPos,yPos,size,value)
`Draws a filled circle in a memblock
size#=size
for x=xPos-(size/2) to xPos+(size/2)
for y=yPos-(size/2) to yPos+(size/2)
if sqrt((xPos-x)^2+(yPos-y)^2)*2<size#
memPos = (y*MEM_ATT_WIDTH*4)+(x*4)
if x>0 and x=<MEM_ATT_WIDTH-1 and y>0 and y=<MEM_ATT_HEIGHT-1
write memblock byte MEM_ATT_MBN,memPos+12,rgbb(value)
write memblock byte MEM_ATT_MBN,memPos+13,rgbg(value)
write memblock byte MEM_ATT_MBN,memPos+14,rgbr(value)
endif
endif
next y
next x
endfunction
I'll start with my wood generator:
`---------------------------------------
`--------- Wood Generator --------------
`-- Author: Benjamin -------------------
`---------------------------------------
`NOTE: This will not work correctly
`in any resolution other than 640,480,32
`Set the sync rate
sync on
sync rate 60
`Make the memblock that we'll draw the wood on
make memblock from bitmap 1,0
`Set the current memblock for editing
SetCurrentMemblock(1)
`Generate the wood texture in the memblock
MakeWood()
`Copy the memblock to the screen
CopyMemblockToScreen(1)
do
sync
loop
function MakeWood()
color=50
rndAdjust=20
for x=1 to 639
for y=1 to 479
way=rnd(3)
if way=1 then color=color+rnd(rndAdjust)
if way=2 then color=color-(rnd(rndAdjust)+20)
if color>50 then color=50
color=WrapColor(color)
MemblockDotRGB(x,y,WrapColor(160+color),WrapColor(143+color),WrapColor(119+color))
next y
next x
endfunction
function WrapColor(value)
if value>255 then value=255
if value<0 then value=0
endfunction value
function SetCurrentMemblock(memblockNum)
`Sets the current memblock for editing
global MEM_ATT_MBN : MEM_ATT_MBN = memblockNum
global MEM_ATT_WIDTH : MEM_ATT_WIDTH = memblock dword(memblockNum,0)
global MEM_ATT_HEIGHT : MEM_ATT_HEIGHT = memblock dword(memblockNum,4)
endfunction
function MemblockDotRGB(x,y,red,green,blue)
`Writes a dot to a memblock taking invidual
`RGB values. ------------------------------
memPos = (y*MEM_ATT_WIDTH*4)+(x*4)
WRITE MEMBLOCK BYTE MEM_ATT_MBN,memPos+12,blue
WRITE MEMBLOCK BYTE MEM_ATT_MBN,memPos+13,green
WRITE MEMBLOCK BYTE MEM_ATT_MBN,memPos+14,red
endfunction
function CopyMemblockToScreen(memNum)
`Copys a memblock to the screen
lock pixels
ptrTo = get pixels pointer()
ptrFrom = get memblock ptr(memNum)+12
copy memory ptrTo,ptrFrom,get memblock size(1)-12
unlock pixels
endfunction
"Lets migrate like bricks" - Me