def tmove(self): if (random.randint(0, 1) == 0): self.sininc += random.randint(0, 10) / 10. # 0.25 else: self.sininc -= random.randint(0, 10) / 10. # 0.25 mr = random.randint(0, 10) / 50. + 0.1 if (self.dirx): self.tx += self.incx else: self.tx -= self.incx if (self.diry): self.ty += self.incy else: self.ty -= self.incy ytr = random.randint(2, 20) if (self.typo == 0): yty = math.sin(self.alf) / ytr elif (self.typo == 1): yty = math.cos(self.alf) / ytr elif (self.typo == 2): yty = self.alf / (math.cos(mr) + self.sininc) else: yty = math.atan(self.alf + 1) # --- MAIN MOVE EQUATIONS --- if (self.tx < width and self.tx > 0): # print("in-x") self.tx -= (-1) * (math.sin(self.alfx * self.sininc)) else: Tarray[self.idnum].recolor() r_elem = random.randint(0, len(graVits) - 1) x_elem = graVits[r_elem] self.tx = x_elem[0] # random.randint(0, width) self.ty = x_elem[1] if (self.ty < height and self.ty > 0): self.ty -= (-1) * (math.cos(self.alf * self.sininc)) else: Tarray[self.idnum].recolor() r_elem = random.randint(0, len(graVits) - 1) y_elem = graVits[r_elem] self.ty = y_elem[1] # random.randint(0, width) self.tx = y_elem[0] aar = random.randint(1, 50) / 50. if (self.alfadir): self.alf = int(self.alf + aar) % 255 else: self.alf = int(self.alf - aar) % 255 mycolor = (self.rr, self.gg, self.bb, self.alf) gfxdraw.pixel(surf, int(self.tx), int(self.ty), mycolor) xcoord = (400, 400) ycoord = (400, 400)
def bresenham(x1, y1, x2, y2): #menentukan length atau jarak if x1 > x2: x, y = x2, y2 length = x1 else: x, y = x1, y1 length = x2 dx = (x2 - x1) dy = (y2 - y1) p = 2 * (dy - dx) gfxdraw.pixel(screen, x, y, white) #perloopingan sampai nilai ketemu for i in range(length): if p < 0: x += 1 p = p + 2 * dy gfxdraw.pixel (screen, x, y, white) else: x += 1 y += 1 p = p + 2 * (dy - dx) gfxdraw.pixel (screen, x, y, white) pygame.display.flip()
def print_square1(x1,y1,x2, y2): m_new = 2 * (y2 - y1) slope_error_new = m_new - (x2 - x1) y=y1 for x in range(x1,x2+1): print(x ,y ) # Add slope to increment angle formed slope_error_new =slope_error_new + m_new # Slope error reached limit, time to # increment y and update slope error. if (slope_error_new >= 0): y=y+1 slope_error_new =slope_error_new - 2 * (x2 - x1) # Plot intermediate points # putpixel(x,y) is used to print pixel # of line in graphics print(x,",",y,"\n") t = "x: "+str(x)+" y: "+str(y)+"\n" gfxdraw.pixel(screen,x,y,white) file1.write(t)
def run(self): mandelbrot_points = get_points(100) progress = 0 x, y = 0, 0 while self.is_running: if self.flush and progress == 0.0: screen.fill(0) for event in pygame.event.get(): self.handle_event(event) for y in range(win_size_y): x, i, n, z = next(mandelbrot_points) gfxdraw.pixel(screen, x, y, self.get_color(i, n, z, x, y)) if self.show_progress_bar: gfxdraw.line(screen, x + 1, 0, x + 1, win_size_y, RED) filter_text = ', '.join( self.filters[filter_index].name for filter_index in self.active_filters ) if not filter_text: filter_text = 'none' progress = ((x * y) / (win_size_x * win_size_y)) * 100 pygame.display.set_caption( f"Mandelbrot - {progress:0>2.0f}% done - filters: {filter_text}" ) pygame.display.update() clock.tick(-1)
def draw_universe_background(self, surface: 'pygame.Surface', *args) -> None: """ Draw stars as background. :param surface: Surface to draw :param args: Optional arguments """ t = self.menu.get_counter_attribute('t', self.menu.get_clock().get_time() * 0.001) # Draw nebulas for nebula in self.nebulas: nebula.draw(surface) nebula.rotate(nebula.get_angle() + nebula.get_attribute('delta_angle')) # Draw stars for s in self.stars: x, y, flicker = s c = int(127 * max(0.5, 1 + math.cos(t + flicker))) gfxdraw.pixel(surface, x, y, (c, c, c)) # Draw shooting stars for s in self.shooting_stars: x, y, dx, dy, theta, speed, flicker = s c = int(150 * max(0.1, max(math.sin(0.1 * t + 1.5 * math.pi + flicker), math.cos(0.1 * t + flicker)))) x = int(x) y = int(y) gfxdraw.line(surface, x, y, x + dx, y + dy, (c, c, c)) # Update velocity + window constraints s[0] = (s[0] + speed * math.cos(theta)) % self.menu.get_width() s[1] = (s[1] + speed * math.sin(theta)) % self.menu.get_height() # This line forces cache update for submenus that call this method self.menu.force_surface_cache_update()
def plot(x, y, colour): psize = 16 col = (((colour >> 4) & 0x3) << 6, ((colour >> 2) & 0x3) << 6, (colour & 0x3) << 6) for yy in range(psize): for xx in range(psize): gfxdraw.pixel(screen, x * psize + xx, y * psize + yy, col)
def draw_mandel(window, sequence, max_iter, re_min = -2, re_max = 1, im_min = -1, im_max = 1): """ Computes the mandelbrot set on a given part of the complex plane. """ screen_array = [[0] * height for _ in range(width)] # For every pixel of the screen for x in range(width): for y in range(height): # Compute the associated complex number c = convert_pixel_complex(x, y, re_min, re_max, im_min, im_max) # Then, compute max_iter element of sequence function with # c as initial value z = c for i in range(max_iter): z = sequence(z, c) # If we detect that the sequence diverges if (z.real * z.real + z.imag * z.imag) > 4: # We draw a pixel which intensity corresponds to # the number of iterations we ran before detecting # the divergence. color_ratio = int((i * 255.) / max_iter) gfxdraw.pixel(window, x, y, Color(color_ratio, color_ratio, color_ratio, 255)) screen_array[x][y] = color_ratio break else: # If we did not detect a divergence in max_iter steps, # we consider that the sequence does not diverge and # draw a black pixel. gfxdraw.pixel(window, x, y, Color(0,0,0,255)) pygame.display.flip() return screen_array
def __init__(self, x, y, rr, gg, bb): self.tx = x self.ty = y self.rr = rr self.gg = gg self.bb = bb gfxdraw.pixel(surf, x, y, (rr, gg, bb, 255))
def displayRGB(red, green, blue): for i in range(red.shape[0]): for j in range(red.shape[1]): color = (int(red[i, j]), int(green[i, j]), int(blue[i, j])) gfxdraw.pixel(screen, j, i, color) pygame.display.update()
def tmove(self): self.sininc += random.randint(0, 10) / 10. # 0.25 self.tx += self.incx self.ty += self.incy if (self.tx < width): self.tx += self.incx + self.dirx - math.sin(self.alf) # math.atan(self.alf / random.randint(1, 2)) else: self.tx = random.randint(1, width) if (self.ty < height): self.ty += self.incy + self.diry + math.sin(self.alf) # math.tan(self.alf / random.randint(1, 2)) else: self.ty = random.randint(1, height) if (self.alfadir): self.alf += self.alfx / 10. else: self.alf -= self.alfx / 10. mycolor = (self.rr, self.gg, self.bb, int(self.alf) % 200) # if(self.alf >= 1 and self.alf <= 255): # mycolor = (self.rr, self.gg, self.bb, int(self.alf / 2)) # mycolor = (200, 200, 200, 0.1) gfxdraw.pixel(surf, int(self.tx), int(self.ty), mycolor) # pyg.draw.circle(surf, mycolor, (int(self.tx), int(self.ty)), 1, 0) # xcoord = (int(self.tx), int(self.ty)) # xcoord = (400, 400) xcoord = (self.tx + self.sininc, self.tx) ycoord = (self.tx, self.ty - self.sininc)
def main(): pygame.init() size = (400, 400) screen = pygame.display.set_mode(size) white = pygame.Color('white') done = False clock = pygame.time.Clock() fps = 40 points = definePoints(50, 400) # Draw the points before the while loop starts. No need to draw them again. for point in points: # Use different random colors for the points. color = (random.randrange(256), random.randrange(256), random.randrange(256)) for p in point[3]: # Draw the citizen points. # Add the offset of the citizen to the positions of the points. gfxdraw.pixel(screen, point[1] + p[0], point[2] + p[1], color) # draw white wherever there's a point. gfxdraw.pixel(screen, point[1], point[2], white) while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True clock.tick(fps) pygame.display.flip()
def DrawPoint(self, p, size, color): gfxdraw.pixel( self.app.surface, p[0] / self.physics_scale * self.app.render_scale[0], p[1] / self.physics_scale * self.app.render_scale[1], (color[0] * 255, color[1] * 255, color[2] * 255), )
def BLine(X1, Y1, X2, Y2): # X1 = input("Enter the x-coordinate of the start point X1: ") # Y1 = input("Enter the y-coordinate of the start point Y1: ") # X2 = input("Enter the x-coordinate of the end point X2: ") # Y2 = input("Enter the y-coordinate of the end point Y2: ") dX = X2 - X1 dY = Y2 - Y1 P0 = 2 * dY - dX Pk = P0 Xk = X1 Yk = Y1 while Xk <= X2: print(Xk, Yk) gfxdraw.pixel(screen, Xk, 400 - Yk, color) Xk = Xk + 1 if Pk < 0: Yk = Yk Pk = Pk + 2 * dY elif Pk > 0: Yk = Yk + 1 Pk = Pk + 2 * dY - 2 * dX pygame.display.flip()
def draw_circle1(self, radius, center=(0, 0), color=GREEN): points = self.bresenhams_circle(radius, center) for pt in points: print('ploting point : ', pt) gfxdraw.pixel(self.DISPSURF, pt[0], pt[1], color) pygame.display.flip()
def __init__(self, x, y, rr, gg, bb): self.tx = x self.ty = y self.rr = rr self.gg = gg self.bb = bb self.alf = random.randint(2, 50) self.alfx = random.random() + 0.1 rrx = random.randint(0, 1) rry = random.randint(0, 1) if (rrx): self.dirx = 1 else: self.dirx = -1 if (rry): self.diry = 1 else: self.diry = -1 alfy = random.randint(0, 1) if (alfy): self.alfadir = 1 else: self.alfadir = -1 gfxdraw.pixel(surf, x, y, (rr, gg, bb, self.alf)) self.incx = random.random() self.incy = random.random()
def trianglefill(vera,verb,verc,zvp,zprp,phi,theta,surface,color,z_buffer,light): vca = rot(vera, phi, theta) vcb = rot(verb, phi, theta) vcc = rot(verc, phi, theta) #Obtain the triangle normal i.e A,B,C of Ax+By+Cz+D=0 para1=vcb-vca para2=vcc-vca para3= np.squeeze(np.asarray(para1)) para4= np.squeeze(np.asarray(para2)) #Checked normal,works ! normal= np.cross(para3[:3],para4[:3]) unit_size= (normal[0]*normal[0]+normal[1]*normal[1]+normal[2]*normal[2])**0.5 unit_normal = normal/unit_size cen = centroid(vera,verb,verc) L=light-cen L_size=(L[0]*L[0]+L[1]*L[1]+L[2]*L[2])**0.5 L_unit= L/L_size I=np.dot(unit_normal,L_unit) I = abs(I) col_list = list(color) for i in range(3): col_list[i] *= I color = tuple(col_list) #d=-(Ax+By+Cz), Put point vca d=-(normal[0]*vca[0]+normal[1]*vca[1]+normal[2]*vca[2]) pa=per(vca,zvp,zprp) pb=per(vcb,zvp,zprp) pc=per(vcc,zvp,zprp) minx=int(min(pa[0],min(pb[0],pc[0]))) miny=int(min(pa[1],min(pb[1],pc[1]))) maxx=int(max(pa[0],max(pb[0],pc[0]))) maxy=int(max(pa[1],max(pb[1],pc[1]))) for i in range(miny,(maxy+1)): if (i<0): continue if (i >= 300): break j = range (max(minx,0),min(400,(maxx+1))) v = np.zeros((4, len(j))) v[0, :] = j v[1, :] = i v[3, :] = 1 pin = pointinside_triangle(v, pa, pb, pc) inside = False for e, j in enumerate(range(max(minx,0.0),(maxx+1))): if(j >= 400): break if pin[e]: inside=True D= zprp-zvp xp = j - 200 yp= i- 150 F = normal[0]*xp + normal[1]*yp - normal[2]*D point_z = ((normal[0]*xp+normal[1]*yp)*zprp+d*D)/F #gfxdraw.pixel(surface,j,i,color) if (point_z < z_buffer[i][j]): z_buffer[i][j] = point_z gfxdraw.pixel(surface,j,i,color) elif (inside): break for i in range(300): for j in range(400): z_buffer[i][j]=99999999.0
def fill_circle(self, x, y, fillcol, boundcol): currcol = self.display.get_at((x, y)) if currcol != boundcol and currcol != fillcol: gfxdraw.pixel(self.display, x, y, fillcol) self.fill_circle(x + 1, y, fillcol, boundcol) self.fill_circle(x, y + 1, fillcol, boundcol) self.fill_circle(x - 1, y, fillcol, boundcol) self.fill_circle(x, y - 1, fillcol, boundcol)
def update(self, surface): if self.fast: self.fastMove() elif not self.fast: self.slowMove() pgf.pixel(surface, self.x, self.y, self.color)
def draw_circle(self, radius, center=(0, 0), color=RED): points = self.bresenhams_circle(radius, center) for pt in points: print('ploting point : ', pt) gfxdraw.pixel(self.DISPSURF, pt[0], pt[1], color) pygame.display.flip( ) #Update the full display Surface to the screen
def mandelbrot(): for x in range(W): for y in range(H): z = complex(-3 + 4*x/W, -1 + 2*y/H) if check(z)[0]: gfxdraw.pixel(pygame.display.get_surface(), x, y, (255, 255, 255)) else: gfxdraw.pixel(pygame.display.get_surface(), x, y, (255-check(z)[1]*8, 255-check(z)[1]*8, 255-check(z)[1]*8))
def boundary_fill(self, x, y, fillcol, boundcol): currcol = self.display.get_at((x, y)) if currcol != boundcol and currcol != fillcol: gfxdraw.pixel(self.display, x, y, fillcol) self.boundary_fill(x + 1, y, fillcol, boundcol) self.boundary_fill(x, y + 1, fillcol, boundcol) self.boundary_fill(x - 1, y, fillcol, boundcol) self.boundary_fill(x, y - 1, fillcol, boundcol)
def plot(x, y, r, g, b): xsize = 2 ysize = 1 #col = (r << 4, g << 4, b << 4) col = (r, g, b) for yy in range(ysize): for xx in range(xsize): gfxdraw.pixel(screen, x * xsize + xx, y * ysize + yy, col)
def draw_pixel(self, left, right, y, fillcol): for x in range(round(left), round(right) + 1): gfxdraw.pixel( self.display, x, y, fillcol, )
def draw_map(screen, map_data): screen.fill(BLACK) for y in range(256): for x in range(256): intensity = map_data[y][x] gfxdraw.pixel(screen, x, y, (intensity, intensity, intensity)) pygame.display.flip()
def drawRings(self, window, numRings, center, color): radius = 2 numRings = numRings*2 gfxdraw.pixel(window, center[0], center[1], color) while numRings > 0: numRings -= 1 radius += 1 if numRings%2: gfxdraw.circle(window, center[0],center[1], radius, color)
def main(): cnt = 0 global count, px, py, number_of_points, div, pt Color_line = (randint(0, 255), randint(0, 255), randint(0, 255)) screen = p.display.set_mode((width, height)) p.display.set_caption("square") vertex = [] while True: for events in p.event.get(): if events.type == p.QUIT: p.quit() gfxdraw.pixel(screen, px, py, Color_line) p.display.flip() t = randint(0, number_of_points - 1) #---------------------------------PATTERN 1------------------------------------------------------ # while abs(pt-t)>2: # t=randint(0,number_of_points-1) # px=(px+points[t][0])//div # py=(py+points[t][1])//div # pt=t # p.time.Clock().tick(50000) #---------------------------------PATTERN 2------------------------------------------------------ # while abs(pt-t)>=2: # t=randint(0,number_of_points-1) # px=(px+points[t][0])//div # py=(py+points[t][1])//div # pt=t # p.time.Clock().tick(50000) #---------------------------------PATTERN 3(Little complex)------------------------------------------------------ if len(vertex) == 0: vertex.append(t) cnt += 1 if len(vertex) == 1: vertex.append(t) cnt += 1 if len(vertex) >= 2 and vertex[0] == vertex[1]: while abs(pt - t) == 1 or abs(pt - t) == 3: t = randint(0, number_of_points - 1) vertex.pop(0) vertex.append(t) elif cnt == 2: vertex.pop(0) vertex.append(t) px = (px + points[t][0]) // div py = (py + points[t][1]) // div pt = t p.time.Clock().tick(50000)
def move(antt): antt.Forward() if equal(checkpixel(antt.getLoc()[0], antt.getLoc()[1]), white): gfxdraw.pixel(screen, antt.getLoc()[0], antt.getLoc()[1], [0, 0, 0]) antt.Right() elif equal(checkpixel(antt.getLoc()[0], antt.getLoc()[1]), black): gfxdraw.pixel(screen, antt.getLoc()[0], antt.getLoc()[1], [255, 255, 255]) antt.Left()
def build_surface(terrain, colorscale): """Return a pygame Surface using <colorscale> as color scale. Suppose <terrain> is already normalized.""" S = len(terrain) surface = pygame.Surface((S, S)) for x in range(S): for y in range(S): color = colorscale.get(terrain[x][y]) gfxdraw.pixel(surface, x, y, color) return surface
def shufflepixel(surface): for x in range (1,int(WIDTH/4)-1): for y in range(1,int(HEIGHT/4)-1): # try: newpixel = [a + b for a, b in zip((x,y), randdirection())] color = surface.get_at(newpixel) # except: # color = surface.get_at((x,y)) gfx.pixel(surface, x, y, color)
def drawPoints(points, window): window.fill((255, 255, 255)) for p in points: randColor = (randint(0, 255), randint(0, 255), randint(0, 255)) randPoint = (randint(0, 255), randint(0, 255), randint(0, 255)) for individual in p[2]: gfxdraw.pixel(window, p[0] + individual[0], p[1] + individual[1], randColor) pygame.draw.circle(window, randPoint, (p[0], p[1]), 4, 1)
def pixelcolor(surface): color = (150,150,150) # Loop through each pixel, column by column for x in range (0,int(WIDTH/4)): for y in range(0,int(HEIGHT/4)): # Separate Function does color modifications based off whatever color = decidecolor(surface, color, x, y) # Draw color onto pixel at position x, y gfx.pixel(surface, x, y, color) next
def Draw(self, screen): for x in range(0, self.CYCLES): for y in range(0, self.CYCLES): x_pixel = x * self.WIDTH_BLOCKS + random.randint( 0, self.WIDTH_BLOCKS) y_pixel = y * self.HEIGHT_BLOCKS + random.randint( 0, self.HEIGHT_BLOCKS) gfxdraw.pixel(screen, x_pixel, y_pixel, self.CalculateRay(screen, x_pixel, y_pixel)) pygame.display.flip()
def draw(self, dtool): if self._obstacle is not None: dtool.set_stroke_width(0); dtool.set_color(self._obstacle.fillcolor); self._env._draw_obstacle(dtool, self._obstacle) dtool.set_color(self._path_color); dtool.set_stroke_width(2); dtool.draw_lineseries(self._visited_points[-1500:]) # Draw circle representing radar range #dtool.draw_circle(np.array(self.location, dtype=int), int(self._sensors['radar'].radius)) # Draw the robot's sensor observations dtool.set_color((0xaa, 0x55, 0xdd)) dtool.set_stroke_width(2); self._draw_pdf(dtool, self._sensors['radar'].scan(self._sensors['gps'].location())) dtool.set_color(self._path_color) # Draw circle to indicate a collision if self._drawcoll > 0: dtool.set_color((255, 80, 210)) dtool.set_stroke_width(3); dtool.draw_circle(np.array(self.location), 12) self._drawcoll = self._drawcoll - 1 # Draw static mapper data if 'mapdata' in self._nav_algo.debug_info.keys() and isinstance(dtool, DrawTool.PygameDrawTool): pix_arr = PG.surfarray.pixels2d(dtool._pg_surface); pix_arr[self._nav_algo.debug_info['mapdata'] == 0b00000101] = 0xFF5555; del pix_arr # Draw predicted obstacle locations if "future_obstacles" in self._nav_algo.debug_info.keys(): if self._nav_algo.debug_info["future_obstacles"]: for fff in self._nav_algo.debug_info["future_obstacles"]: for x,y in fff.keys(): gfxdraw.pixel(dtool._pg_surface.screen, x, y, (255,0,0)) # Draw planned path waypoints if "path" in self._nav_algo.debug_info.keys(): if self._nav_algo.debug_info["path"]: points = [x.data[:2] for x in self._nav_algo.debug_info["path"]] dtool.set_color((30,30,60)); dtool.set_stroke_width(0); for x,y in points: dtool.draw_circle((x,y), 3) # Draw RRT if "rrt_tree" in self._nav_algo.debug_info.keys() and self._nav_algo.debug_info["rrt_tree"]: dtool.set_color((255,0,0)); dtool.set_stroke_width(0.11); for node in self._nav_algo.debug_info['rrt_tree'].toListValidNodes(): if node.parent is None or node is None: continue dtool.draw_line((node.data[0],node.data[1]), (node.parent.data[0],node.parent.data[1]))
def draw_function(self, f, color = (200, 200, 200)): size_x, size_y = self.size axes_center_x, axes_center_y = self.axes_center zoom = self.zoom for x_ in range(size_x): x = float(x_ - axes_center_x)/zoom y = f(x) y_ = axes_center_y - int(y*zoom) if (y_ > 0) and (y_ < size_y) and (x_ > 0) and (x_ < size_x): gfxdraw.pixel(self.windowSurface, x_, y_, color) pygame.display.update()
def bresenham_line(screen, x1, y1, x2, y2, color): x = int(x1) y = int(y1) gfxdraw.pixel(screen, x, y, color) dx = x2-x1 dy = y2-y1 p = 2*dy - dx while(dx == 0 and y<=y2): gfxdraw.pixel(screen, x, y, color) y += 1 while(x<=x2 and y<=y2 and dx != 0): if(p<0): gfxdraw.pixel(screen, x+1, y, color) p = p + 2*dy x+=1 else: gfxdraw.pixel(screen, x, y, color) p = p + 2*dy - 2*dx x+=1 y+=1
def trianglefill_no_rot(vera,verb,verc,zvp,zprp,phi,theta,surface,color,z_buffer): vca = vera.ver() vcb = verb.ver() vcc = verc.ver() #Obtain the triangle normal i.e A,B,C of Ax+By+Cz+D=0 para1=vcb-vca para2=vcc-vca para3= np.squeeze(np.asarray(para1)) para4= np.squeeze(np.asarray(para2)) #Checked normal,works ! normal= np.cross(para3[:3],para4[:3]) #d=-(Ax+By+Cz), Put point vca d=-(normal[0]*vca[0]+normal[1]*vca[1]+normal[2]*vca[2]) pa=per(vca,zvp,zprp) pb=per(vcb,zvp,zprp) pc=per(vcc,zvp,zprp) minx=int(min(pa[0],min(pb[0],pc[0]))) miny=int(min(pa[1],min(pb[1],pc[1]))) maxx=int(max(pa[0],max(pb[0],pc[0]))) maxy=int(max(pa[1],max(pb[1],pc[1]))) for i in range(miny,(maxy+1)): if (i<0): continue if (i >= 300): break j = range (max(minx,0),min(400,(maxx+1))) v = np.zeros((4, len(j))) v[0, :] = j v[1, :] = i v[3, :] = 1 pin = pointinside_triangle(v, pa, pb, pc) inside = False for e, j in enumerate(range(max(minx,0.0),(maxx+1))): if(j >= 400): break if pin[e]: inside=True D= zprp-zvp xp = j - 200 yp= i- 150 F = normal[0]*xp + normal[1]*yp - normal[2]*D point_z = ((normal[0]*xp+normal[1]*yp)*zprp+d*D)/F #gfxdraw.pixel(surface,j,i,color) if (point_z < z_buffer[i][j]): z_buffer[i][j] = point_z gfxdraw.pixel(surface,j,i,color) elif (inside): break for i in range(300): for j in range(400): z_buffer[i][j]=99999999.0
def draw_grid(self, display): spacing = 100 if self._slice_rect is None: return left = self._slice_rect.left top = self._slice_rect.top start_left = int(left + left % spacing) start_top = int(top + top % spacing) screen_start = self.convert_world_to_screen((start_left, start_top)) screen_left = screen_start[0] screen_top = screen_start[1] screen_spacing = int(spacing * self.scale) for x in range(screen_left, self.rect.right, screen_spacing): for y in range(screen_top, self.rect.bottom, screen_spacing): gfxdraw.pixel(display.window, x, y, (255, 255, 255))
def process(): # for i in bubbleList: # i.findCollision() for i in bubbleList: i.putCollision() for i in range(windowX): for j in range(windowY): gfxdraw.pixel(window,i,j,(int(collisionArray[i][j])*7,0,0)) if(collisionArray[i][j]-3<3 and collisionArray[i][j]-3 >0):gfxdraw.pixel(window,i,j,(255,255,255)) #bubbleA.drawSimpleCircle() #bubbleB.drawSimpleCircle() pygame.display.flip() collision_initialize()
def draw_mandel(): screen = [[0] * height for i in range(width)] for x in range(width): for y in range(height): c = complex(((x * 3.) / width) - 2, ((y * 2.0) / height) - 1) z = c complex_sequence = set([]) for i in range(maxIter): complex_sequence.add(z) z = z ** 2 + c if (z.real * z.real + z.imag * z.imag) > 4: complex_sequence.add(z) for term in complex_sequence: pixel_x = math.floor(((term.real + 2) * width) / 3.) pixel_y = math.floor(((term.imag + 1) * height) / 2.) if 0 <= pixel_x < width and 0 <= pixel_y < height: screen[int(pixel_x)][int(pixel_y)] += 1 break minimum = screen[0][0] maximum = screen[0][0] for x in range(width): for y in range(height): if screen[x][y] < minimum: minimum = screen[x][y] if screen[x][y] > maximum: maximum = screen[x][y] for x in range(width): for y in range(height): color_value = ((screen[x][y] - minimum) * 255) / (maximum - minimum) gfxdraw.pixel(window, x, y, Color(color_value, color_value, color_value, 255)) print "maximum :", maximum print "minimum :", minimum print "done !" pygame.display.flip()
def line(self, surface, X1, Y1, X2, Y2, color): x1 = copy.copy(X1) y1= copy.copy (Y1) x2 = copy.copy(X2) y2 = copy.copy(Y2) gfxdraw.pixel(surface, x1, y1, color) dx = abs(x2 - x1) dy = abs(y2 - y1) if (x2 > x1): xinc = 1 else: xinc = -1 if (y2 > y1): yinc = 1 else: yinc = -1 x1t = x1 y1t = y1 if (dx > dy): p = 2 * dy - dx k = 0 while k <= dx: x1t += xinc if p < 0: p += 2 * dy else: y1t += yinc p += 2 * dy - 2 * dx gfxdraw.pixel(surface, x1t, y1t, color) k += 1 else: p = 2 * dx - dy k = 0 while k <= dy: y1t += yinc if p < 0: p += 2 * dx else: x1t += xinc p += 2 * dx - 2 * dy gfxdraw.pixel(surface, x1t, y1t, color) k += 1
def draw_mandel(window, sequence_function, width, height, max_iter, threshold): x_ratio = 3. / width y_ratio = 2. / height for x in xrange(width): for y in xrange(height): c = complex((x * x_ratio) - 2, (y * y_ratio) - 1) z = c for i in xrange(maxIter): z = sequence_function(z, c) if (z.real * z.real + z.imag * z.imag) > 4: color_ratio = int((i * 255.) / maxIter) if color_ratio >= threshold: gfxdraw.pixel(window, x, y, Color(0, 0, 0, 255)) else: gfxdraw.pixel(window, x, y, Color(255, 255, 255, 255)) break else: gfxdraw.pixel(window, x, y, Color(255,255,255,255)) pygame.display.flip() pygame.image.save(window, 'render_border.png')
horizon_line = screen_size[1] - 100 ground_color = (210, 180, 140) for background in range(0, numBackgrounds): background_img = pygame.Surface(screen_size).convert() background_img.fill((0, 0, 0)) backgrounds.append(background_img) # fill with stars numStars = 500 for i in range(0, numStars): color = (randrange(50, 255), randrange(50, 255), randrange(50, 255)) x = randrange(0, screen_size[0]) y = randrange(0, horizon_line) gfxdraw.pixel(background_img, x, y, color) # Create the horizon line for i in range(0, screen_size[0]): gfxdraw.pixel(background_img, i, horizon_line, ground_color) # Place buildings numBuildings = 10 for i in range(0, numBuildings): gray_shade = randrange(40, 200) building_color = (gray_shade, gray_shade, gray_shade) # Dimensions of the building - width and height. building_dims = (randrange(20, 50), randrange(10, 150)) # Position of the building
def mid_point_circle(screen, xc, yc, r, color): p=1.25-r x=0 y=r while(x<=y): if(p<0): x=x+1 p=p+2*x+1 else: x=x+1 y=y-1 p=p+2*x-2*y+10 gfxdraw.pixel(screen, xc+x, yc+y, color) gfxdraw.pixel(screen, xc-y, yc-x, color) gfxdraw.pixel(screen, xc+y, yc-x, color) gfxdraw.pixel(screen, xc-y, yc+x, color) gfxdraw.pixel(screen, xc+y, yc+x, color) gfxdraw.pixel(screen, xc-x, yc-y, color) gfxdraw.pixel(screen, xc+x, yc-y, color) gfxdraw.pixel(screen, xc-x, yc+y, color)
def display(self): #pygame.draw.circle(screen, self.colour, (int(self.x), int(self.y)), self.size) gfxdraw.pixel(screen, int(self.x), int(self.y), self.colour)
fileTxt = fileTxt.strip('\r\n') fileTxt = fileTxt.split(" ") if fileTxt[0] not in query.keys(): #imp query[fileTxt[0]] = [] #imp query[fileTxt[0]].append(int(fileTxt[3])) #imp fileTxt = fileO.readline() for key in query.keys(): calculate_p_r_f(key,query[key]) calculate_map() for i in range(10): print query["302"][i],precision["302"][i] print "Average Precision: ",avg_precision["302"],"\n" from pygame import gfxdraw gfxdraw.pixel(surface, x, y, color) def calculate_p_r_f(query,list): global precision global recall global fScore global avg_precision total_relevant_count = 0.0 for i in range(0,len(list)): if list[i]==1: total_relevant_count += 1 #calculating precision and recall and fScore temp_precision = 0.0 temp_recall = 0.0 count = 0
def display(self): gfxdraw.pixel(screen, int(self.x), int(self.z), self.colour)
def drawScreen(self): self.pixels = sorted(self.pixels, key=lambda x: x[3]) for p in self.pixels: gfxdraw.pixel(self.screen, p[0], p[1], p[2])
pixely=0 isJulia=False #Mandelbrot loop \ while not isJulia: multkoeffx = (plotx[1]-plotx[0]) / float(displLengths[0]) multkoeffy = (ploty[1]-ploty[0]) / float(displLengths[1]) x=plotx[0] y=ploty[0] pixelx=0 pixely=0 while y<ploty[1]: while x<plotx[1]: gfxdraw.pixel(surface,int(pixelx-plotx[0]),int(pixely-ploty[0]), (0,0,mandelbrot(complex(x,y),complex(x,y),accuracy))) x+=multkoeffx pixelx+=1 x = plotx[0] pixely+=1 pixelx=0 y+=multkoeffy pygame.display.update() #EVENT HADLER notDone=True isJulia=False while notDone: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit()
'2836670236974546101465599793379853748314378684' '1806593422227898388722980000748404719' ) pygame.init() screen = pygame.display.set_mode(((115*2) + 10, (17*2) + 10)) pygame.display.set_caption('Tupper\'s Self-referential formula') for y in range(k+0,k+17): for x in range(0,106): if tupper(x, y): col = WHITE else: col = BLACK i = 10 + 105 + (105 - x*2) j = 5 + ((y - k)*2) gfxdraw.pixel(screen, i , j , col) gfxdraw.pixel(screen, i + 1, j , col) gfxdraw.pixel(screen, i , j + 1, col) gfxdraw.pixel(screen, i + 1, j + 1, col) pygame.display.flip() while True: for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.dict["key"] == 27): pygame.quit() exit()