;################################################################# ;# Chapter One: Setting up the GUI as well as the blank Bitmap24 # ;################################################################# Local $1=1024,$2=768,$NZ[$1+1][$2+1],$WB=$NZ,$WX=$WB,$WY=$WB,$Col=$WB,$CC=$WB,$FC,$SX,$SY,$v=GUICreate("Procedural Sunset",$1,$2),$22=GUICtrlCreateLabel("Initializing",0,380,1024,16,1),$23=GUICtrlCreateLabel("",312,404,400,2)+0*GUICtrlSetBkColor(-1, 0x808080),$24 = GUICtrlCreateLabel("", 312, 404, 2, 2)-2+GUICtrlSetBkColor(-1,0xFF00)+GUISetState() Local $c=Mod($1,4),$d=Binary(""),$25=Binary("0x424D00000000000000003600000028000000"&A(Hex($1,8))&A(Hex($2,8))&"0100180000000000"&A(Hex(($2)*($1)*3+($2*$c),8))&"00000000000000000000000000000000"),$rowData=Binary(""),$13=Binary("") for $n=1 to $1 $rowData&=Binary("0xFFFFFF") Next $rowData&=$d for $m=1 to $2 $13&=$rowData Next Local $12=$25&$13,$BMP[4]=[$c,$1,$2,DllStructCreate('ubyte['&BinaryLen($12)&']')],$v=DllStructSetData($BMP[3],1, $12)+B()+C()+D()+E()+F(),$out=FileOpen("s.bmp",18),$v=FileWrite($out,DllStructGetData($BMP[3],1))+FileClose($out)+GUICtrlDelete($22)+GUICtrlDelete($24)+GUICtrlDelete($23)+GUICtrlCreatePic("s.bmp",0,0,1024,768) While GUIGetMsg() <> -3 WEnd ;########################################################################## ;# Chapter Two: Calc. effects in the air and draw final image to Bitmap24 # ;########################################################################## Func F() GUICtrlSetData($22,"Calculating Atmosphere") For $y=0 To 767 $k1=(1-Abs(383.5-$y)/384)^5 For $x = 0 To 1023 $k2 = ATan(($x-$SX)/($y-$SY))/6.283186 + 0.25 If $y=$SY Then $k2=0.25 If ($y-$SY) < 0 Then $k2 += 0.5 $k2 = BN($k2 * 512, 0) * 0.03 $k2 = 0.2 - $k2 * $k2 If $k2 < 0 Then $k2 = 0 $s = 50 / Sqrt(($x - $SX) * ($x - $SX) + ($y - $SY) * ($y - $SY)) If $s > 1 Then $s = 1 $c = M(0xFFFFFF, $FC, $k2 * (1 - $s)) $offset = _of($x,$y,$BMP) DllStructSetData($BMP[3],1,dec(StringLeft(Hex(M($c, $Col[$x][$y], $k1),6),2)),$offset+3) DllStructSetData($BMP[3],1,dec(stringmid(Hex(M($c, $Col[$x][$y], $k1),6),3,2)),$offset+2) DllStructSetData($BMP[3],1,dec(StringRight(Hex(M($c, $Col[$x][$y], $k1),6),2)),$offset+1) Next GUICtrlSetPos($24, 312, 404, 300+100*($y/767)) Next EndFunc ;############################################################## ;# Chapter Three: Use color-corrected noise to simulate waves # ;############################################################## Func E() GUICtrlSetData($22, "Calculating Water") Local $x, $y, $x1, $y1, $k, $c, $kx, $sx1, $sy1, $sx2, $sy2 For $y = 768 To 384 Step -1 $k = ($y - 383) * 0.5 $kx = (900 - $y) / 580 For $x = 1024 To 0 Step -1 $sy1 = 64000 / ($y - 380) $sx1 = ($x - 511.5) * $sy1 * 0.002 $sy2 = $sy1 * 0.34 - $sx1 * 0.71 $sx2 = $sx1 * 0.34 + $sy1 * 0.71 $sy1 = $sy2 * 0.34 - $sx2 * 0.21 $sx1 = $sx2 * 0.34 + $sy2 * 0.21 $WB[$x][$y] = BN($sx1, $sy1) - BN($sx2, $sy2) If $x < 1024 And $y < 768 Then $WX[$x][$y] = ($WB[$x + 1][$y] - $WB[$x][$y]) * $k * $kx $WY[$x][$y] = ($WB[$x][$y + 1] - $WB[$x][$y]) * $k $x1 = $x + $WX[$x][$y] If $x1 < 0 Then $x1 = -$x1 ElseIf $x1 > 1023 Then $x1 = 2047 - $x1 EndIf $y1 = 768 - $y + $WY[$x][$y] If $y1 < 0 Then $y1 = 0 ElseIf $y1 > 383 Then $y1 = 383 EndIf $c = M(BC($x1 / 8, $y1 / 48), 0x352520, $kx) $Col[$x][$y] = $c EndIf Next GUICtrlSetPos($24, 312, 404, 250+50*(Abs($y-768)/384)) Next EndFunc ;######################################################### ;# Chapter Four: Calc. sund, halo and the skys' blending # ;######################################################### Func C() GUICtrlSetData($22, "Calculating Sky") Local $x, $y, $c1, $c2, $k, $s Local $sx1, $sy1 $SX = Random(350,675) $SY = 192 + Random(0,157) For $y = 0 To 383 $sy1 = 100000 / (390-$y) For $x = 0 To 1023 $sx1 = ($x - 511.5) * $sy1 * 0.0005 $k = BN($sx1, $sy1) - BN($sx1 * 0.14 + $sy1 * 0.21, $sy1 * 0.14 - $sx1 * 0.21) If $k < -8 Then $k = 0 Else $k = ($k + 8) * 0.02 If $k > 1 Then $k = 1 EndIf $FC = 0x908000 + ($SY + 500) * 0.2 $c1 = M($FC + 25, 0x906050, $y / 384) $c2 = M(0x807080, 0xD0D0D0, $y / 384) $s = 50 / Sqrt(($x - $SX) * ($x - $SX) + ($y - $SY) * ($y - $SY)) If $s > 1 Then $s = 1 $c1 = M(0xFFFFFF, $c1, $s) $Col[$x][$y] = M($c2, $c1, $k) Next GUICtrlSetPos($24, 312, 404, 100 + 100*($y/383)) Next EndFunc ;############################################# ;# Chapter Five: Give it a more natural look # ;############################################# Func D() GUICtrlSetData($22, "Color Correction") For $x = 0 To 127 For $y = 0 To 7 Local $r = 0, $g = 0, $b = 0 For $yy = 0 To 47 For $xx = 0 To 7 $r += BitAND($Col[$xx + $x * 8][$yy + $y * 48], 255) $g += BitAND($Col[$xx + $x * 8][$yy + $y * 48], 0xFF00) $b += Int(BitAND($Col[$xx + $x * 8][$yy + $y * 48], 0xFF0000) / 256) Next Next $CC[$x][$y] = $r / 384 + BitAND(($g / 384), 0xFF00) + BitAND(($b / 384), 0xFF00) * 256 GUICtrlSetPos($24, 312, 404, 200+50*($x/127)) Next $CC[$x][8] = $CC[$x][7] Next EndFunc ;####################################### ;# The End: Various color manipulation # ;####################################### Func BC($x, $y) $ix = Int($x) $SX = $x - $ix $iy = Int($y) $SY = $y - $iy $c0 = $CC[BitAND($ix,127)][Mod($iy,9)] $c1 = $CC[BitAND(($ix+1),127)][Mod($iy,9)] $c2 = $CC[BitAND($ix,127)][Mod(($iy+1),9)] $c3 = $CC[BitAND(($ix+1),127)][Mod(($iy+1),9)] Return BitAND($c0,255)*(1-$SX)*(1-$SY)+BitAND($c1,255)*$SX*(1-$SY)+BitAND($c2,255)*(1-$SX)*$SY+BitAND($c3,255)*$SX*$SY+BitAND(BitAND($c0,0xFF00)*(1-$SX)*(1-$SY)+BitAND($c1,0xFF00)*$SX*(1-$SY)+BitAND($c2,0xFF00)*(1-$SX)*$SY+BitAND($c3,0xFF00)*$SX*$SY,0xFF00)+BitAND(BitAND($c0,0xFF0000)*(1-$SX)*(1-$SY)+BitAND($c1,0xFF0000)*$SX*(1-$SY)+BitAND($c2,0xFF0000)*(1-$SX)*$SY+BitAND($c3,0xFF0000)*$SX*$SY,0xFF0000) EndFunc Func B() ReDim $NZ[512][512] $d = 64 While 1 For $y = 0 To 511 Step 2*$d For $x = 0 To 511 Step 2*$d $NZ[BitAnd(($x+$d), 511)][$y] = ($NZ[$x][$y] + $NZ[BitAnd(($x+$d+$d), 511)][$y]) * 0.5 + $d * (Random(0,1) - 0.5) $NZ[$x][BitAnd(($y+$d), 511)] = ($NZ[$x][$y] + $NZ[$x][BitAnd(($y+$d+$d), 511)]) * 0.5 + $d * (Random(0,1) - 0.5) $NZ[BitAnd(($x+$d), 511)][BitAnd(($y+$d), 511)] = ($NZ[$x][$y] + $NZ[BitAnd(($x+$d+$d), 511)][BitAnd(($y+$d+$d), 511)] + $NZ[$x][BitAnd(($y+$d+$d), 511)] + $NZ[BitAnd(($x+$d+$d), 511)][$y]) * 0.25 + $d * (Random(0,1) - 0.5) Next Next If $d = 1 Then ExitLoop $d /= 2 WEnd GUICtrlSetPos($24, 312, 404, 100) EndFunc Func BN($x, $y) Local $_SX=$x-Int($x),$_SY=$y-Int($y) Return $NZ[BitAND(Int($x),511)][BitAND(Int($y),511)]*(1-$_SX)*(1-$_SY)+$NZ[BitAND((Int($x)+1), 511)][BitAND(Int($y), 511)]*$_SX*(1-$_SY)+$NZ[BitAND(Int($x),511)][BitAND((Int($y)+1), 511)]*(1-$_SX)*$_SY+$NZ[BitAND((Int($x)+1), 511)][BitAND((Int($y)+1), 511)]*$_SX*$_SY EndFunc Func M($c1, $c2, $k) Return BitOR(((BitAND($c1,255))*$k+(BitAND($c2,255))*(1-$k)),BitAND((BitAND($c1,0xFF00))*$k+(BitAND($c2,0xFF00))*(1-$k),0xFF00),BitAND((BitAND($c1,0xFF0000))*$k+(BitAND($c2,0xFF0000))*(1-$k),0xFF0000)) EndFunc Func A($inHex) Return StringMid($inHex,7,2)&StringMid($inHex,5,2)&StringMid($inHex,3,2)&StringMid($inHex,1,2) EndFunc Func _of($x,$y,ByRef $no) Local $row=($no[1]*3+$no[0]) return 54+(($no[2]*$row)-(($y+1)*$row)+($x*3)) EndFunc