Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

My workday

Name: Anonymous 2012-10-11 5:27

I was assigned to some ERP project. That shit is boring as hell so I accidentally opened FIOC interpreter and wasted some time.

Damn I hate enterprise crap.


Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
DreamPie 1.1.1
>>> u = (1,1,1)
>>> v = (2,2,2)
>>> zip(u, v)
0: [(1, 2), (1, 2), (1, 2)]
>>> def dot(u, v):
...     sum(a*b for a, b in zip(u, v))
>>> dot(u, v)
>>> def dot(u, v):
...     return sum(a*b for a, b in zip(u, v))
>>> dot(u, v)
1: 6
>>> def intrsct(ld, so, sr):
...     ld = unit_vec(ld)
...     base = dot(ld, so) # direction . center point
...     discr = dot(ld, so) ** 2 - dot(so, so) + sr ** 2
...     if (discr < 0):
...         return []
...     elif discr == 0:
...         return [x * base for x in ld]
...     dists = [base + math.sqrt(discr), base - math.sqrt(discr)]
...     return [[x * dist for x in ld] for dist in dists]
>>> def unit_vec(u):
...     ulen = dot(u, u)
...     return [float(x) / ulen for x in u]
>>> unit_vec(v)
2: [0.16666666666666666, 0.16666666666666666, 0.16666666666666666]
>>> def unit_vec(u):
...     ulen = math.sqrt(dot(u, u))
...     return [float(x) / ulen for x in u]
>>> import math
>>> unit_vec(v)
3: [0.5773502691896258, 0.5773502691896258, 0.5773502691896258]
>>> intrsct([1, 0, 0], [0, 0, 0], 1.0)
4: [[1.0, 0.0, 0.0], [-1.0, -0.0, -0.0]]
>>> def draw_shit(spheres, rows, cols, camdist=2.0):
...     result = [[0 for i in range(cols)] for j in range(rows)]
...     for row in range(rows):
...         for col in range(cols):
...             y = float(row) / rows - 0.5
...             x = float(col) / cols - 0.5
...             raydir = (x, y, camdist)
...             if any(len(intrsct(raydir, sphere[0], sphere[1])) > 0 for sphere in spheres):
...                 result[y][x] = res
...     return result
>>> spheres = [([0.1, 0, 5], 1)]
>>> rs = draw_shit(spheres, 40, 40)
Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    rs = draw_shit(spheres, 40, 40)
  File "<pyshell#14>", line 9, in draw_shit
    result[y][x] = res
NameError: global name 'res' is not defined
>>> def draw_shit(spheres, rows, cols, camdist=2.0):
...     result = [[0 for i in range(cols)] for j in range(rows)]
...     for row in range(rows):
...         for col in range(cols):
...             y = float(row) / rows - 0.5
...             x = float(col) / cols - 0.5
...             raydir = (x, y, camdist)
...             if any(len(intrsct(raydir, sphere[0], sphere[1])) > 0 for sphere in spheres):
...                 result[y][x] = 1
...     return result
>>> rs = draw_shit(spheres, 40, 40)
Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    rs = draw_shit(spheres, 40, 40)
  File "<pyshell#17>", line 9, in draw_shit
    result[y][x] = 1
TypeError: list indices must be integers, not float
>>> def draw_shit(spheres, rows, cols, camdist=2.0):
...     result = [[0 for i in range(cols)] for j in range(rows)]
...     for row in range(rows):
...         for col in range(cols):
...             y = float(row) / rows - 0.5
...             x = float(col) / cols - 0.5
...             raydir = (x, y, camdist)
...             if any(len(intrsct(raydir, sphere[0], sphere[1])) > 0 for sphere in spheres):
...                 result[row][col] = 1
...     return result
>>> rs = draw_shit(spheres, 40, 40)
>>> len(rs)
5: 40
>>> len(rs[0])
6: 40
>>> for r in rs:
...     print ''.join(r)
Traceback (most recent call last):
  File "<pyshell#23>", line 2, in <module>
    print ''.join(r)
TypeError: sequence item 0: expected string, int found
>>> for r in rs:
...     print ''.join(map(str, r))
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000111111000000000000000
0000000000000000111111111111100000000000
0000000000000011111111111111111000000000
0000000000001111111111111111111100000000
0000000000011111111111111111111110000000
0000000000111111111111111111111111000000
0000000001111111111111111111111111100000
0000000001111111111111111111111111110000
0000000011111111111111111111111111110000
0000000111111111111111111111111111111000
0000000111111111111111111111111111111000
0000000111111111111111111111111111111100
0000001111111111111111111111111111111100
0000001111111111111111111111111111111100
0000001111111111111111111111111111111100
0000001111111111111111111111111111111100
0000001111111111111111111111111111111110
0000001111111111111111111111111111111100
0000001111111111111111111111111111111100
0000001111111111111111111111111111111100
0000001111111111111111111111111111111100
0000000111111111111111111111111111111100
0000000111111111111111111111111111111000
0000000111111111111111111111111111111000
0000000011111111111111111111111111110000
0000000001111111111111111111111111110000
0000000001111111111111111111111111100000
0000000000111111111111111111111111000000
0000000000011111111111111111111110000000
0000000000001111111111111111111100000000
0000000000000011111111111111111000000000
0000000000000000111111111111100000000000
0000000000000000000111111000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
>>> rs = draw_shit(spheres, 40, 60)
>>> for r in rs:
...     print ''.join(map(str, r))
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000011111111110000000000000000000000
000000000000000000000001111111111111111111100000000000000000
000000000000000000001111111111111111111111111100000000000000
000000000000000000111111111111111111111111111111000000000000
000000000000000011111111111111111111111111111111110000000000
000000000000000111111111111111111111111111111111111000000000
000000000000001111111111111111111111111111111111111100000000
000000000000011111111111111111111111111111111111111110000000
000000000000111111111111111111111111111111111111111111000000
000000000001111111111111111111111111111111111111111111100000
000000000011111111111111111111111111111111111111111111110000
000000000011111111111111111111111111111111111111111111110000
000000000111111111111111111111111111111111111111111111111000
000000000111111111111111111111111111111111111111111111111000
000000000111111111111111111111111111111111111111111111111000
000000000111111111111111111111111111111111111111111111111000
000000001111111111111111111111111111111111111111111111111100
000000000111111111111111111111111111111111111111111111111000
000000000111111111111111111111111111111111111111111111111000
000000000111111111111111111111111111111111111111111111111000
000000000111111111111111111111111111111111111111111111111000
000000000011111111111111111111111111111111111111111111110000
000000000011111111111111111111111111111111111111111111110000
000000000001111111111111111111111111111111111111111111100000
000000000000111111111111111111111111111111111111111111000000
000000000000011111111111111111111111111111111111111110000000
000000000000001111111111111111111111111111111111111100000000
000000000000000111111111111111111111111111111111111000000000
000000000000000011111111111111111111111111111111110000000000
000000000000000000111111111111111111111111111111000000000000
000000000000000000001111111111111111111111111100000000000000
000000000000000000000001111111111111111111100000000000000000
000000000000000000000000000011111111110000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
>>> def print_shit():
...     rs = draw_shit(spheres, 40, 60)
...     for r in rs:
...         print ''.join(map(str, r))
>>> def print_shit():
...     rs = draw_shit(spheres, 40, 75)
...     for r in rs:
...         print ''.join(map(str, r))
>>>

Name: 1 2012-10-11 6:38

The rest, i was fucking productive this day.

Yeah, the code is full of duplication and other smells.


>>> def perse(d, n):
...     mul = -2.0 * dot(d, n)
...     return [d[i] + n[i] * mul for i in range(len(d))]
>>> perse((1, 0, 0), (-1, 0.5, 0))
7: [-1.0, 1.0, 0.0]
>>> def lval(scale, intr, indr, n, light):
...     p = perse(unit_vec(indr), unit_vec(n))
...     mag = dot(p, [a - b for a, b in zip(light, intr)])
...     return 0 if mag < 0 else int(mag * scale)
>>> lval(7, (1, 0, 0), (1, 0, 0), (-1, 0.5, 0), (-2, -3, 0))
8: 0
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0.5, 0), (-2, -3, 0))
9: 0
>>> def lval(scale, intr, indr, n, light):
...     p = perse(unit_vec(indr), unit_vec(n))
...     mag = unit_vec(dot(p, [a - b for a, b in zip(light, intr)]))
...     return 0 if mag < 0 else int(mag * scale)
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0.5, 0), (-2, -3, 0))
Traceback (most recent call last):
  File "<pyshell#35>", line 1, in <module>
    lval(700, (1, 0, 0), (1, 0, 0), (-1, 0.5, 0), (-2, -3, 0))
  File "<pyshell#34>", line 3, in lval
    mag = unit_vec(dot(p, [a - b for a, b in zip(light, intr)]))
  File "<pyshell#10>", line 2, in unit_vec
    ulen = math.sqrt(dot(u, u))
  File "<pyshell#5>", line 2, in dot
    return sum(a*b for a, b in zip(u, v))
TypeError: zip argument #1 must support iteration
>>> def lval(scale, intr, indr, n, light):
...     p = perse(unit_vec(indr), unit_vec(n))
...     mag = dot(p, unit_vec([a - b for a, b in zip(light, intr)]))
...     return 0 if mag < 0 else int(mag * scale)
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0.5, 0), (-2, -3, 0))
10: 0
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0.5, 0), (2, 3, 0))
11: 398
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (-1, 0, 0))
12: 700
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (-1, 0.1, 0))
13: 699
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (-1, 1, 0))
14: 626
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (0, 1, 0))
15: 494
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (1, 1, 0))
16: 0
>>> lval(700, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (0.01, 1, 0))
17: 492
>>> lval(7, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (0.01, 1, 0))
18: 4
>>> lval(7, (1, 0, 0), (1, 0, 0), (-1, 0, 0), (-1, 1, 0))
19: 6
>>> def vecsub(u, v):
...     return [a-b for a,b in zip(u, v)]
...
... def draw_shit(spheres, rows, cols, camdist=2.0, light=(5, 0.5, 0)):
...     result = [[0 for i in range(cols)] for j in range(rows)]
...     sphere = spheres[0]
...     for row in range(rows):
...         for col in range(cols):
...             y = float(row) / rows - 0.5
...             x = float(col) / cols - 0.5
...             raydir = (x, y, camdist)
...             intrs = [i for i in intrsct(raydir, sphere[0], sphere[1])
...                      if dot(vecsub(i, sphere[0]), raydir) < 0]
...             if len(intrs) > 0:
...                 intr = intrs[0]
...                 result[row][col] = lval(8, intr, raydir,
...                         [a-b for a, b in ziip(intr, sphere[0])], light)
...     return result
>>> vecsub
20: <function vecsub at 0x025A4E70>
>>> draw_shit
21: <function draw_shit at 0x025A4DF0>
>>> print_shit()
Traceback (most recent call last):
  File "<pyshell#50>", line 1, in <module>
    print_shit()
  File "<pyshell#28>", line 2, in print_shit
    rs = draw_shit(spheres, 40, 75)
  File "<pyshell#47>", line 17, in draw_shit
    [a-b for a, b in ziip(intr, sphere[0])], light)
NameError: global name 'ziip' is not defined
>>> def vecsub(u, v):
...     return [a-b for a,b in zip(u, v)]
...
... def draw_shit(spheres, rows, cols, camdist=2.0, light=(5, 0.5, 0)):
...     result = [[0 for i in range(cols)] for j in range(rows)]
...     sphere = spheres[0]
...     for row in range(rows):
...         for col in range(cols):
...             y = float(row) / rows - 0.5
...             x = float(col) / cols - 0.5
...             raydir = (x, y, camdist)
...             intrs = [i for i in intrsct(raydir, sphere[0], sphere[1])
...                      if dot(vecsub(i, sphere[0]), raydir) < 0]
...             if len(intrs) > 0:
...                 intr = intrs[0]
...                 result[row][col] = lval(8, intr, raydir,
...                         [a-b for a, b in zip(intr, sphere[0])], light)
...     return result

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List