Dec 12, 2012

#1

5th Dan Black Belt
Join Date: Nov 2009
Posts: 4,186

Random useless (or not) miniscripts thread
For any bits of scripting that don't belong anywhere else. Feel free to share them here.
Newbie scripts are also accepted.
To get things started:
Having been learning how to work with math.cos and math.sin, I have achieved some wonderful results:
lua code:
len = 0
ang = 0
w,h = get_window_size()
angtbl = {}
while len <= w do
table.insert(angtbl,{x=(w/2)+(len*math.cos(ang)), y=(h/2)+(len*math.sin(ang))})
len = len + 0.1
ang = ang+0.01
end
add_hook("draw2d","y_test",function()
set_color(0,0,0,1)
draw_quad(0,0,w,h)
for i = 1,#angtbl do
set_color(math.random(),math.random(),math.random(),1)
draw_quad(angtbl[i].x2, angtbl[i].y2,4,4)
end
end)




Dec 14, 2012

#2

ub3r
6th Dan Black Belt
Join Date: Jan 2012
Posts: 2,879

Hello Yoyo.
What it does?

:D



Dec 14, 2012

#3

Junior Member
Black Belt
Join Date: Dec 2011
Posts: 20

what it does?




Dec 14, 2012

#4

5th Dan Black Belt
Join Date: Nov 2009
Posts: 4,186

Why don't you try it? :)




Dec 16, 2012

#5

ub3r
6th Dan Black Belt
Join Date: Jan 2012
Posts: 2,879

 Hmmm , I feel curious about that
 I'll download!
 Let me see.. WOW WTF
Nice script lol!

:D



Dec 18, 2012

#6

5th Dan Black Belt
Join Date: Nov 2009
Posts: 4,186

I was bored, so I decided to code 2 circle algorithms:
lua code:
function draw_circle_b(xc,yc,r)
local x = 0
local y = r
local p = 3  2 * r
if not r then return end
while y >= x do
draw_quad(xcx, ycy, 1, 1)
draw_quad(xcy, ycx, 1, 1)
draw_quad(xc+y, ycx, 1, 1)
draw_quad(xc+x, ycy, 1, 1)
draw_quad(xcx, yc+y, 1, 1)
draw_quad(xcy, yc+x, 1, 1)
draw_quad(xc+y, yc+x, 1, 1)
draw_quad(xc+x, yc+y, 1, 1)
if p < 0 then
x=x+1
p=p+(4*x+6)
else
x=x+1
y=y1
p=p+(4*(xy)+10)
end
end
end
function draw_circle_n(xc,yc,r)
draw_disk(xc,yc,r1,r,r*2.5,1,0,360,0)
end
add_hook("draw2d","",function() set_color(0,0,0,1) draw_circle_b(500,300,50) draw_circle_n(700,500,10) draw_circle_n(700,500,100) end)
First one is a lua translation of Bresenham's circle algorithm, second one is a simplified version of draw_disk adapted for circles.
The hook provided is an example.
Parameters are x position, y position and radius of the circle on both functions.




Dec 22, 2012

#7

5th Dan Black Belt
Join Date: Nov 2009
Posts: 4,186

A hacked startup.lua requested by john (aka box), it removes several restrictions while keeping backwards compatibility.
It removes all OS and cpath restrictions, and allows you to use the original file functions.
ex: _old_io_open("etc","w")
You can check for the hacked startup by checking the boolean _hackedstartup.
_startup.lua is the default startup.
Please don't mess around with this if you don't know what you're doing.

Last edited by Yoyo; Dec 22, 2012 at 07:17 PM..



Dec 22, 2012

#8

?crazykid700=flashglass
Cardboard Belt
Join Date: Sep 2007
Posts: 9,203

Great work, Yoyo. Your talent does not go unnoticed.

[23:23:53] <AndChat700625> Blue eyes ultimate dragon best card
[23:24:29] <AndChat700625> You know the one with 3 heads
[23:24:39] <~Lightningkid> just like my dick
[11:35:40] <box> Hampa suck
[11:36:21] <hampa> not the first to tell me that today



Dec 24, 2012

#9

5th Dan Black Belt
Join Date: Nov 2009
Posts: 4,186

Working on a maze generator that john asked for, using prim's algorithm.
This is as far as I've gotten, but the maze still doesn't generate quite properly.
If anyone wants to help, feel free to.
lua code:
local grid = {}
local n = {}
local path = {}
local nn = {}
local r
local len = 0
local is_stepping = false
for x = 1, 50 do
grid[x] = {}
path[x] = {}
for y = 1, 50 do
grid[x][y] = false
path[x][y] = false
end
end
n={{x=1,y=1}}
local function maze_gen() actual prims alg, generates 1 cell everytime the func is ran
if #n>0 then
r = math.random(1,#n)
if not grid[n[r].x][n[r].y] then
grid[n[r].x][n[r].y] = true path[n[r].x][n[r].y] = true
if n[r].y>1 then if not grid[n[r].x][n[r].y1] then table.insert(nn,{x=n[r].x,y=n[r].y1}) end end
if n[r].y<50 then if not grid[n[r].x][n[r].y+1] then table.insert(nn,{x=n[r].x,y=n[r].y+1}) end end
if n[r].x>1 then if not grid[n[r].x1][n[r].y] then table.insert(nn,{x=n[r].x1,y=n[r].y}) end end
if n[r].x<50 then if not grid[n[r].x+1][n[r].y] then table.insert(nn,{x=n[r].x+1,y=n[r].y}) end end
if #nn>0 then
for i=1,#nn do
if nn[i].y>1 then if n[r].x~=nn[i].x and n[r].y~=nn[i].y1 and path[nn[i].x][nn[i].y1] then len=len+1 grid[nn[i].x][nn[i].y1]=true end end
if nn[i].y<50 then if n[r].x~=nn[i].x and n[r].y~=nn[i].y+1 and path[nn[i].x][nn[i].y+1] then len=len+1 grid[nn[i].x][nn[i].y+1]=true end end
if nn[i].x>1 then if n[r].x~=nn[i].x1 and n[r].y~=nn[i].y and path[nn[i].x1][nn[i].y] then len=len+1 grid[nn[i].x1][nn[i].y]=true end end
if nn[i].x<50 then if n[r].x~=nn[i].x+1 and n[r].y~=nn[i].y and path[nn[i].x+1][nn[i].y] then len=len+1 grid[nn[i].x+1][nn[i].y]=true end end
if nn[i].y>1 and nn[i].x>1 then if n[r].x~=nn[i].x1 and n[r].y~=nn[i].y1 and path[nn[i].x1][nn[i].y1] then len=len+1 grid[nn[i].x1][nn[i].y1]=true end end
if nn[i].y<50 and nn[i].x>1 then if n[r].x~=nn[i].x1 and n[r].y~=nn[i].y+1 and path[nn[i].x1][nn[i].y+1] then len=len+1 grid[nn[i].x1][nn[i].y+1]=true end end
if nn[i].x<50 and nn[i].y>1 then if n[r].x~=nn[i].x+1 and n[r].y~=nn[i].y1 and path[nn[i].x+1][nn[i].y1] then len=len+1 grid[nn[i].x+1][nn[i].y1]=true end end
if nn[i].x<50 and nn[i].y<50 then if n[r].x~=nn[i].x+1 and n[r].y~=nn[i].y+1 and path[nn[i].x+1][nn[i].y+1] then len=len+1 grid[nn[i].x+1][nn[i].y+1]=true end end
if len ~= 0 then
grid[nn[i].x][nn[i].y]=true
end
table.insert(n,nn[i])
len = 0
end
end
nn = {}
end
table.remove(n,r)
end
end
while #n>0 do
maze_gen()
end
add_hook("draw2d","box's homework",
function()
set_color(0,0,0,1)
draw_quad(0,0,520,520)
draw_text("boxprims.lua by yoyo  press h to regenerate maze, press n to generate step by step",550,100,1)
for j=1,50 do
for i=1,50 do
set_color(1,1,1,1)
if path[j][i] then
draw_quad(j*10,i*10,10,10)
end
if is_stepping then
set_color(0,0,1,0.3)
if grid[j][i] then
draw_quad(j*10,i*10,10,10)
end
end
end
end
if is_stepping then
set_color(1,0,0,0.3)
for i=1,#n do
draw_quad(n[i].x*10,n[i].y*10,10,10)
end
maze_gen() maze_gen() maze_gen() step the algorithm forward 3 times
if #n==0 then is_stepping = false end
end
end
)
add_hook("key_down","box's homework",function(k)
if k==104 then
run_cmd("ls boxprims.lua")
elseif k==110 then
if not is_stepping then
is_stepping = true
if #n==0 then
for x = 1, 50 do
grid[x] = {}
path[x] = {}
for y = 1, 50 do
grid[x][y] = false
path[x][y] = false
end
end
n = {{x=1,y=1}}
end
else
is_stepping = false
end
end
end)




Dec 24, 2012

#10

Member
2nd Dan Black Belt
Join Date: Feb 2010
Posts: 388

What do you mean with "the maze still doesn't generate quite properly"? Looks like a maze to me.

Signature temporarily out of order.



Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off



All times are GMT +1. The time now is 01:16 AM.
