Skip to content

Instantly share code, notes, and snippets.

@MinatsuT
Last active February 10, 2020 16:59
Show Gist options
  • Save MinatsuT/4969f47ad66cd230e8684c0158656181 to your computer and use it in GitHub Desktop.
Save MinatsuT/4969f47ad66cd230e8684c0158656181 to your computer and use it in GitHub Desktop.
Calculate coordinates of the i-th pixel of MxM size dither pattern.
'
' ディザパターンの生成 by みなつ
'
option strict
acls
xscreen 128,128
'左上、右下、右上、左下の順のパターン
dim px[4]:copy px,@px:@px:data 0,1,1,0
dim py[4]:copy py,@py:@py:data 0,1,0,1
main
end
'メイン
'--------------------------------------------------
def main
var size=64:gbox 32-1,32-1,32+size,32+size,#green
var i,wt=1000
for i=0 to size*size-1
var x,y:dither size,i out x,y
gpset 32+x,32+y,#red:waitMillis wt:wt=max(1,wt-20):gpset 32+x,32+y,#white
next
end
'サイズ s*s ドットのディザパターンの、i番目のドットの座標を返す
'==================================================
def dither s,i out x,y
x=0:y=0
while 1
s=s/2
if s<1 then break
var bits=i and &b11
inc x,s*px[bits]
inc y,s*py[bits]
i=i>>2
wend
end
'ミリ秒ウェイト
'--------------------------------------------------
def waitMillis w:var ed=millisec+w:while millisec<ed:wend:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment