首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在smallbasic上创建快速图像

在smallbasic上创建快速图像
EN

Stack Overflow用户
提问于 2016-08-09 15:56:13
回答 1查看 105关注 0票数 0

我试图创造一个噪音图像的小基础,然而,我无法获得足够快的图像加载,以看上去现实。我试过用伊达雷,但还是不够快。

下面是使用以下方法的当前代码im:

代码语言:javascript
复制
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计数器,那将是非常有帮助的,因为我不知道从哪里开始。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-14 05:39:24

嗯,这看起来有点快,但并不完美。这是你能做的更难的任务之一,因为它需要使76,800像素中的每一个像素同时随机化。非常难。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38855428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档