c语言中.用4种颜色画8个球,要求每个球的颜色随机选择的程序怎么写

c语言中.用4种颜色画8个球,要求每个球的颜色随机选择的程序怎么写,第1张

4种颜色 的RGB 数值存放在 unsigned int color[4] 里。

用 rand()%4 定出 color[ ] 的下标 ( 0,1,2,3 之一)

#include <stdioh>

#include <timeh>

main(){

unsigned int color[4]={0xff00a0,0x00ff80,0x8040ff,0xff8000};

int i;

srand(time(NULL)); // 随机种子

for (i=0;i<8;i++)

{

printf("draw Ball_%d in color %06x\n",i,color[rand()%4]);

}

return 0;

}

cls

dim a$(1 to 9)

randomize timer ’重置随机数种子

for i=1 to 9

read a$(i) '输入那些水果

next i

x=int(rnd9+1)

do

y=int(rnd9+1)

loop while y=x

do

z=int(rnd9+1)

loop while z=x or z=y

'这两个do循环是为了不重复选择

print a$(x);a$(y);a$(z) '打印水果

data 苹果,橘子,桃,梨,葡萄,西瓜,椰子,杏,香蕉

end

关于放到网页里,我就不知道了,你得琢磨琢磨。

建立两个Command1和2

Dim RedBalls, BullBalls

Private Sub Command1_Click()

'Label1Caption = ""

rarr = GetRndNotRepeat(0, UBound(RedBalls), 6)

barr = GetRndNotRepeat(0, UBound(BullBalls), 1)

For i = 1 To 6

t = Now

Do

DoEvents

Loop While DateDiff("s", t, Now) < 15

FillStyle = 0

FillColor = vbRed

Form1Circle (500 + i 500, 1000), 200, vbRed

CurrentX = 350 + i 500

CurrentY = 840

Print Format(RedBalls(rarr(i)), "00")

Next i

t = Now

Do

DoEvents

Loop While DateDiff("s", t, Now) < 2

i = 7

FillStyle = 0

FillColor = vbBlue

Form1Circle (500 + i 500, 1000), 200, vbBlue

CurrentX = 350 + i 500

CurrentY = 840

Print Format(BullBalls(barr(1)), "00")

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

RedBalls = Array(2, 3, 4, 7, 8, 9, 12, 13, 14, 17, 18, 19, 22, 23, 24, 27, 28, 29, 32, 33)

BullBalls = Array(3, 4, 5, 9, 13, 14, 15)

'Label1Caption = ""

Command1Caption = "开始"

Command2Caption = "退出"

Form1FontSize = 15

Form1FontName = "Arial"

Form1ForeColor = &HFFFFFF

End Sub

Public Function GetRndNotRepeat(ByVal NumMin As Integer, ByVal NumMax As Integer, ByVal n As Integer)

Dim arr() As Integer

If n > NumMax - NumMin + 1 Then

ReDim arr(0)

arr(0) = 0

Else

ReDim arr(n)

Dim b() As Byte

Dim m As Integer

m = Int((NumMax - NumMin) / 8)

ReDim b(m)

Dim x As Integer, y As Integer

Dim z As Byte

Randomize

arr(0) = 1

For i = 1 To n

Do

x = Int(Rnd (NumMax - NumMin + 1)) + NumMin

y = x - NumMin

z = 2 ^ (y Mod 8)

y = y \ 8

Loop While b(y) And z

b(y) = b(y) Or z

arr(i) = x

Next i

End If

GetRndNotRepeat = arr

End Function

已经运行过。

以上就是关于c语言中.用4种颜色画8个球,要求每个球的颜色随机选择的程序怎么写全部的内容,包括:c语言中.用4种颜色画8个球,要求每个球的颜色随机选择的程序怎么写、关于随机选的一个小程序●●、用VB编写双色球程序,要求是以指定数字为尾的数字中随机选择该怎么编写程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9858869.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存