Cardioid: Sunday kind of LÖVE 1K Challenge

Show off your games, demos and other (playable) creations.
User avatar
ivan
Party member
Posts: 1545
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Cardioid: Sunday kind of LÖVE 1K Challenge

Post by ivan » Fri Dec 27, 2019 6:57 pm

It's that time of year again!

Challenge:
Make a cardoid animation with LÖVE2D in 1K or less
Rules:
1.No external assets such as fonts or animation
2.Everything must be contained in a single main.lua file
3.Your main.lua file cannot exceed 1K

Thanks for participating!

User avatar
ivan
Party member
Posts: 1545
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by ivan » Fri Dec 27, 2019 6:59 pm

Raw:

Code: Select all

l = love
g = l.graphics
m = math
s,c = m.sin,m.cos
p = m.pi

a={}
for i = -50,50 do
  t = i/100*6
  a[#a+1] = 10*(16*s(t)^3)
  a[#a+1] = -10*(13*c(t)-5*c(2*t)-2*c(3*t)-c(4*t)) - 20
end
b={}
for i = -50,50 do
  t = i/100*p*2
  b[#b+1] = 120*c(t - p/2)
  b[#b+1] = 120*s(t - p/2)
end
d={}

h = g.newCanvas()
r = 0
function l.draw()
  r = r + 0.05
  q = (s(r) + 1)/2

  for i = 1, #b do
    d[i] = (a[i]*q + b[i]*(1-q))/2
  end
  u = l.math.triangulate(d)
  g.setColor(0,0,0.75)
  g.rectangle('fill', 0,0, 800,600)
  g.translate(400, 300)
  g.scale(4, 4)
  g.setColor(1,1,1)
  for _,t in ipairs(u) do
    g.polygon('fill',t)
  end
  g.scale(0.95, 0.95)
  g.setColor(0.75,0,0)
  for _,t in ipairs(u) do
    g.polygon('fill',t)
  end
end
Minify-ed:

Code: Select all

l=love;g=l.graphics;m=math;s,c=m.sin,m.cos;p=m.pi;a={}for e=-50,50 do t=e/100*6;a[#a+1]=10*16*s(t)^3;a[#a+1]=-10*(13*c(t)-5*c(2*t)-2*c(3*t)-c(4*t))-20 end;b={}for e=-50,50 do t=e/100*p*2;b[#b+1]=120*c(t-p/2)b[#b+1]=120*s(t-p/2)end;d={}h=g.newCanvas()r=0;function l.draw()r=r+0.05;q=(s(r)+1)/2;for e=1,#b do d[e]=(a[e]*q+b[e]*(1-q))/2 end;u=l.math.triangulate(d)g.setColor(0,0,0.75)g.rectangle('fill',0,0,800,600)g.translate(400,300)g.scale(4,4)g.setColor(1,1,1)for f,t in ipairs(u)do g.polygon('fill',t)end;g.scale(0.95,0.95)g.setColor(0.75,0,0)for f,t in ipairs(u)do g.polygon('fill',t)end end

Attachments
cardoid.love
(498 Bytes) Downloaded 19 times
1k.png
1k.png (7.61 KiB) Viewed 889 times

User avatar
ingsoc451
Party member
Posts: 108
Joined: Sat Feb 06, 2016 9:42 pm
Location: Oceania

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by ingsoc451 » Fri Dec 27, 2019 11:19 pm

I tried compressing and encoding your code, unfortunately it is only a few bytes smaller. But the result is more readable

Code: Select all

c='eNqVkGFrwyAQhv9KoB+qqbGaNt2G+Kk/o3RgEpsKVlO1LWPsv+/M1tF9GYyDu/PxeO/lrLT+qsUgLR2CGo+mi+IkTyodRSSdPNFoHDnRzkcxwms0Qsn3j4MPhZZVw0jDit4XSeolZ6zcCLWbqQXfS85KvikjSvh19QMroIivyg5w1UCpS2hqaFa56dAaCgBWaNeL9o9FY1mLdjdrp1U1y4rVuKzxI4vfLGv1oHWUA3X6tlXuqiLCQTJxuLguGe8KS/ugbhmGBaOsEWeJIgp4wfGyFl8uOJm12UO/03uJFOTyvGhzQbw6YxicbF/glPl+NAWj3HCxKmnU44FGnbbe+oAYgaBPDbCguwRDVqP5wVg7zz/kmTGyYQy+U1AuTgJrYKuJxU7B+JqsHyU5gcDZ54GkwrjCjMqEiC4YDA909PZt8O6+JE03uUsx+tKQnH55BH/ZzP808wE+ATmXse4='
d,s=love.data,"string";loadstring(d.decompress(s,"zlib",d.decode(s,"base64",c)))()
Attachments
main.lua
(556 Bytes) Downloaded 6 times
encomp.lua
(763 Bytes) Downloaded 9 times
eom

User avatar
raidho36
Party member
Posts: 1992
Joined: Mon Jun 17, 2013 12:00 pm

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by raidho36 » Sat Dec 28, 2019 5:39 am

Last time I did this challenge I cheated too, but I used a binary string instead of a base64 encoded string. It allowed me to implement tic-tac-toe with pixel graphics, different colors, score tracking, play against a human and a 2 level AI (no minimax though). Try your luck compressing it into a binary string. Be aware that C++ doesn't likes null characters, so you'll have to screw around with raw text until you get the right compression; automated tools do this but it takes a fair bit of time. You can also improve compression ratio by screwing around with order of text and whatnot. Also, putting the string in a variable instead of passing it directly into the function is a bunch of extra bytes.

User avatar
ingsoc451
Party member
Posts: 108
Joined: Sat Feb 06, 2016 9:42 pm
Location: Oceania

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by ingsoc451 » Sat Dec 28, 2019 11:11 am

I was able to reduce the size without compression
Attachments
main.lua
(499 Bytes) Downloaded 11 times
eom

grump
Party member
Posts: 595
Joined: Sat Jul 22, 2017 7:43 pm

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by grump » Sat Dec 28, 2019 2:51 pm

Will any heart-shaped object do or does it have to be a literal cardioid?

512 bytes

Image

Code: Select all

l=love;g=l.graphics;i,s=g.newImage(l.image.newImageData(1,1)),g.newShader([[#define f float
#define v vec2
extern f t;f b=t*6.283;float h(v p,v c,f s){v k=(c-p)/s;f d=k.x*k.x+k.y*k.y,a=d-.5;return step(a*a*a,k.x*k.x*k.y*k.y*k.y);}vec4 effect(vec4 c,Image t,v u,v e){
vec3 r=vec3(0);for(f i=1,n=0;i<32;++i){n=i/64;f c1=n*h(e,v(350+i,240+i*3),n*400+sin(b)*50+100+cos(b*2)*50);r+=c1*vec3(u.x,.1,.2*u.y);}return vec4(r,1);}]])
g.setShader(s)function l.draw()s:send('t',l.timer.getTime()%1);g.draw(i,0,0,0,800,600)end
Edit: 512 is a nice number, but I golfed some more, and here's a 468 bytes version, after fixing some mistakes:
Edit2: down to 462 bytes

Code: Select all

l=love;g=l.graphics;i,s=g.newCanvas(),g.newShader([[#define f float
#define v vec2
extern f t;f b=t*6.3;f h(v p,v c,f s){v k=(c-p)/s;f d=k.x*k.x+k.y*k.y,a=d-.5;return step(a*a*a,k.x*k.x*k.y*k.y*k.y);}vec4 effect(vec4 c,Image t,v u,v e){vec3 r=vec3(0);for(f i=1,n=0,c=0;i<32;++i){n=i/64;c=n*h(e,v(350+i,240+i*3),n*500+(sin(b)+cos(b*2))*50);r+=c*vec3(u.x,.1,.2*u.y);}return vec4(r,1);}]])g.setShader(s)function l.draw()s:send('t',l.timer.getTime()%1);g.draw(i)end
Attachments
heart.love
(519 Bytes) Downloaded 17 times
Last edited by grump on Sun Dec 29, 2019 7:02 am, edited 3 times in total.

User avatar
ingsoc451
Party member
Posts: 108
Joined: Sat Feb 06, 2016 9:42 pm
Location: Oceania

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by ingsoc451 » Sat Dec 28, 2019 3:55 pm

I tried to do a proxy minimal cardioid (283bytes)

Code: Select all

a={0,6,3,0,10,5,0,15}b={0,5,7,5,7,15,0,15}c={}d={}e=0
l=love
z=l.graphics
y=z.polygon
x="fill"
w=l.math.newBezierCurve
l.draw=function()z.translate(400,-40)e=(e+0.03)%2
f=e*(2-e)for i=1,#a do
c[i]=40*((1-f)*a[i]+f*b[i])d[i]=c[i]*(1-2*(i%2))end
y(x,w(c):render())y(x,w(d):render())end
Last edited by ingsoc451 on Mon Dec 30, 2019 9:32 am, edited 1 time in total.
eom

User avatar
ivan
Party member
Posts: 1545
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by ivan » Sat Dec 28, 2019 4:13 pm

Nicely done Grump & ingsoc451.
Doesn't really matter if it's not a perfect cardoid.

User avatar
zorg
Party member
Posts: 2745
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by zorg » Sat Dec 28, 2019 9:43 pm

Not a perfect cardioid but with a color pulse animation in 384 350 characters/bytes:

Code: Select all

L=love;G=L.graphics;S,t,u,d,l,r,x,y,C=math.sin,0,{0,-1},{0,1},{-1,0},{1,0},2.5,1.5,G.newCanvas(11,10)L.update=function(_)t=t+_;s=("rdrdrrururdrddldldldldululululuurdrdrrdlrdurururlllllluu"):gsub('.',function(c)C:renderTo(function()G.setColor(1,S(t),S(t))G.points(x,y)end)x=x+_G[c][1];y=y+_G[c][2]end)end;L.draw=function()G.draw(C,0,0,0,75,64,0,.2)end
Edit: The logo/turtle-graphics-esque sequence could probably be optimized more... also, here's the non-animated version, shaved down to 278 chars/bytes from 280:

Code: Select all

L,u,d,l,r,x,y,C=love,{0,-1},{0,1},{-1,0},{1,0},2.5,1.5;G=L.graphics;C=G.newCanvas(11,10)s=("rdrdrrururdrddldldldldululululuurdrdrrdlrdurururd"):gsub('.', function(c)C:renderTo(function()G.points(x,y)end)x=x+_G[c][1];y=y+_G[c][2]end)L.draw=function()G.draw(C,0,0,0,75,64,0,.2)end
pic.jpg
pic.jpg (29.85 KiB) Viewed 659 times
(atm, mine are the smallest in both cases, whether or not we take the fact that the OP specified a "cardioid animation". :3)
Last edited by zorg on Mon Dec 30, 2019 7:56 am, edited 4 times in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

grump
Party member
Posts: 595
Joined: Sat Jul 22, 2017 7:43 pm

Re: Cardioid: Sunday kind of LÖVE 1K Challenge

Post by grump » Sun Dec 29, 2019 4:28 pm

790 bytes
Image

Code: Select all

l=love;g=l.graphics;i,s=g.newCanvas(),g.newShader([[#define v vec3
#define f float
#define l normalize
#define r return
extern f t;f T=cos(t*3);f g(v p){v q=p*p;f a=q.x+2*q.y+q.z-1;r a*a*a-(q.x+.1*q.y)*(q*p).z;}f h(f x,f z){f y=.5;for(f a=0,b=1,i=0;i<12;i++){if(0>g(v(x,y,z)))a=y;else b=y;y=(a+b)*.5;}r y;}v n(vec2 p){v b=v(p.x,h(p.x,p.y),p.y),q=b*b,s=q*b;f a=dot(q,v(1,2,1))-1;a*=a;r l(v(-2*b.x*s.z+6*b.x*a,.1*b.y*s.z+15*b.y*a,b.z*(-3*q.x*b.z-.3*q.y*b.z+6*a)));}vec4 effect(vec4 y,Image e,vec2 u,vec2 F){v c=v(.3);v p=v(.7-u*1.4,0);v b=p*v((T*T*u.y)+2+T*T*.5,2+T*T*.25,0);v V=v(1);if(0>g(b.xzy)){v m=n(b.xy);f d=dot(m,l(V))*.5+.5;f s=pow(max(dot(m,l(V)),0),8+T*T*5);c=d*v(.6,.2,.2)+s-dot(m,V)*.2;}r vec4(c,1);}]])
g.setShader(s)function l.draw()s:send('t',l.timer.getTime()%1);g.draw(i)end
Credits: based on heart surface rendering code written by miloyip.
Attachments
h3d.love
(681 Bytes) Downloaded 17 times

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests