Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the related Operation of computer Graphics based on python win32setpixel api

Shulou Source: shulou.com Published: 2022-06-02 07:25:51 09月19日 Update

This article introduces the relevant knowledge of "how to realize the operation of computer graphics based on python win32setpixel api". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Scan line filling process

Clipping process (the polygon is cropped in real time according to the mouse position, and the blue on the right is the cropped figure)

Why did you choose win32 api to draw?

The reason for choosing win32 is that I want to do something different. I prefer to draw an image directly on the monitor and look more geek than using D3 or Echarts as a webGL implementation. This also led to the screencap software can not capture, can only use the mobile phone to record?

Why choose python instead of C++?

Mainly python can do a management of memory, C++ directly adjust this underlying interface will damage the memory, causing the computer to become particularly stuck. If you don't believe it, you can compile and run this code on your computer for 2 minutes and try it. If your computer doesn't explode, you have money.

# include / / Gmail + a.cpp-o a.exe-lgdi32 & & a.exevoid bresenham (int x0 abs int x1) {int dx = abs (x1-x0); int dy = abs (y1-y0) Int sx = x0room300: continue ionome0 while (Maps [LX + I] [YBN 1] = 0): if (Maps [LX + I] [YBN 1] = = 1): stack.append ((lx+i) 1) break iTunes 1 ionome0 while (Maps [RX-I] [YBN 1] = 0): if (Maps [RX-I Must1] [YBY 1] = = 1): stack.append ((rx-i) 1) break iPerform1 if ymurf 1-dy: err-= dy x0 + = sx if e2 < dx: err + = dx y0 + = sydef draw_rectangle (x0, y0, x1, y1): bresenham (x0, y0, x1, y0pr 0xffff) bresenham (x1, y0, x1, y1, Y1mem0xffff) bresenham (x1, y1, x0, y1m0xffffff) bresenham (x0, y1, x0 Y0re0xffffff) def draw_polygon (points): for i in range (len (points)): X0 = points [I] [0] y0 = points [I] [1] x1 = points [(I + 1)% len (points)] [0] y1 = points [(I + 1)% len (points)] [1] bresenham (x0, y0, x1) Y1points 0x00ff00) def draw_polygon_black (points): for i in range (len (points)): X0 = points [I] [0] y0 = points [I] [1] x1 = points [(I + 1)% len (points)] [0] y1 = points [(I + 1)% len (points)] [1] bresenham (x0, y0, x1, y1line 0x000000) # whether line segments intersect def IsRectCross (p1x, p1y, p2x, p2y, Q1x Q1Y, Q2x, Q2Y): return min (p1x dint p2x)

Tags: Algorithm polygon code seed process selection computer vertex run graphics Scanline display part face operation computer complexity one line intersection position Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia MariaDB Xiaomi macOS