[ / / / / / / / / / / / / / ] [ dir / abdl / acme / animu / hypno / loomis / nep / vg / vore ][Options][ watchlist ]

/prog/ - Programming

Programming board
You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
Password (Randomized for file and post deletion; you may also set your own.)
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): 1462256813384.jpg (37.2 KB, 486x399, 162:133, stamp_sierpinski.jpg) (h) (u)

[–]

be5d46 (7) No.4178[Watch Thread][Show All Posts]

Sierpinski thread.


def sierpinski(depth, marks=[' ','X']):
line = []
for i in range(depth):
line += [0]
line = [1] + [line[j] ^ line[j + 1] for j in range(i)]
print(''.join([marks[l] for l in line]))

sierpinski(2 ** 4)
sierpinski(2 ** 5, ['*', '.'])
sierpinski(2 ** 6, ['.', '#'])

be5d46 (7) No.4179

def sierpinski(depth, marks=[' ','X']):
line = []
for i in range(depth):
line += [0]
line = [1] + [line[j] ^ line[j + 1] for j in range(i)]
print((' '.join([marks[l] for l in line])).center(depth * 2))

sierpinski(2 ** 3)
sierpinski(2 ** 4, ['$', '.'])
sierpinski(2 ** 5, ['.', '#'])


be5d46 (7) No.4189>>4191

File (hide): 1462580248140.png (357.15 KB, 1633x1414, 1633:1414, 2016-05-06-181637_1633x141….png) (h) (u)

For svg, without anything special being done to it, and just dumping it to stdout:


from xml.etree.ElementTree import Element, SubElement, tostring

def makeserp(width, height, x, y, e, recursions):
if recursions == 0:
return
a = (x + (width / 2), y + height)
b = (x + (width / 4), y + (height / 2))
c = (x + (3 * width / 4), y + (height / 2))
tri = (a, b, c)
smalle = SubElement(e, 'polygon')
smalle.attrib = {'style': 'fill:white', 'points': ' '.join(','.join(str(part) for part in point) for point in tri)}
makeserp(width / 2, height / 2, x, y + (height / 2), e, recursions - 1)
makeserp(width / 2, height / 2, x + (width / 2), y + (height / 2), e, recursions - 1)
makeserp(width / 2, height / 2, x + (width / 4), y, e, recursions - 1)


svg = Element('svg')
svg.attrib = {'height': '866', 'width': '1000', 'xmlns': 'http://www.w3.org/2000/svg', 'version': '1.1'}
bigtri = SubElement(svg, 'polygon')
bigtri.attrib = {'style': 'fill:black', 'points': '0,866 1000,866 500,0'}
makeserp(1000, 866, 0, 0, svg, 8)
print(str(tostring(svg), 'utf-8'))

The image is at the 8 levels of recursion.


be5d46 (7) No.4191

>>4189

Nice nice.


be5d46 (7) No.4320

File (hide): 1468333068839.png (6.74 KB, 512x512, 1:1, sfc_sierpinski.png) (h) (u)

Sierpinski, you say? Fine, I'll fill up this square.


@ addtest
def sfc_sierpinski (self):
delta = {
# quarters
'u': (2, 1), 'd': (2, 3),
'l': (1, 2), 'r': (3, 2),

# halves
"UR": (1, 0), "UL": (0, 0),
"DL": (0, 1), "DR": (1, 1)
}

reduce = {
"UR": "drul", "UL": "ruld",
"DL": "uldr", "DR": "ldru"
}
terminal = {
key: tuple (delta [ch] for ch in val)
for key, val in reduce.items ()
}

expand = {
"UR": ("UR", "DR", "UR", "UL"),
"UL": ("UL", "UR", "UL", "DL"),
"DL": ("DL", "UL", "DL", "DR"),
"DR": ("DR", "DL", "DR", "UR")
}

places = {
"UR": ("DL", "DR", "UR", "UL"),
"UL": ("DR", "UR", "UL", "DL"),
"DL": ("UR", "UL", "DL", "DR"),
"DR": ("UL", "DL", "DR", "UR")
}
wind = {
key: tuple (delta [x] for x in val)
for key, val in places.items ()
}

size = 512
draw = self.makedraw (size, size)
Tests.sfc_sierpinski_work (
draw, expand, wind, terminal,
0, 0, size, "UR", 5)
return draw

@ staticmethod
def sfc_sierpinski_work (draw, expand, wind, terminal, x, y, size, var, level):
ps = Tests.sfc_sierpinski_points (
expand, wind, terminal, x, y, size, var, level)
pit = iter (ps)
p0 = p = next (pit)

for q in pit:
draw.line (p [0], p [1], q [0], q [1])
p = q

draw.line (p [0], p [1], p0 [0], p0 [1])

@ staticmethod
def sfc_sierpinski_points (expand, wind, terminal, x, y, size, var, level):
if level == 0:
s14 = size // 4
delta = terminal [var]
return [(x + dx * s14, y + dy * s14) for dx, dy in delta]

symbols = expand [var]
delta = wind [var]
level -= 1
s12 = size // 2

l = [
Tests.sfc_sierpinski_points (
expand, wind, terminal,
x + d [0] * s12, y + d [1] * s12,
s12, sym, level
) for d, sym in zip (delta, symbols)
]

l0 = l [0]
l1 = l [1:]
half = (4 ** level) * 2
l0it = iter (l0)

return itertools.chain (
itertools.islice (l0it, half),
itertools.chain.from_iterable (l1),
l0it
)


be5d46 (7) No.4598>>4602

Made a solution with love2d and lua


require "math"

function love.load()
love.window.setMode(800, 800, {msaa = 4});
function sierpinski (Width, Height, x, y, iteration, maxiterations)
local triangleLength = Width / (2 ^ (iteration+1));
local triangleHeight = (math.sin(1.04719755) * triangleLength);

local a = {x + triangleLength, y};
local b = {x + (triangleLength/2), (y + triangleHeight)}
local c = {x + (triangleLength/2) + triangleLength, (y + triangleHeight)};

love.graphics.polygon("fill", a[1], 800-a[2], b[1], 800-b[2], c[1], 800-c[2])

local i = iteration+1;
if maxiterations > iteration then
sierpinski(Width, Height, x , y , i, maxiterations);
sierpinski(Width, Height, b[1], b[2], i, maxiterations);
sierpinski(Width, Height, a[1], a[2], i, maxiterations);
end
end
end

function love.draw()
love.graphics.scale(0.9,0.9);
love.graphics.translate(46, -50);
love.graphics.setColor(255,255,255);
love.graphics.polygon("fill",0,800,800,800,400,800-(math.sin(1.0472)*800)); -- 1.0472 is 60 degrees in radians
love.graphics.setColor(0,0,0);
sierpinski(800, 800, 0, 0, 0, 7);
end


be5d46 (7) No.4602

>>4598

forgot pic


ece7d1 (1) No.4839>>5198

File (hide): f557ea96b331dc6⋯.png (762.21 KB, 1061x1500, 1061:1500, image.png) (h) (u)


a16012 (4) No.4845

File (hide): 0ee9ff84fdd518a⋯.png (44.55 KB, 729x729, 1:1, image.png) (h) (u)


a16012 (4) No.4848>>5198

File (hide): e8b0d30d98c8809⋯.png (532.64 KB, 1040x1304, 130:163, image.png) (h) (u)


a16012 (4) No.4859>>5198

File (hide): 8a15330085df7a3⋯.png (1 MB, 848x1076, 212:269, image.png) (h) (u)


a16012 (4) No.4866

File (hide): 295133b9393860b⋯.png (616.4 KB, 729x729, 1:1, image.png) (h) (u)


5c98c3 (10) No.4869

File (hide): 6766ebeaa24ac72⋯.png (2.11 MB, 1296x1296, 1:1, image.png) (h) (u)


50e034 (2) No.4870>>4871

I'm not sure what yuri has to do with Sierpinski, but I like it.


5c98c3 (10) No.4871>>4872

>>4870

>>Sierpinski carpet

>>adorable rugmunchers

>I'm not sure what yuri has to do with Sierpinski


50e034 (2) No.4872>>4873

>>4871

It's all so clear now.


bcd259 (1) No.4873

File (hide): 6b79c1d04318574⋯.png (38.64 KB, 443x375, 443:375, at last I truly see.png) (h) (u)


5c98c3 (10) No.4875

File (hide): a771ed8d0e704a3⋯.png (36.69 KB, 701x701, 1:1, image.png) (h) (u)


5c98c3 (10) No.4878

File (hide): bd4b1c7cd02f7ed⋯.png (70.24 KB, 701x701, 1:1, image.png) (h) (u)

gradient path


5c98c3 (10) No.4882

File (hide): 8687a4fa7806df7⋯.png (77.27 KB, 1296x1296, 1:1, image.png) (h) (u)


5c98c3 (10) No.4885

File (hide): 6cf6c852b8df232⋯.png (107.58 KB, 512x512, 1:1, image.png) (h) (u)

added the white stop to get quarters


5c98c3 (10) No.4890>>5198

File (hide): 221f8684f3a5a36⋯.png (1.06 MB, 1000x758, 500:379, image.png) (h) (u)

U+2665


5c98c3 (10) No.4892

File (hide): b5c31cdd70cd687⋯.png (42.58 KB, 729x729, 1:1, image.png) (h) (u)

random choice between stamps


5c98c3 (10) No.4895

File (hide): 013e518acc30437⋯.png (1.3 MB, 1296x1296, 1:1, image.png) (h) (u)

fixed cycle of random alternates


5c98c3 (10) No.4911

File (hide): 1017bceb23a50d2⋯.png (1.73 MB, 1296x1296, 1:1, image.png) (h) (u)

text stamp with fill and outline

random choice

U+2601 U+2660 U+2691


f1f910 (6) No.4947

File (hide): 9dbf39f4c0be5a8⋯.png (1.2 MB, 729x729, 1:1, k.png) (h) (u)

fixed rotation cycle


f1f910 (6) No.4983

File (hide): 88e679230231c58⋯.png (1.39 MB, 729x729, 1:1, image.png) (h) (u)

fixed color cycle


f1f910 (6) No.5014

File (hide): 4a80094e8bfe31f⋯.png (1.33 MB, 512x512, 1:1, image.png) (h) (u)


565eb3 (3) No.5029>>5030

File (hide): 202eed3a3a05f3a⋯.png (25.66 KB, 638x166, 319:83, sierpinski.png) (h) (u)

File (hide): 63425380d61952a⋯.png (44.24 KB, 669x392, 669:392, ffsierpinski.png) (h) (u)

outputs Sierpinski using rule 90

One outputs as ascii, other outputs as farbfeld to stdout (save as .ff)


565eb3 (3) No.5030>>5031

File (hide): 399e7690b30614d⋯.png (696.23 KB, 10000x5000, 2:1, test.png) (h) (u)

>>5029

The output of the second one after being converted from farbfeld to png. (A bit fucked cuz of its massive size and grey pixels)


f1f910 (6) No.5031>>5032

>>5030

>information content: 1 bit per pixel

>PNG type: 16-bit RGBA -> 64 bits per pixel

One wonders why. After farbfeld to png, it could be converted to 1-bit grayscale black-and-white png. While deflate takes care of the file size, the memory use is still there when viewing.

My toaster gave up the ghost opening your image.


565eb3 (3) No.5032

File (hide): cf4c6cc6ea287c8⋯.png (31.05 KB, 128x114, 64:57, smug.png) (h) (u)

>>5031

In my defense, there aren't many tools to convert ff to png and I used the standard one.


f1f910 (6) No.5051>>5066

File (hide): 4b4109c27017f39⋯.png (5.4 KB, 333x778, 333:778, cells-333-777-1-r90.png) (h) (u)

Did the rule90 thing to see whether pycairo will export its 1-bit packed FORMAT_A1 surfaces as 1-bit grayscale PNGs. Turns out write_to_png does produce grayscale in this case but uses 8-bit samples, so 7 bits wasted. So I wrote my own quick hack of an exporter to output 1-bit grayscale PNGs anyway. Here's a sample run with one seed, and also some saner image dimensions, because unlike smug anime girls I don't have a terabyte of RAM.


import functools
import sys

import lib.pong as pong


class Show:
@ staticmethod
def null (row):
pass

@ staticmethod
def text (symbols):
def show (row):
print (''.join (map (
lambda x: symbols [x], row)))
return show


class NextRow:
@ staticmethod
def r90 (rowin, rowout):
last = len (rowin) - 1

rowout [0 ] = rowin [1]
rowout [last] = rowin [last - 1]

for k in range (1, last):
rowout [k] = rowin [k - 1] ^ rowin [k + 1]

@ staticmethod
def r90wrap (rowin, rowout):
last = len (rowin) - 1

rowout [0 ] = rowin [1] ^ rowin [last ]
rowout [last] = rowin [0] ^ rowin [last - 1]

for k in range (1, last):
rowout [k] = rowin [k - 1] ^ rowin [k + 1]


class Seed:
@ staticmethod
def middle (row):
w = len (row)

row [w // 2] = 1

@ staticmethod
def uniform (count):
n = count + 1

def seed (row):
w = len (row)

for k in range (1, n):
row [k * w // n] = 1

return seed


def runcells (width, steps, seed_func, next_func, show_func):
row = bytearray (width)
row2 = row [:]

seed_func (row)
show_func (row)

for k in range (0, steps):
next_func (row, row2)
row, row2 = row2, row
show_func (row)


def textrun (data):
dots = ['.', 'O']

width = data ["width" ]
steps = data ["steps" ]
seed_func = data ["seed_func"]
next_func = data ["next_func"]
show_func = Show.text (dots)
# show_func = Show.null

runcells (width, steps, seed_func, next_func, show_func)


def pngrun (data):
out = "temp/cells-{}-{}-{}-{}.png".format (
data ["width"], data ["steps"],
data ["seeds"], data ["rule" ])
print (out)

with open (out, "wb") as f:
data ["outfile"] = f
pngrun_open (data)
del data ["outfile"]

def pngrun_open (data):
pw = pong.Write

width = data ["width" ]
steps = data ["steps" ]
outfile = data ["outfile"]

pw.beforeIDATs (outfile,
width, steps + 1,
color = "GRAY", bits = 1)

wdiv8, wmod8 = divmod (width, 8)
rowbytes = wdiv8 + (0 if wmod8 == 0 else 1)
packed = bytearray (rowbytes)

r2i = pw.rowsToIDATs (
outfile, rowbytes, steps + 1)
proc = r2i ["processor"]

seed_func = data ["seed_func"]
next_func = data ["next_func"]
show_func = process_row_func (
proc, packed, wdiv8, wmod8)

runcells (width, steps, seed_func, next_func, show_func)

proc.flush ()
pw.afterIDATs (outfile)

def packrow (row, packed, wdiv8, wmod8):
srcoff = 0
reduce = functools.reduce
range8 = range (8)

def redstep (acc, item):
return acc | (row [srcoff + item] << (7 - item))

for k in range (wdiv8):
packed [k] = reduce (redstep, range8, 0)
srcoff += 8

if wmod8 > 0:
packed [wdiv8] = reduce (redstep, range (wmod8), 0)

def process_row_func (processor, packed, wdiv8, wmod8):
def work (row):
packrow (row, packed, wdiv8, wmod8)
processor.process (packed)
return work


def main_argv (argv, handler):
width = int (argv [0])
steps = int (argv [1])
seeds = int (argv [2])
rule = argv [3]

data = {
"width" : width,
"steps" : steps,
"seeds" : seeds,
"rule" : rule,
"seed_func": Seed.uniform (seeds),
"next_func": getattr (NextRow, rule),
}

handler (data)

def main ():
argv = sys.argv [1:]
# handler = textrun
handler = pngrun

main_argv (argv, handler)

if __name__ == "__main__": main ()


f1f910 (6) No.5052

File (hide): 6b82debbcd03017⋯.png (5.78 KB, 333x778, 333:778, cells-333-777-1-r90wrap.png) (h) (u)

r90wrap for comparison


4ba389 (1) No.5066

File (hide): cb863efd3ad1674⋯.jpg (71.32 KB, 560x577, 560:577, smug-asuka.jpg) (h) (u)

>>5051

>unlike smug anime girls I don't have a terabyte of RAM.

Sorry to hear fam.

Seriously tho, the pic does load on my machine, just not particularly quickly.

I was considering using PNG directly but it's fucking cancer to work with :/


666fc8 (1) No.5198

>>4839

>>4848

>>4859

>>4890

Now cracks a noble board.---Good night, sweet carpet munchers, And flights of angels sing thee to thy rest!—

Why does the BO come hither?


b3d8fb (1) No.5199

this is (((gay)))




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
36 replies | 27 images | 11 UIDs | Page ?
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / abdl / acme / animu / hypno / loomis / nep / vg / vore ][ watchlist ]