컬러 애니메이션과 물리학; 순수 JavaScript, 457 (335) 바이트
이 포럼의 첫 번째 게시물입니다. 이 코드를 만들고이 스레드를 소급하여 게시 할 것을 찾았습니다.
다음은 HTML로 캡슐화되어 html 파일로 복사 / 붙여 넣을 수있는 코드입니다.
<body><script>A=120;B=280;d=document;y=180;x=v=n=s=0;f=140;c=d.createElement('canvas');p=c.getContext('2d');c.width=B;c.height=400;c.onclick=()=>{v-=6};p.font='50px Arial';d.body.appendChild(c);r=(h,t,k=0,i='#0f0',w=40)=>{p.fillStyle=i;p.fillRect(h,k,w,t)};b=setInterval(()=>{if(x==0){n=f;f=Math.floor(B*Math.random());x=160}x--;v+=.1;y+=v;r(0,400,0,'#08f',B);r(20,40,y,'#fc0');r(x-40,n);r(x+A,f);r(x-40,B-n,n+A);r(x+A,B-f,f+A);if(x==60)s++;p.strokeText(s,A,80);if(x>20&&x<100&&(y<n||y>n+80)){clearInterval(b);location.reload()}},15)</script><br>Made by Thomas Kaldahl</body>
여기에는 픽셀 완벽 충돌, 정확한 2 차 물리학 및 부드러운 색상 애니메이션이 있으며 457 바이트의 순수하게 독립된 오프라인 Javascript 코드가 있으며 여기에 자세히 설명되어 있습니다.
<!--entire HTML shell is omitted in golf-->
<body>
<script>
//common numbers and the document are assigned shortcut letters
A = 120;
B = 280;
d = document;
y = 180; //y position of the top of the bird
x = //x position of scrolling for pipes
v = //vertical velocity of bird
n = //y position of the top of the nearest pipe opening
s = 0; //score
f = 140; //y position of the top of the farther pipe opening
c = d.createElement('canvas'); //canvas
p = c.getContext('2d'); //canvas context
//set canvas dimensions
c.width = B;
c.height = 400;
c.onclick = () => { v -= 6 }; //apply jump velocity to bird when clicked
p.font = '50px Arial'; //font for scoring (omitted in golf)
d.body.appendChild(c); //add canvas to html page
//draw a rectangle on the canvas
r = (h, t, k = 0, i = '#0f0', w = 40) => {
p.fillStyle = i;
p.fillRect(h, k, w, t)
};
//main loop (not assigned to b in golf)
b = setInterval( () => {
if (x == 0) { //the x position is a countdown. when it hits 0:
n = f; //the far pipe is now the near pipe, overwriting the old near pipe
f = B * Math.random() //assign the far pipe a new vertical location
x = 160; //restart the countdown back at 160
//(score increments here in golf)
}
x--; //count down
v += .1; // apply gravity to velocity
y += v; // apply velocity to bird
r(0, 400, 0, '#08f', B); //draw background
r(20, 40, y, '#fc0'); //draw bird (non-default color is omitted in golf)
r(x - 40, n); //draw first pipe upper half
r(x + A, f); //draw second pipe upper half
r(x - 40, B - n, n + A); //draw first pipe lower half
r(x + A, B - f, f + A); //draw second pipe lower half
if (x == 60)
s++; //(this is done earlier on golf)
p.strokeText(s, A, 80); //draw score
// if the bird is in range of the pipes horizontally,
// and is not in between the pipes,
if (x > 20 && x < 100 && (y < n || y > n + 80)) {
clearInterval(b); location.reload() //omit interval clear in golf
}
}, 15) //(reduced the frame delay to 9, a 1 digit number, in golf)
</script><br>
Made by Thomas Kaldahl <!-- GG -->
</body>
재미있는 그래픽을위한 1066 바이트 버전이 있습니다.
<body style='margin:0'><script>var y=180,x=v=n=s=0,f=140,c=document.createElement('canvas'),p=c.getContext('2d');c.width=280;c.height=400;c.onclick=function(){v-=6};c.style='width:68vh;height:97vh';document.body.appendChild(c);p.font="50px Arial";p.shadowColor='#444';p.shadowBlur=9;p.shadowOffsetX=p.shadowOffsetY=5;function r(h,t,k=0,i='#0f0',j='#0a0',u=0,l=0,w=40){var g=p.createLinearGradient(h,l,h+40,u);g.addColorStop(0,i);g.addColorStop(1,j);p.fillStyle=g;p.fillRect(h,k,w,t);}b=setInterval(function(){if(x==0){n=f;f=Math.floor(280*Math.random());}x=x==0?159:x-1;v+=.1;y+=v;r(0,400,0,'#08c','#0cf',280,0,280);r(20,40,y,'#ff0','#fa0',y+40,y);r(x-40,n);r(x-50,20,n-20,'#0f0','#0a0',n+20,n,60);r(x+120,f);r(x+110,20,f-20,'#0f0','#0a0',f+20,f,60);r(x-40,280-n,n+120);r(x-50,20,n+120,'#0f0','#0a0',n+140,n+100,60);r(x+120,280-f,f+120);r(x+110,20,f+120,'#0f0','#0a0',f+140,f+100,60);if(x==60){s++;}p.fillStyle='#fff';p.fillText(s,120,80);if(x>20&&x<100&&(y<n||y>n+80)||y<0||y>360){clearInterval(b);location.reload();}},15);</script><br>Made by Thomas Kaldahl</body>
또한 DEFLATE와 같은 압축 시스템을 사용하는 것이 바람을 피우고 있습니까?
아래는 DEFLATEd 버전의 ASCII85 코드입니다. 압축 된 코드의 총 개수
는 335 바이트입니다.
Gapon95_Wi'Kf'c (i ## 6'h, + cM \ JZeFO <h; $ W '# A1', RqNigBH02C '# R $ m] <i <X # 6GR`2pE <Ri5mu-n % cVPrsJe : * R ^ pnr9bI @ [DAZnPP02A ^! .. $ MN / @`U7l5gm !! Vr4> A; P? u [Pk8] jCnOP % dIu?`fWql> "tuO4 / KbIWgK; 7 / iJN'f2, hnFg8e. ^ SO * t \ *`, 3JBn6j (f`O #], M0; 5Sa35Zc @ * XaBs @ N %] k \ M76qa [.ie7n (^ * Z5G-lfhUZ3F # '%, X17Pj1u] L) LjpO6XbIl % N3tJhTsab8oV1T (? MC $ mT; 90VMmnfBNKEY (^ 'UV4c? SW': X (! 4, * WCY + f; 19eQ?`FK0I "(uDe : f & XV & ^ Rc + 'SWRIbd8Lj9bG.l (MRUc1G8HoUsn # H \ V (8"Y $ / TT ( ^ kATb (OreGfWH7uIf