Posts: 7
Threads: 3
Joined: Dec 2004
Hey everyone, I'm new...
So, I'm in a computer class and we have a project that involves making holiday scenes. Mines comining along fine except I want some lights that flash using a RND command but I only get two colors (blue and black) Any solution? The section of code for this is below (haven't gotten to the flashing part yet...).
Code:
SUB lightsonhouse
FOR c = 60 TO 240 STEP 20
CIRCLE (c, 220), 5, 0
PAINT (c, 220), RND, 0
RANDOMIZE TIMER
NEXT c
END SUB
Posts: 2,765
Threads: 138
Joined: Nov 2002
RND command get's a number from 0 to 1
that includes decimals
so what you have to do is
that from 1 to 5
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 7
Threads: 3
Joined: Dec 2004
Thanks, but I have another question about making it flash.
I have a GOTO statement so it just repeats the code to make the lights flash, but the lights just keep flashing...forever. Anyway around it?
Code:
SUB lightsonhouse
10 FOR c = 60 TO 240 STEP 20
CIRCLE (c, 220), 5, 0
PAINT (c, 220), INT(RND * 10) + 1, 0
RANDOMIZE TIMER
NEXT c
SLEEP 1
GOTO 10
END SUB
Posts: 2,765
Threads: 138
Joined: Nov 2002
I recomend you use DO LOOP
but it needs and exit condition.
What's the SLEEP for?
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 7
Threads: 3
Joined: Dec 2004
DO LOOP? sorry, never heard of it. You mind explaining it (my help files don't work so I can't just look it up...), or at least point me toward a tutorial for it.
And the SLEEP is so theres a pause for the lights so it looks like lights flashing.
Nevermind, looked at the tutorial on the main site. But one more question hopefully. How do I make it so the lights keep flashing as the rest of my program runs. It just repeats the lights right now.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Posts: 5
Threads: 2
Joined: Dec 2004
sorry, ive got a question.
What does the sleep command do and how do you use it?
Posts: 293
Threads: 31
Joined: Nov 2004
Sleep pause program execution for a period of time you pass to SLEEP as an argument.
ie:
SLEEP 10 will pause the program for 10 seconds
his sig left intentionally blank
Posts: 144
Threads: 17
Joined: Jan 2004
DO
PRINT "YO!"
SLEEP 10
LOOP
This'll print "YO!" every 10 seconds... ALSO, if you press a key it cancels the SLEEP. So, you can also just say
instead of
Code:
DO
LOOP WHILE INKEY$ = ""
Posts: 3,522
Threads: 189
Joined: Dec 2003
Although, thats bad coding practice, because SLEEP doesent clear the keyboard buffer, so your computer may start beeping after a few keystrokes.