Skip to content

Instantly share code, notes, and snippets.

View RichardEllicott's full-sized avatar

Richard Ellicott RichardEllicott

  • Luton
View GitHub Profile
func distance_to_string(distance_m):
var suffix = "m"
if distance_m > 1000.0:
distance_m /= 1000.0
suffix = "km"
var txt = "%*.*f m" % [7,1,distance_m]
txt += " %s" % suffix
return txt
@RichardEllicott
RichardEllicott / GridContainerTest.gd
Last active June 27, 2019 14:18
showing iterating child nodes of GridContainer to produce the coordinates of the rectangles
extends GridContainer
func _ready():
print('running tests...')
for child in get_children():
print(self, " found child: ",child)
print(child.rect_global_position)
func array_split(array, start = 0, end = -1):
var ret = []
if end < 0:
end = array.size() + end
for i in range(array.size()):
if i >= start and i<= end:
ret.append(array[i])
return ret
func ran_gaussian_2D():
var r1 = randf()
var r2 = randf()
var al1 = sqrt(-2 * log(r1)) # part one
var al2 = 2 * PI * r2 # part two
var x = al1 * cos(al2)
var y = al1 * sin(al2)
func ran_gaussian_2D():
"""
ported from the caltech lua one
making some optimisations now, many bits are just repeated!
STILL NEED TO FIGURE SOME OF THESE EQUATIONS OUT
"""
var r1 = randf()
var r2 = randf()
func shuffle_list(list, _seed = null):
list = list.duplicate()
if _seed:
seed(_seed)
var shuffledList = []
var indexList = range(list.size())
for i in range(list.size()):
var x = randi()%indexList.size()
shuffledList.append(list[x])
indexList.remove(x)
extends ImmediateGeometry
var points = [Vector3(), Vector3(10,0,10), Vector3(0,0,10)]
func _process(delta):
clear()
begin(1, null)
for i in range(points.size()):
if i + 1 < points.size():
var A = points[i]
var coll_dict_data1 = [
["player",
"1000000000000000", "0000111111111111"],
["playerbullet",
"0100000000000000", "0000101110111011"],
["playerbulletclash",
"0010000000000000", "0000111111111111"],
["enemy",
"0000100000000000", "1111000011111111"],
["enemybullet",
mat3 GetTBN();
vec3 GetBumpedNormal(mat3 tbn, vec2 texcoord);
vec2 ParallaxMap(mat3 tbn);
Material ProcessMaterial()
{
mat3 tbn = GetTBN();
vec2 texCoord = ParallaxMap(tbn);
Material material;
if pcall(function ()
print('test1')
error()
end)then
print('test2')
else
print('test3')
end