Created
August 26, 2016 16:44
-
-
Save byronhulcher/f5e6058eba47e72867ad1e05f3f52c48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pico-8 cartridge // http://www.pico-8.com | |
version 8 | |
__lua__ | |
-- mondrian art v.1 | |
-- by hypirlink | |
r1 = {} | |
r1.clr = 8 | |
r2 = {} | |
r2.clr = 12 | |
function generate_sqr(r,xp,yp,size,rando) | |
r.x1 = xp | |
r.y1 = yp | |
r.x2 = r.x1+flr(rnd(rando))+size | |
r.y2 = r.y1+flr(rnd(rando))+size | |
end | |
function collide(r1,r2,t) | |
if t==nil then | |
t=0 | |
end | |
x1 = r1.x1-t | |
y1 = r1.y1-t | |
w1 = r1.x2-r1.x1+(2*t) | |
h1 = r1.y2-r1.y1+(2*t) | |
x2 = r2.x1-t | |
y2 = r2.y1-t | |
w2 = r2.x2-r2.x1+(2*t) | |
h2 = r2.y2-r2.y1+(2*t) | |
return x1<x2+w2 and x2<x1+w1 and y1<y2+h2 and y2 < y1+h1 | |
end | |
function cross(r1,r2,t) | |
crx1 = abs(r1.x1-r2.x1) <= t or abs(r1.x1-r2.x2) <= t | |
crx2 = abs(r1.x2-r2.x1) <= t or abs(r1.x2-r2.x2) <= t | |
cry1 = abs(r1.y1-r2.y1) <= t or abs(r1.y1-r2.y2) <= t | |
cry2 = abs(r1.y2-r2.y1) <= t or abs(r1.y2-r2.y2) <= t | |
return crx1 or crx2 or cry1 or cry2 | |
end | |
function generate_squares() | |
// squares start as big | |
generate_sqr(r1,0,0,128,0) | |
generate_sqr(r2,0,0,128,0) | |
while (collide(r1,r2,5) or cross(r1,r2,5)) do | |
generate_sqr(r1,10,10,40,50) | |
generate_sqr(r2,75,75,35,15) | |
end | |
end | |
generate_squares() | |
function datalog() | |
if collide(r1,r2) then | |
print("collide",0,0,9) | |
else | |
print("no collide",0,0,9) | |
end | |
print(r1.x1,0,12,2) | |
print(r1.y1,12,12,2) | |
print(r1.x2,24,12,2) | |
print(r1.y2,36,12,2) | |
print(r2.x1,0,24,1) | |
print(r2.y1,12,24,1) | |
print(r2.x2,24,24,1) | |
print(r2.y2,36,24,1) | |
if cross(r1,r2,5) then | |
print("cross",0,36,9) | |
else | |
print("no cross",0,36,9) | |
end | |
end | |
function _update() | |
if btnp()>0 then | |
generate_squares() | |
end | |
end | |
function draw_bg() | |
rectfill(0,0,128,128,7) | |
end | |
function draw_lines(r) | |
// left line | |
line(r.x1-1,0,r.x1-1,128,0) | |
// right line | |
line(r.x2+1,0,r.x2+1,128,0) | |
// top line | |
line(0,r.y1-1,128,r.y1-1,0) | |
// bottom line | |
line(0,r.y2+1,128,r.y2+1,0) | |
end | |
function draw_r(r) | |
// draw shape | |
rectfill(r.x1,r.y1,r.x2,r.y2,r.clr) | |
end | |
function _draw() | |
draw_bg() | |
draw_lines(r1) | |
draw_lines(r2) | |
draw_r(r1) | |
draw_r(r2) | |
// datalog() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment