Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title>Div Fractal Mountains</title>
- <hta:application
- maximizebutton = "No"
- minimizebutton = "No"
- border = "Thin"
- selection ="No" />
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- <meta name="author" content="Alan Bond" />
- <style type="text/css">
- html{
- overflow:hidden;
- }
- body{
- border:0;
- margin:0;
- background-color:black;
- }
- #btnRender, #txtSeed{
- width:80px;
- }
- #divViewPort{
- position:absolute;
- display:none;
- left:0px;
- }
- .pixel{
- position:absolute;
- /*overflow:hidden;*/
- width:4px;
- height:20px;
- }
- </style>
- <script type="text/vbscript">
- Option Explicit
- Dim sngPerlinMap, objPixel
- Const MAP_SIZE = 128
- Const MAP_SIZE_1 = 127
- Const ENTER_KEY = 13
- Sub Window_OnLoad()
- SetupView
- End Sub
- Sub SetupView()
- Dim X,Y, Div
- Dim SX : SX = MAP_SIZE * 4
- Dim SY : SY = 60
- Dim PX : PX = SX
- Dim PY : PY = SY
- Dim Template : Set Template = Document.CreateElement("div")
- Template.className = "pixel"
- Redim objPixel(MAP_SIZE, MAP_SIZE)
- Self.ResizeTo (SX * 2) + 8, SX * 1.4
- Self.MoveTo (Screen.Width/2) - SX,(Screen.Height/2) - SX * 0.7
- For Y = 0 to MAP_SIZE_1
- For X = 0 to MAP_SIZE_1
- Set Div = divViewPort.AppendChild( Template.cloneNode(False) )
- With Div.Style
- .PixelLeft = PX
- .PixelTop = PY
- .BackgroundColor = RGB(X*3, Y*2, X*2)
- End With
- Set objPixel(X,Y) = Div
- PX = PX + 4 : PY = PY + 2
- Next
- SX = SX - 4 : PX = SX : SY = SY + 2 : PY = SY
- Next
- divViewPort.style.display = "block"
- End Sub
- Sub btnRender_OnClick()
- divViewPort.style.display = "none"
- Dim X,Y,SY,PY,intColour,sngRed,sngGreen,sngBlue
- If IsNumeric(txtSeed.Value) Then
- Rnd(-1) : Randomize ABS(txtSeed.Value)
- Else
- Randomize
- End If
- Perlin 0.45, 2
- SY=MAP_SIZE*2 : PY=SY
- sngRed=Rnd(1) : sngGreen=Rnd(1) : sngBlue=Rnd(1)
- For Y = 0 to MAP_SIZE_1
- For X = 0 to MAP_SIZE_1
- intColour = sngPerlinMap(X,Y)*5
- With objPixel(X,Y).Style
- .PixelTop = PY - sngPerlinMap(X,Y)*6
- .BackgroundColor = RGB(intColour*sngBlue,intColour*sngGreen,intColour*sngRed)
- End With
- PY=PY+2
- Next
- SY=SY+2 : PY=SY
- Next
- divViewPort.style.display = "block"
- End Sub
- Sub txtSeed_OnKeyPress()
- If Window.Event.KeyCode = ENTER_KEY Then btnRender_OnClick
- End Sub
- Sub Perlin(sngScale, intMultiply)
- ReDim sngPerlinMap(MAP_SIZE, MAP_SIZE)
- Dim sngRandNoise : ReDim sngRandNoise(MAP_SIZE, MAP_SIZE)
- Dim sngCeiling : sngCeiling = sngScale * intMultiply
- Dim intNoiseSize : intNoiseSize = MAP_SIZE/2
- While intNoiseSize > 1
- Dim NY, NX
- For NY = 0 To intNoiseSize
- For NX = 0 To intNoiseSize
- sngRandNoise(NX, NY) = Rnd(1) * sngCeiling
- Next
- Next
- Dim intScaleRem : intScaleRem = MAP_SIZE/intNoiseSize
- Dim ISR_1 : ISR_1 = intScaleRem - 1
- Dim sngStep : sngStep = 1/intScaleRem
- Dim intNS_1 : intNS_1 = intNoiseSize-1
- For NY = 0 To intNS_1
- For NX = 0 To intNS_1
- Dim IY: IY = 0
- Dim NX1 : NX1 = NX+1
- Dim NY1 : NY1 = NY+1
- Dim N1 : N1 = sngRandNoise(NX, NY)
- Dim N2 : N2 = sngRandNoise(NX1, NY)
- Dim N3 : N3 = sngRandNoise(NX, NY1)
- Dim N4 : N4 = sngRandNoise(NX1, NY1)
- Dim HX : HX = NX*intScaleRem
- Dim HY : HY = NY*intScaleRem
- Dim HTY
- For HTY = 0 To ISR_1
- Dim IX : IX = 0
- Dim HYHTY : HYHTY = HY+HTY
- Dim HTX
- For HTX = 0 To ISR_1
- Dim IX_1 : IX_1 = 1-IX
- Dim HXHTX : HXHTX = HX+HTX
- sngPerlinMap(HXHTX, HYHTY) = sngPerlinMap(HXHTX, HYHTY) + ((N1*IX_1 + N2*IX) * (1-IY) + (N3*IX_1 + N4*IX) * IY)
- IX = IX + sngStep
- Next
- IY = IY+sngStep
- Next
- Next
- Next
- intNoiseSize = intNoiseSize/2
- sngCeiling = sngCeiling*intMultiply
- Wend
- End Sub
- </script>
- </head>
- <body>
- <button id="btnRender">Render</button><br />
- <input type="text" id="txtSeed" value="23455"/>
- <div id="divViewPort"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment