(05-01-2026, 05:53 AM)1micha.elok Wrote: I'm amazed that math can generate textures - rocks, bricks, ....even trees (fractals). It makes me wonder, is our entire universe just one big math composition ?
I'm doing in code the steps I usually take when creating textures in the gimp, creating bumpmaps from noise etc. I need to write more image manipulation functions though, for altering colors.
'------------
' MAIN LOOP
'------------
while not keydown(KEY_ESCAPE, true)
'clear screen
set color 0,0,0;cls
' Terrain
scroll_x = scroll_x + 3.5 'scroll speed
for x = 0 to width() - 1
ty_map[x] = height() / 2 + terrain.ValueAt((x + scroll_x) / scale, 0.5) * amp
next
set color green
for x = 0 to width() - 2
' Draw terrain fill (vertical line) + edge (diagonal)
draw line x, ty_map[x], x, height()
draw line x, ty_map[x], x + 1, ty_map[x + 1]
next
' last vertical line
draw line width() - 1, ty_map[width() - 1], width() - 1, height()
' Ball
i = min(max(int(bx), 0), width() - 1)
ty_curr = ty_map[i]
bvy = bvy + 0.45
by = by + bvy
if by + 4 >= ty_curr
by = ty_curr - 4
bvy = -bvy * 0.75
endif
bx = bx + (width() / 2 - bx) * 0.08
set color yellow; draw ellipse bx, by, 4,4, true
redraw
fwait 60
wend
'-------------
' FUNCTIONS
'-------------
function MakeTerrain(resX, resY)
t = []
t.g = dim(resX, resY)
t.w = resX
t.h = resY
for y = 0 to resY - 1
for x = 0 to resX - 1
a = rnd() * PI * 2
t.g[x][y] = [x: cos(a), y: sin(a)]
next
next
t.ValueAt = function(x, y)
m = this.g
w = this.w; h = this.h
x = x * w; y = y * h
x0 = floor(x); y0 = floor(y)
x1 = (x0 + 1) % w; y1 = (y0 + 1) % h
x0 = x0 % w; y0 = y0 % h
fx = x - floor(x); fy = y - floor(y)
'------------
' MAIN LOOP
'------------
while not keydown(KEY_ESCAPE, true)
'clear screen
set color 0,0,0;cls
' Terrain
scroll_x = scroll_x + 3.5 'scroll speed
for x = 0 to width() - 1
ty_map[x] = height() / 2 + terrain.ValueAt((x + scroll_x) / scale, 0.5) * amp
next
set color green
for x = 0 to width() - 2
' Draw terrain fill (vertical line) + edge (diagonal)
draw line x, ty_map[x], x, height()
draw line x, ty_map[x], x + 1, ty_map[x + 1]
next
' last vertical line
draw line width() - 1, ty_map[width() - 1], width() - 1, height()
' Ball
i = min(max(int(bx), 0), width() - 1)
ty_curr = ty_map[i]
bvy = bvy + 0.45
by = by + bvy
if by + 4 >= ty_curr
by = ty_curr - 4
bvy = -bvy * 0.75
endif
bx = bx + (width() / 2 - bx) * 0.08
set color yellow; draw ellipse bx, by, 4,4, true
redraw
fwait 60
wend
'-------------
' FUNCTIONS
'-------------
function MakeTerrain(resX, resY)
t = []
t.g = dim(resX, resY)
t.w = resX
t.h = resY
for y = 0 to resY - 1
for x = 0 to resX - 1
a = rnd() * PI * 2
t.g[x][y] = [x: cos(a), y: sin(a)]
next
next
t.ValueAt = function(x, y)
m = this.g
w = this.w; h = this.h
x = x * w; y = y * h
x0 = floor(x); y0 = floor(y)
x1 = (x0 + 1) % w; y1 = (y0 + 1) % h
x0 = x0 % w; y0 = y0 % h
fx = x - floor(x); fy = y - floor(y)
Interesting. Replace the "ball" with a motor cycle or car; apply a little physics to the vehicle; control the speed of the scroll; add a timer; score based on timer; persistent high score... Could be the makings of an "endless runner" type game... Moo Ha Ha Ha....
05-07-2026, 03:11 PM (This post was last modified: 05-07-2026, 03:12 PM by Marcus.)
Textures and landscape based on that perlin noise thing, everything generated in code. It looks a bit like Mordor at the moment, will post the source code when things look better It's a really large map that has been divided into "chunks", and I only render the chunks that are determined visible.