0

我试图在小型基础上创建噪声图像,但是,我无法让图像加载速度足够快以看起来很逼真。我尝试使用 ldarray 但它仍然不够快。

这是我正在使用的当前代码:

GraphicsWindow.Left = 0 'positions graph
GraphicsWindow.Top = 0
GraphicsWindow.Height = 240
GraphicsWindow.Width = 320
numpix = 320 * 240 'creates number of indices for ldarray
pixels = LDArray.Create(numpix) 'creates 1D array where color values will be       stored
While 1=1
setcolor()
importcolor()
EndWhile

Sub setcolor
For h = 1 To numpix
randomcolor = Math.GetRandomNumber(2)
If randomcolor = 1 Then
  ldarray.SetValue(pixels,h,"black") 'sets the pixel color to black or white
Else
  ldarray.SetValue(pixels,h,"white")
EndIf
EndFor
EndSub


sub importcolor
'prints out the image
For h = 1 To 320
For w = 1 To 240
  i = i + 1
  color = LDArray.GetValue(pixels,i)
  GraphicsWindow.SetPixel(h,w,color)
EndFor
EndFor

EndSub

您可以稍后格式化程序,方法是选择所有文本,然后单击“格式化程序”

另外,如果你能帮我写一个 fps 计数器,那将非常有帮助,因为我不知道从哪里开始。

4

1 回答 1

0

好吧,这似乎有点快,但并不完美。这是您可以做的较难的任务之一,因为它需要同时使 76,800 个像素中的每一个像素随机化。很难。

GraphicsWindow.Left = 0 'positions graph
GraphicsWindow.Top = 0
GraphicsWindow.Height = 240
GraphicsWindow.Width = 320


Randcol[1] = "Black"
Randcol[2] = "White"

'Load a random image of the right size into the imagelist
img = ImageList.LoadImage("http://www.hdiphonewallpapers.us/phone-wallpapers/freewallpaper/12954B94004N0-1Da.jpg")
LDImage.OpenWorkingImage(img)

While 1=1
   For x = 1 To 320
    For y = 1 to 240
      LDImage.SetWorkingImagePixel(img,x,y,Randcol[Math.GetRandomNumber(2)])
    EndFor
   EndFor
  LDImage.CloseWorkingImage(img)
  GraphicsWindow.DrawImage(img,0,0)
  LDImage.OpenWorkingImage(img)
EndWhile
于 2016-08-14T05:39:24.927 回答