-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tkInter Canvas Antialiasing hack! #986
Comments
@Harvie And how can this be applied? |
If it's just for display, then I think it's superfluous, because you need to see what will be done. |
i've already applied it in my commit
it does not affect milling or precision
It will not affect your ability to see details (which is quite bad in bCNC anyway). Currently the view of bCNC is far from accurate. It approximates arcs using lines, etc... But missing antialiasing is one of the reasons why you can't see lines accurately. Read something on the topic if you need. However my eyes hurt from non-antialiased lines, so i've added this, because it was simple to do. However this was just cheap simple fix until we move to OpenGL #591 |
Just for reference if someone is looking for Tkinter Canvas antialiasing: ANTIALIAS_CHEAP = True
class CNCCanvas(Canvas, object):
#Calculate arguments for antialiasing
def antialias_args(self, args, winc=0.5, cw=2):
nargs = {}
#set defaults
nargs['width'] = 1
nargs['fill'] = "#000"
#get original args
for arg in args:
nargs[arg] = args[arg]
if nargs['width'] == 0:
nargs['width'] = 1
#calculate width
nargs['width'] += winc
#calculate color
#cbg = self.winfo_rgb(CANVAS_COLOR)
cbg = self.winfo_rgb(self.cget("bg"))
cfg = list(self.winfo_rgb(nargs['fill']))
#print cbg, cfg
cfg[0] = (cfg[0] + cbg[0]*cw)/(cw+1)
cfg[1] = (cfg[1] + cbg[1]*cw)/(cw+1)
cfg[2] = (cfg[2] + cbg[2]*cw)/(cw+1)
nargs['fill'] = '#%02x%02x%02x' % (cfg[0]/256, cfg[1]/256, cfg[2]/256)
#nargs['fill'] = '#AAA'
#print cfg, nargs['fill']
return nargs
#Override alias method if antialiasing enabled:
if ANTIALIAS_CHEAP:
def create_line(self, *args, **kwargs):
nkwargs = self.antialias_args(kwargs)
super(CNCCanvas, self).create_line(*args, **nkwargs)
return super(CNCCanvas, self).create_line(*args, **kwargs) |
Also, tkinter canvas antialiasing is enabled on OSX. |
What are you refering to? I am not aware the tkinter canvas has antialiasing... And this hack was not huge success, especialy in terms of performance. bCNC canvas needs complete rewrite to C. |
I've figured little hack to do antialiasing in tkinter canvas (which is otherwise known to not be able to do antialiasing by itself):
5px:
![image](https://user-images.githubusercontent.com/276504/46249712-e9ce8b80-c42d-11e8-9278-c0c882e5a3d4.png)
1px:
![image](https://user-images.githubusercontent.com/276504/46249715-fd79f200-c42d-11e8-8305-5815d2b0fb54.png)
It's not extremely smooth subpixel antialiasing, but i think it's much easier on eyes!
All we have to do is override tkinter Canvas methods like create_line() or create_oval() to do this.
Only problem is that we have to calculate right color somehow. That can be done like this:
The text was updated successfully, but these errors were encountered: