Why my code dont work /u/Mother-Newspaper-504 Python Education

Im trying to make an marching squares algorithm in python and doesnt give any errors but it does not work as it supposed to too. i cant find anything to fix it,(i asked chatgpt too for help). Please help me

import pygame, sys

from pygame.locals import QUIT

import random

import numpy as np

pygame.init()

res = 20

dheigth = 600

dwidth = 1000

rows = dheigth // res + res * 2

cols = dwidth // res + res * 2

def drawl(st, en):

pygame.draw.line(display, (255, 255, 255), st, en)

FPS = pygame.time.Clock()

display = pygame.display.set_mode((dwidth, dheigth))

display.fill((128, 128, 128))

pygame.display.set_caption(‘Marching Squares’)

def mainrunner():

grid = [[random.randint(0, 1) for __ in range(cols)] for __ in range(rows)]

for n in range(rows – res):

for m in range(cols – res):

color = grid[n][m] * 255

print(color)

x, y = m * res-res, n * res-res

a = [x + int(res * 0.5),y]

b = [x + res,y + int(res * 0.5)]

c = [x + int(res * 0.5),y + res]

d = [x,y + int(res * 0.5)]

ab = grid[n + int(res * 0.5)][m]

bb = grid[n + res][m + int(res * 0.5)]

cb = grid[n + int(res * 0.5)][m + res]

db = grid[n][m + int(res * 0.5)]

state = ab * 8 + bb * 4 + cb * 2 + db * 1

print(ab,bb,cb,db)

if state == 1:

drawl(c,d)

elif state == 2:

drawl(b,c)

elif state == 3:

drawl(b,d)

elif state == 4:

drawl(a,b)

elif state == 5:

drawl(a,d)

drawl(b,c)

elif state == 6:

drawl(a,c)

elif state == 7:

drawl(a,d)

elif state == 8:

drawl(a,d)

elif state == 9:

drawl(a,c)

elif state == 10:

drawl(a,b)

drawl(c,d)

elif state == 11:

drawl(a,b)

elif state == 12:

drawl(b,d)

elif state == 13:

drawl(b,c)

elif state == 14:

drawl(c,d)

mainrunner()

#pygame.draw.circle(display, (color, color, color), (m * res, n * res),2)

while True:

FPS.tick(30)

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

pygame.display.flip()

submitted by /u/Mother-Newspaper-504
[link] [comments]

​r/learnpython Im trying to make an marching squares algorithm in python and doesnt give any errors but it does not work as it supposed to too. i cant find anything to fix it,(i asked chatgpt too for help). Please help me import pygame, sys from pygame.locals import QUIT import random import numpy as np pygame.init() res = 20 dheigth = 600 dwidth = 1000 rows = dheigth // res + res * 2 cols = dwidth // res + res * 2 def drawl(st, en): pygame.draw.line(display, (255, 255, 255), st, en) FPS = pygame.time.Clock() display = pygame.display.set_mode((dwidth, dheigth)) display.fill((128, 128, 128)) pygame.display.set_caption(‘Marching Squares’) def mainrunner(): grid = [[random.randint(0, 1) for __ in range(cols)] for __ in range(rows)] for n in range(rows – res): for m in range(cols – res): color = grid[n][m] * 255 print(color) x, y = m * res-res, n * res-res a = [x + int(res * 0.5),y] b = [x + res,y + int(res * 0.5)] c = [x + int(res * 0.5),y + res] d = [x,y + int(res * 0.5)] ab = grid[n + int(res * 0.5)][m] bb = grid[n + res][m + int(res * 0.5)] cb = grid[n + int(res * 0.5)][m + res] db = grid[n][m + int(res * 0.5)] state = ab * 8 + bb * 4 + cb * 2 + db * 1 print(ab,bb,cb,db) if state == 1: drawl(c,d) elif state == 2: drawl(b,c) elif state == 3: drawl(b,d) elif state == 4: drawl(a,b) elif state == 5: drawl(a,d) drawl(b,c) elif state == 6: drawl(a,c) elif state == 7: drawl(a,d) elif state == 8: drawl(a,d) elif state == 9: drawl(a,c) elif state == 10: drawl(a,b) drawl(c,d) elif state == 11: drawl(a,b) elif state == 12: drawl(b,d) elif state == 13: drawl(b,c) elif state == 14: drawl(c,d) mainrunner() #pygame.draw.circle(display, (color, color, color), (m * res, n * res),2) while True: FPS.tick(30) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.flip() submitted by /u/Mother-Newspaper-504 [link] [comments] 

Im trying to make an marching squares algorithm in python and doesnt give any errors but it does not work as it supposed to too. i cant find anything to fix it,(i asked chatgpt too for help). Please help me

import pygame, sys

from pygame.locals import QUIT

import random

import numpy as np

pygame.init()

res = 20

dheigth = 600

dwidth = 1000

rows = dheigth // res + res * 2

cols = dwidth // res + res * 2

def drawl(st, en):

pygame.draw.line(display, (255, 255, 255), st, en)

FPS = pygame.time.Clock()

display = pygame.display.set_mode((dwidth, dheigth))

display.fill((128, 128, 128))

pygame.display.set_caption(‘Marching Squares’)

def mainrunner():

grid = [[random.randint(0, 1) for __ in range(cols)] for __ in range(rows)]

for n in range(rows – res):

for m in range(cols – res):

color = grid[n][m] * 255

print(color)

x, y = m * res-res, n * res-res

a = [x + int(res * 0.5),y]

b = [x + res,y + int(res * 0.5)]

c = [x + int(res * 0.5),y + res]

d = [x,y + int(res * 0.5)]

ab = grid[n + int(res * 0.5)][m]

bb = grid[n + res][m + int(res * 0.5)]

cb = grid[n + int(res * 0.5)][m + res]

db = grid[n][m + int(res * 0.5)]

state = ab * 8 + bb * 4 + cb * 2 + db * 1

print(ab,bb,cb,db)

if state == 1:

drawl(c,d)

elif state == 2:

drawl(b,c)

elif state == 3:

drawl(b,d)

elif state == 4:

drawl(a,b)

elif state == 5:

drawl(a,d)

drawl(b,c)

elif state == 6:

drawl(a,c)

elif state == 7:

drawl(a,d)

elif state == 8:

drawl(a,d)

elif state == 9:

drawl(a,c)

elif state == 10:

drawl(a,b)

drawl(c,d)

elif state == 11:

drawl(a,b)

elif state == 12:

drawl(b,d)

elif state == 13:

drawl(b,c)

elif state == 14:

drawl(c,d)

mainrunner()

#pygame.draw.circle(display, (color, color, color), (m * res, n * res),2)

while True:

FPS.tick(30)

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

pygame.display.flip()

submitted by /u/Mother-Newspaper-504
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *