The fun part of the challenge is to figure out how to write text on the screen without depending on external assets.
I thought this was obvious, but very well, I'll adjust the description.
Edit: an argument could be made about using love.graphics.newImageFont( image, glyphs ) so I suppose print/printf would be ok in the latter case
1K Terminal challenge
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: 1K Terminal challange
The code doesn't work, I'm getting the same error as DeltaF1"The size of the raw byte string must match the imageData's actual size in bytes.".Ortimh wrote:It's so hard. I couldn't do it. I use your code, optimize it a bit, and now can use right shift for caps, with 3 bytes in extra (1,528 bytes).Code: Select all
F=(" 66 __ ` 66?c6f_ 0 63<_ 6?n ÿ? ? 0; <_ _ 6?f3 f 6cn _ _______ 8??_ 3+<+3_ 3;0060+?0?30> 0700330_?3+0+3 ??0 _____ __>?<?<3xgcccff6FFf30fwg6{3ff306oc{3>f?0k{c{?ffs336Fcsc3ff6Ff33ffcc63?<?|3gcc________???+cc3 f3f3-+cc+ f3f+c636 >3>+kc ;8+6F0_633wcc`_8g?cc@________ ÿ 8 _ 0 6 __ >0n6f7 0f3>33n6+ >f3?3fk+ 3f+>f6c+ n=n0ggc3___ _____ ___8n_____;;n>>+cc3? 6f36+c63 8 cf36+k3 c>>0,36>& c0n6c0?8 x___ ___"):gsub("_"," "):gsub("+","33")O=""for a=1,#F do b=F:byte(a)for j=1,8 do h=b%2 O=O..(h>0 and"ÿÿÿÿ"or" y")b=(b-h)/2 end end L=love G=L.graphics K=L.keyboard.isScancodeDown I=G.newImage(L.image.newImageData(128,48,O)) Q={}for c=0,5 do for f=0,15 do Q[#Q+1]=G.newQuad(f*8,c*8,8,8,128,48) end end function W(g,f,c) for a=1,#g do b=g:byte(a)-31 if Q[b]then G.draw(I,Q[b],f+(a-1)*8,c)else W(g:sub(a+1),f,c+8)break end end end O=""function L.draw()W(O.."_",0,0)end function print(i)O=O.."\n"..tostring(i)end Z='~!@#$%^&*()_+|{}:"<>?'z="`1234567890-=\\[];',./"function L.keypressed(k)k=k:gsub("space"," ")if k=="back "then O=O:sub(1,-2)elseif k=="return"then e=O:match("[^\n]-$")r,t=pcall(loadstring(e))O=O.."\n"..(t or"").."\n"elseif#k<2 then if K('lshift')or K('rshift') then j=z:find(k,1,true)k=(j and Z:sub(j,j)or k):upper()end O=O..k end end
Re: 1K Terminal challange
Keep in mind that the code contains controls characters so it must be saved as ANSI.Ranguna259 wrote:The code doesn't work, I'm getting the same error as DeltaF1"The size of the raw byte string must match the imageData's actual size in bytes.".
Alternatively, just run the .love file provided in earlier posts.
Re: 1K Terminal challange
Oh baby. I spent a day playing Cards against Humanity, but I was secretly thinking about this and launched into it this morning. My trick here is I use a 3x5 font I stole from the dwarf fortress wiki, rather than the 8x8 font. So, sorry for everyone that has to squint while looking at my terminal window. The version in the love zip file I'm uploading isn't minified, in case anyone wants to try and improve on my methods. Here's the final minified version:
Edit: From here on out this is version 2 after ivan points out my bug.
973 Bytes. (bumps right against 1024ish if you include the conf.lua file for resizable windows)
Here's the feature list I achieved:
- typed input via the keyboard
- execute commands by pressing enter
- delete characters via backspace
- embedded font string
- print command (with tabs between parameters in output)
- tab key works
- outputs errors on the screen (v2 fix shows both kinds of errors now)
- upper and lowercase, caps
- shift modifier (love.textinput gave me this one for free)
- numeric keypad (kp_enter)
- a cursor (underscore character to indicate your prompt on the bottom line)
Also my drop the mic image, I'll leave the link but i think I lost to privilege of dropping the mic after picking it back up.
https://love2d.org/imgmirrur/lxLhfNl.gif
Edit: From here on out this is version 2 after ivan points out my bug.
Code: Select all
Z=[[Qa9^c&&NDEBYO.&McCQARQ:)9SLccXc\ccS?Y26FIQDO*@A@&?T@PJN<MQNN9=aaaSKBYA++[AY@a)6*94FFFUZE6FTX$JZU65&6LQ<?N68VZ*&464696IFZ9&EF6U<(QQ6646N6$6N66Q)O*MQUR?PQP^cccDacc5TJFcU=/.cD=)Q+.TJ6aPQSIZFNQQc$^K6c9a8X3._KZcM`)1c6\;Nc&\;9;NbPJMPMaQPM8ac]]T=table;F=math.floor;M=Z.gmatch;B=Z.byte;L=love;G=L.graphics;R=G.rectangle;O={}S={""}i=495;for a in M(Z,'.')do p,b=1,99-B(a)while p<64 do O[i]=F(b/p)%2>0;p,i=p*2,i+1 end end;A=function(a)S[1]=a and S[1]..a or S[1]:sub(1,#S[1]-1)end;L.draw=function()H=G.getHeight()/2;G.scale(2,2)A'_'for c=1,#S do X=0;for a in M(S[c],'.')do if a=='\t'then X=F(X/8)*8+8 else for i=0,14 do if O[B(a)*15+i]then R('fill',X*4+i%3,(F(H/6)-c)*6+F(i/3),1,1)end end;X=X+1 end end end;A()end;L.textinput=A;print=function(...)T.insert(S,1,T.concat({...},'\t'))end;L.keypressed=function(d)d=d:sub(1,3)if d=="ret"or d=="kpe"then o,r=pcall(loadstring,S[1])if o then o,r=pcall(r)end;print(r)print''elseif d=="bac"and#S[1]>0 then A()elseif d=="tab"then A'\t'end end
Here's the feature list I achieved:
- typed input via the keyboard
- execute commands by pressing enter
- delete characters via backspace
- embedded font string
- print command (with tabs between parameters in output)
- tab key works
- outputs errors on the screen (v2 fix shows both kinds of errors now)
- upper and lowercase, caps
- shift modifier (love.textinput gave me this one for free)
- numeric keypad (kp_enter)
- a cursor (underscore character to indicate your prompt on the bottom line)
Also my drop the mic image, I'll leave the link but i think I lost to privilege of dropping the mic after picking it back up.
https://love2d.org/imgmirrur/lxLhfNl.gif
- Attachments
-
- terminal_challenge_inny_v2.love
- Version 2
- (6.72 KiB) Downloaded 366 times
-
- terminal_challenge_inny.love
- got the space-backspace bug
- (6.67 KiB) Downloaded 308 times
Last edited by Inny on Sun May 22, 2016 10:13 pm, edited 2 times in total.
Re: 1K Terminal challange
Well done, Inny, I like your version more than mine.
textinput is a good idea too, I might steal that.
A small suggestion: pressing the spacebar deletes the last character (not sure if this is omitted intentionality).
But yea, very well done.
PS. I was thinking about doing vector fonts using love.graphics.line,
just wasn't clever enough to come up with a good way to compress the glyphs.
textinput is a good idea too, I might steal that.
A small suggestion: pressing the spacebar deletes the last character (not sure if this is omitted intentionality).
But yea, very well done.
PS. I was thinking about doing vector fonts using love.graphics.line,
just wasn't clever enough to come up with a good way to compress the glyphs.
Re: 1K Terminal challange
Whoops, that slipped through my testing. I'll fix it and just edit my other post.ivan wrote:pressing the spacebar deletes the last character
Re: 1K Terminal challange
So i made a new version from my first entry. Now it uses a personally modified 3x4 font and a much more paste-friendly string. It is essentially a complete shrink of inny's terminal.
1.5 - 849 Bytes
I also have a version with a complete bit string, which uses 50 bytes less!
1.5 - 849 Bytes
Code: Select all
B4JH"Z 4 X "+T=N67QWS.-Y\?4_Y:=^590004"B''"*Q"5C5]VN<CUN^G\T<KM]Z7)JMUDGO]OM5JUT5KUU<>Z2MOMJM_JMM2YW:3F9R65 'B #OFN#C+K'S*Z]?DU0206EU21']&M"J'\'Y&D#673%O%J%_%5%4RF:S22R>S ]],".")do X=B(b)-32;for a=5,0,-1 do T[J+a]=X%2;X=(X-X%2)/2 end;J=J+6 end;function N(c)table.insert(G,1,tostring(c))end;print=N;function L.draw()for d=0,#G do X=0;for b in M(G[d]or C,".")do if B(b)>32 then for a=0,11 do if T[(B(b)-33)*12+a]>0 then L.graphics.rectangle("fill",X+a%3*2,d*12+math.floor(a/3)*2,2,2)end end end;X=X+8 end end end;function L.textinput(b)C=C..b end;N"G={} - Clear Log"function L.keypressed(e)if e=="backspace"then C=C:sub(1,-2)elseif e=="return"and#C>0 then O,R=loadstring(C)if O then O,R=pcall(O)X=O or N(R)else N(R)end;C=""end end
- Attachments
-
- 1k_3x4_terminal.love
- 1.5 (799 Byte version.)
- (3.69 KiB) Downloaded 334 times
-
- 1k_terminal_hatninja.love
- 1.0
- (3.67 KiB) Downloaded 329 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: 1K Terminal challange
Modified airstruck's solution to not break the "-do not use [...] love's default embedded font" rule.
The rules don't require any type of visual feedback.
EDIT: wow, I've been absent on this forum for longer than I realised... sorry for necroposting everyone.
Code: Select all
local buffer = ''
function love.textinput (text)
buffer = buffer .. text
end
function love.keypressed (key)
if key == 'backspace' then
buffer = buffer:gsub('.$', '')
elseif key == 'return' then
io.execute(buffer)
buffer = ''
end
end
EDIT: wow, I've been absent on this forum for longer than I realised... sorry for necroposting everyone.
Help us help you: attach a .love.
Re: 1K Terminal challenge
Came here to tell that minifying and mangling the source is not how you do this. What you should be doing is generating and loading bytecode.
Re: 1K Terminal challange
Thats alright, i actually wish these kinds of challenges went on for longer!Robin wrote:EDIT: wow, I've been absent on this forum for longer than I realised... sorry for necroposting everyone.
It was a pretty clever solution, albeit a little lame.
Who is online
Users browsing this forum: No registered users and 6 guests