Created
February 18, 2011 15:14
-
-
Save ynkdir/833797 to your computer and use it in GitHub Desktop.
vim-paint-screen-test.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!gvim -u | |
set nocompatible | |
if has('vim_starting') | |
set loadplugins | |
call feedkeys(":source " . expand('<sfile>:t') . "\<CR>") | |
finish | |
endif | |
function! s:init_screen(width, height) | |
" XXX: linux only | |
set guifont=Monospace\ 1 | |
set linespace=-999 | |
set guioptions= | |
set buftype=nofile | |
let &lines = a:height | |
let &columns = a:width | |
for y in range(a:height) | |
call append(0, repeat(".", a:width)) | |
for x in range(a:width) | |
if 0 | |
execute printf('syn match Screen%dx%d /\%%%dc\%%%dl./', x, y, x + 1, y + 1) | |
else | |
" optimized version (It seems that nextgroup has limit about 10000). | |
let attr = '' | |
if x != a:width - 1 | |
let attr .= printf(' nextgroup=Screen%dx%d skipnl', x + 1, y) | |
endif | |
if x != 0 | |
let attr .= ' contained' | |
endif | |
execute printf('syn match Screen%dx%d /\%%%dc\%%%dl./ %s', x, y, x + 1, y + 1, attr) | |
endif | |
endfor | |
endfor | |
call cursor(1, 1) | |
endfunction | |
function! s:set_pixel(x, y, r, g, b) | |
execute printf('hi Screen%dx%d guifg=#%02x%02x%02x guibg=#%02x%02x%02x', a:x, a:y, a:r, a:g, a:b, a:r, a:g, a:b) | |
endfunction | |
function! s:main() | |
let width = 100 | |
let height = 100 | |
call s:init_screen(width, height) | |
for x in range(width) | |
for y in range(height) | |
let r = float2nr(255.0 * x / width) | |
let g = float2nr(255.0 * y / height) | |
let b = float2nr(255.0 * x / width) | |
call s:set_pixel(x, y, r, g, b) | |
endfor | |
endfor | |
endfunction | |
try | |
call s:main() | |
endtry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment