pouët.net

Go to bottom

Random line of code thread

category: code [glöplog]
Code:mov ax,1015h
Code:void ellipse(int x, int y, int a, int b) { int z, e, t, u, i, j, k, l; t = z = k = 0; e = u = a; i = b; l = j = (a + 1)>>1; for (;;) { point(x + t, y + i); point(x + t, y - i); point(x - t, y + i); point(x - t, y - i); point(x + u, y + k); point(x + u, y - k); point(x - u, y + k); point(x - u, y - k); if (t >= u) return; t++; e += (z<<1) + 1; z++; if (e >= (u<<1)) { e -= (u<<1); u--; j += b; if (j > a) { j -= a; i--; } } l += b; if (l > a) { l -= a; k++; } } }

Not a single * & about 8 new points per iteration (hence, less iterations). May overdraw, however.
added on the 2012-11-19 22:46:25 by Kais Kais
Code:function plasma()
added on the 2012-11-20 04:25:53 by ___ ___
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { unsigned int iter; int x,y,xsize,ysize; if(argc != 2) { return 1; } iter = atoi(argv[1]); ysize = 1 << iter; xsize = 1 << (iter+1); for(y = 0; y < ysize; y++) { for(x = -xsize/2; x < xsize/2; x++) { if(!((y-x)&(y+x))) printf("\\"); else if(!((y-x-1)&(y+x+1))) printf("/"); else printf(" "); } putchar('\n'); } return 0; }

And here's the output for 5:
Code: /\ /\/\ /\ /\ /\/\/\/\ /\ /\ /\/\ /\/\ /\ /\ /\ /\ /\/\/\/\/\/\/\/\ /\ /\ /\/\ /\/\ /\ /\ /\ /\ /\/\/\/\ /\/\/\/\ /\ /\ /\ /\ /\/\ /\/\ /\/\ /\/\ /\ /\ /\ /\ /\ /\ /\ /\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\ /\ /\/\ /\/\ /\ /\ /\ /\ /\/\/\/\ /\/\/\/\ /\ /\ /\ /\ /\/\ /\/\ /\/\ /\/\ /\ /\ /\ /\ /\ /\ /\ /\ /\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\ /\ /\ /\ /\ /\/\ /\/\ /\/\ /\/\ /\ /\ /\ /\ /\ /\ /\ /\ /\/\/\/\ /\/\/\/\ /\/\/\/\ /\/\/\/\ /\ /\ /\ /\ /\ /\ /\ /\ /\/\ /\/\ /\/\ /\/\ /\/\ /\/\ /\/\ /\/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
added on the 2012-11-26 21:41:24 by FreeFull FreeFull
That's funny, just today I found this year old snippet on my drive:

Code: a = '''a = ''{0}'' # /\ # /\/\ def sierp(x): # /\ /\ if x == 1: # /\/\/\/\ yield '/%c' % 92 # /\ /\ else: # /\/\ /\/\ for i in sierp(x-1): # /\ /\ /\ /\ yield i.center(2**x) # /\/\/\/\/\/\/\/\ for i in sierp(x-1): # /\ /\ yield i+i # /\/\ /\/\ # /\ /\ /\ /\ py = a.format("'%s'" % a) # /\/\/\/\ /\/\/\/\ for i,j in zip(py.splitlines(), # /\ /\ /\ /\ sierp(6)): # /\/\ /\/\ /\/\ /\/\ print('%s # %s' % (i[:31],j)) # /\ /\ /\ /\ /\ /\ /\ /\ # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ''' # /\ /\ # /\/\ /\/\ def sierp(x): # /\ /\ /\ /\ if x == 1: # /\/\/\/\ /\/\/\/\ yield '/%c' % 92 # /\ /\ /\ /\ else: # /\/\ /\/\ /\/\ /\/\ for i in sierp(x-1): # /\ /\ /\ /\ /\ /\ /\ /\ yield i.center(2**x) # /\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\ for i in sierp(x-1): # /\ /\ /\ /\ yield i+i # /\/\ /\/\ /\/\ /\/\ # /\ /\ /\ /\ /\ /\ /\ /\ py = a.format("'%s'" % a) # /\/\/\/\ /\/\/\/\ /\/\/\/\ /\/\/\/\ for i,j in zip(py.splitlines(), # /\ /\ /\ /\ /\ /\ /\ /\ sierp(6)): # /\/\ /\/\ /\/\ /\/\ /\/\ /\/\ /\/\ /\/\ print('%s # %s' % (i[:31],j)) # /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


You can guess the output...
added on the 2012-11-26 23:30:24 by algorias algorias
Code:mov word[bp+8],di
Code: else if((diff < 0) && (transform.position.x > lastWaypoint.transform.position.x + 1f))
G0 Z5
added on the 2012-12-02 16:46:04 by FunGas FunGas
Code:jsr (CODELOCATION+(Precalc-BOOT)).w
added on the 2012-12-03 10:13:21 by StingRay StingRay
Code: if (Screen.showCursor) { Screen.showCursor = false; } else { Screen.showCursor = true; }
Why not just
Code:Screen.showCursor = !Screen.showCursor;
?
added on the 2012-12-06 21:46:13 by FreeFull FreeFull
Code:#define MAKE_ENUM(name, enums, enumOp, strOp) \ struct Enum##name \ { \ enum values { enums(enumOp) }; \ static const char *strings[]; \ }; \ const char *Enum##name::strings[] = { enums(strOp) };

(Fiddling around with X Macros)
For Friday brainfarts (I saw the bad version to often lately, even in my own code)

instead of
Code: function isLegit() { if(_legit === "katze") return true; else return false; }


do
Code: function isLegit() { return (isLegit === "katze") }
added on the 2012-12-06 22:30:17 by mog mog
Whoops missed the underscore in the good version
Code: return (_isLegit === "katze")
added on the 2012-12-06 22:31:28 by mog mog
Code:xchg al,ah
Code: for (int i=0;i<NUM_BUBBLES;i++) { float zPos = 0.0f; float tX=bubbles[i].xsize/2.0f; float tY=bubbles[i].ysize/2.0f; BeginOrtho2D(XRES,YRES); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D,bubbles[i].texture); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0,1.0,1.0,0.5); glPushMatrix(); // Save modelview matrix bubbles[i].y+=bubbles[i].speed; bubbles[i].rot += bubbles[i].rotspeed; if(bubbles[i].y >720) bubbles[i].y = 675; glTranslatef(bubbles[i].x,bubbles[i].y,0.0f); // Position sprite glRotatef(bubbles[i].rot,0.0f,0.0f,1.0f); glBegin(GL_QUADS); // Draw sprite glTexCoord2f(0.0f,0.0f); glVertex3i(-tX, tY,zPos); glTexCoord2f(0.0f,1.0f); glVertex3i(-tX,-tY,zPos); glTexCoord2f(1.0f,1.0f); glVertex3i( tX,-tY,zPos); glTexCoord2f(1.0f,0.0f); glVertex3i( tX, tY,zPos); glEnd(); glPopMatrix(); // Restore modelview matrix glBindTexture(GL_TEXTURE_2D,0); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); EndProjection(); }


yes i am naughty
added on the 2012-12-07 05:51:28 by mudlord mudlord
Code:item.getParentItem() != null ? ((TreeNode)item.getParentItem().getData()).getChildren()[item.getParentItem().indexOf(item)] : ((TreeNode)item.getParent().getData()).getChildren()[item.getParent().indexOf(item)]

also: why u add spaces to my code, renderer?
added on the 2012-12-14 14:49:27 by skomp skomp
Code:10 PRINT CHR$(205.5+RND(1));:GOTO 10

added on the 2013-01-03 22:08:40 by pintcat pintcat
Code:main = putStrLn $ a ++ show a where a = "main = putStrLn $ a ++ show a where a = "
added on the 2013-01-04 02:52:26 by FreeFull FreeFull
Code:# # E F F E C T S # define CLEAR_BUFFERS 10 define FX_GRIDBLOB 20 define FX_TUBE 21 define FX_BALL 22 define FX_CUBES 23 define FX_GREETINGS 24 define FX_COLORBLOCKS 25 define FX_PURPLELINES 26 define FX_CREDITS 27 define FX_CUBE 28 define TRANS_PART1 50 define TRANS_PART2 51 define TRANS_PART3 52 define TRANS_PART4 53 define TRANS_PART5 54 define TRANS_PART6 55 define LOGO_AARDBEI 60 define LOGO_SOUTHSIDE 61 define FLASH_WHITE 80 define FADE_BLACK 82 # # M U S I C # startmusic 00 # # C L E A R S C R E E N # send CLEAR_BUFFERS 00 00 00 255 255 255 run CLEAR_BUFFERS 00 00 50 00 10 # # P A R T - 00 : AARDBEI AND SOUTHSIDE LOGO # run FX_COLORBLOCKS 00 00 01 32 15 send FX_COLORBLOCKS 00 00 00 00 00 01 send FX_COLORBLOCKS 00 05 00 00 00 02 send FX_COLORBLOCKS 00 16 00 00 00 03 send FX_COLORBLOCKS 00 24 00 00 00 04 send FX_COLORBLOCKS 00 32 00 00 00 05 send FX_COLORBLOCKS 00 37 00 00 00 06 send FX_COLORBLOCKS 00 48 00 00 00 07 send FX_COLORBLOCKS 00 56 00 00 00 08 send FX_COLORBLOCKS 01 00 00 00 00 10 run FX_CUBE 01 10 03 00 17 send FX_CUBE 02 50 00 00 00 01 run LOGO_AARDBEI 01 00 03 00 20 send LOGO_AARDBEI 01 16 00 00 00 01 send LOGO_AARDBEI 01 28 00 00 00 02 send LOGO_AARDBEI 01 40 00 00 00 03 send LOGO_AARDBEI 01 52 00 00 00 04 send LOGO_AARDBEI 01 52 00 00 00 05 send LOGO_AARDBEI 02 24 00 00 00 06 send LOGO_AARDBEI 01 00 00 00 00 30 send LOGO_AARDBEI 01 05 00 00 00 30 send LOGO_AARDBEI 01 16 00 00 00 30 send LOGO_AARDBEI 01 24 00 00 00 30 send LOGO_AARDBEI 01 32 00 00 00 30 send LOGO_AARDBEI 01 37 00 00 00 30 send LOGO_AARDBEI 01 48 00 00 00 30 send LOGO_AARDBEI 01 56 00 00 00 30 send LOGO_AARDBEI 02 00 00 00 00 30 send LOGO_AARDBEI 02 05 00 00 00 30 send LOGO_AARDBEI 02 16 00 00 00 30 send LOGO_AARDBEI 02 24 00 00 00 30 send LOGO_AARDBEI 02 32 00 00 00 30 send LOGO_AARDBEI 02 37 00 00 00 30 send LOGO_AARDBEI 02 48 00 00 00 30 send LOGO_AARDBEI 02 52 00 00 00 10 run LOGO_SOUTHSIDE 03 00 03 63 20 send LOGO_SOUTHSIDE 03 01 00 00 00 01 send LOGO_SOUTHSIDE 03 52 00 00 00 10 # # P A R T - 01 : THE BLOB THING # send CLEAR_BUFFERS 04 00 00 00 00 00 run TRANS_PART1 04 00 06 33 20 send TRANS_PART1 04 28 00 00 00 01 send TRANS_PART1 06 13 00 00 00 02 send TRANS_PART1 06 24 00 00 00 03 run FX_GRIDBLOB 04 00 06 33 15 send FX_GRIDBLOB 04 01 00 00 00 01 send FX_GRIDBLOB 06 20 00 00 00 02 send FX_GRIDBLOB 06 22 00 00 00 03 # # P A R T - 02 : THE EXPLODING BALL # run TRANS_PART2 06 33 08 16 20 send TRANS_PART2 06 43 00 00 00 01 send TRANS_PART2 07 04 00 00 00 02 send TRANS_PART2 07 16 00 00 00 03 send TRANS_PART2 07 28 00 00 00 04 run FX_BALL 07 24 07 37 15 send FX_BALL 07 37 00 00 00 01 run FX_BALL 07 37 08 16 25 send FX_BALL 08 00 00 00 00 02 # # P A R T - 03 : THE TUBE THING # run TRANS_PART3 08 16 11 00 20 run FX_TUBE 08 32 10 48 15 send TRANS_PART3 08 16 00 00 00 01 send TRANS_PART3 08 32 00 00 00 02 send TRANS_PART3 08 48 00 00 00 30 send TRANS_PART3 09 00 00 00 00 31 send TRANS_PART3 09 16 00 00 00 32 send TRANS_PART3 09 32 00 00 00 33 send TRANS_PART3 09 48 00 00 00 34 send TRANS_PART3 10 00 00 00 00 35 send TRANS_PART3 10 16 00 00 00 36 send TRANS_PART3 10 32 00 00 00 03 send TRANS_PART3 10 48 00 00 00 04 # # P A R T - 04 : THE CUBES # run TRANS_PART4 11 00 15 00 20 send TRANS_PART4 11 26 00 00 00 01 send TRANS_PART4 14 40 00 00 00 02 run FX_CUBES 11 40 15 00 15 send FX_CUBES 14 00 00 00 00 01 run FADE_BLACK 14 30 15 00 17 # # P A R T - 05 : THE CREDITS # run TRANS_PART5 15 00 17 00 20 send TRANS_PART5 15 18 00 00 00 01 send TRANS_PART5 15 38 00 00 00 02 send TRANS_PART5 16 32 00 00 00 03 run FX_CREDITS 16 00 18 00 25 send FX_CREDITS 16 32 00 00 00 01 # # P A R T - 06 : THE GREETINGS # run TRANS_PART6 17 00 24 00 20 send TRANS_PART6 22 00 00 00 00 01 run FX_GREETINGS 17 00 24 00 25 send FX_GREETINGS 17 40 00 00 00 01 send FX_GREETINGS 18 12 00 00 00 02 send FX_GREETINGS 18 38 00 00 00 03 send FX_GREETINGS 18 58 00 00 00 04 send FX_GREETINGS 19 34 00 00 00 05 send FX_GREETINGS 20 04 00 00 00 06 send FX_GREETINGS 20 36 00 00 00 07 send FX_GREETINGS 21 06 00 00 00 08 send FX_GREETINGS 21 34 00 00 00 09 send FX_GREETINGS 22 00 00 00 00 10 send FX_GREETINGS 22 10 00 00 00 11 run FADE_BLACK 22 40 24 00 30 # # E X I T # quit 22 60
added on the 2013-01-04 09:08:29 by Rob Rob
Code: static_cast<Demo*>(context)->addScene("build", new Build()); static_cast<Demo*>(context)->addScene("feed", new Feed()); static_cast<Demo*>(context)->addScene("start", new Start()); static_cast<Demo*>(context)->addScene("tausta", new Tausta());
added on the 2013-01-04 13:31:32 by Preacher Preacher
10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10
love it!
Yuppz, but you could also have posted the link.

10print.org
added on the 2013-01-12 23:04:25 by wix wix
Code:unsigned abs(int x) { return (((int)x)>>31)^(x - (((unsigned)x)>>31)); } /* (int) & (unsigned) because compiler specific */
Not patented.
added on the 2013-01-24 21:18:18 by Kais Kais

login

Go to top