Created
February 9, 2020 16:26
-
-
Save MinatsuT/d0ec1593b9f5863a01276f638e98b92c to your computer and use it in GitHub Desktop.
[WIP]Cloud generator for PiSTARTER
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
' | |
' 丸を組み合わせた雲の生成 by みなつ | |
' | |
option strict | |
acls | |
var sw,sh,aspect | |
xscreen out sw,sh,aspect | |
var center_x=sw/2 | |
var center_h=sh/2 | |
var size=32 '雲のひとつの丸の直径 | |
var def_shadow=0 '陰部分のSPEDFの番号 | |
var def_bright=1 '光が当たっている部分のSPEDFの番号 | |
spInit 'スプライトの初期化 | |
backcolor rgb(0,128,256) | |
while 1 | |
spclr | |
makeCloud | |
wait 60*2 | |
wend | |
end | |
'雲のまるいスプライトの作成 | |
'================================================== | |
def spInit | |
sppage 0 | |
var xofs,r=size/2,c | |
'陰部分の丸 | |
xofs=size*0 | |
c=rgb(255-32,255-16,255) | |
gcircle xofs+r,r,r-1,c | |
gpaint xofs+r,r,c | |
spdef def_shadow, 0,0, size,size, size/2,size | |
'光が当たっている部分のの丸 | |
xofs=size*1 | |
c=rgb(250,250,250) | |
var d=r/8 | |
var dr=sqr(d*d+d*d) | |
gcircle xofs+r-d,r-d,r-1-dr,c | |
gpaint xofs+r-d,r-dr,c | |
spdef def_bright, xofs,0, size,size, size/2,size | |
end | |
'雲を作成 | |
'================================================== | |
def makeCloud | |
var dx=rand(-size*0.2,size*0.2) 'direction:雲の伸びる方向 | |
var dd=size*0.8 'direction deviation:雲の伸びる方向のゆらぎ幅 | |
var cw=size*rand(3,5) 'cloud width:雲の幅 | |
var xofs=0,height=0 | |
var i | |
for i=0 to 20 | |
dec cw,size*rand(0.3,0.7) '雲の幅を縮める | |
if cw<=0 then break | |
inc xofs,dx+dd*rand(-1,1) '雲を横にずらす | |
'陰部分の配置 | |
var x | |
for x=-cw to cw step size/2 | |
put center_x+xofs+x,height,def_shadow, 1001 | |
next | |
'光が当たっている部分の配置 | |
for x=-cw to cw | |
var p=lerp(-cw/2,cw/2, x, 100,0) '光が当たっている部分がつづく確率:100%〜0% | |
if rnd(100)>p then break '光っている部分終了 | |
put center_x+xofs+x,height,def_bright, 1000 | |
inc x,size*rand(0.3,0.6) | |
next | |
inc height,size*rand(0.3,0.5) '雲の高さを一段上げる | |
next | |
end | |
'雲を配置 | |
'-------------------------------------------------- | |
def put x,height,sp_def,z | |
var sp=spset(sp_def) | |
spofs sp, x,center_h-height,z | |
end | |
'範囲指定ランダム | |
'-------------------------------------------------- | |
def rand(minV,maxV) | |
return minV+rndf()*(maxV-minV) | |
end | |
'in0〜in1の範囲の数値xを、out0〜out1の範囲に変換する | |
'-------------------------------------------------- | |
def lerp(in0,in1, x, out0,out1) | |
var inRange=in1-in0, outRange=out1-out0 | |
var outMin=min(out0,out1), outMax=max(out0,out1) | |
return max(outMin,min(outMax,out0+outRange/inRange*(x-in0))) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment