Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Static Simulation Code Help*
- JAVAProgramming
- Scratcher
100+ posts
Static Simulation Code Help*
I made a program to simulate static. I know this is a section for Scratch Projects, but I still need help with my code…
Here is my code, if someone could help me get it right, because right now it is just a blank screen when I run it:
*This is in JavaScript
Here is my code, if someone could help me get it right, because right now it is just a blank screen when I run it:
var y = 0;
var x = 0;
noStroke();
var draw = function() {
//repeatng 160k times because there will be 160k squares
for (var i = 0; i > 160000; i ++) {
//random colour chooser
var randomColour = random(1, 10);
//changing the number into a fill colour
if(randomColour < 5){
//if the random number is less than 5, fill the square black
fill(0,0,0);
} else {
//if not, fill it white
fill(255, 255, 255);
}
//if y is at 400, bring it back to 0 and change x by 10 for a new row
if (y === 400){
y = 0;
x += 10;
}
//finally, draw the square
rect(x, y, 10, 10);
y += 10;
}
};
*This is in JavaScript
Last edited by JAVAProgramming (Dec. 24, 2013 20:30:12)
My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.
“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
- AonymousGuy
- Scratcher
1000+ posts
Static Simulation Code Help*
Well,
A) I don't think you should post this here
B) Did you invoke the function? (I don't know if setting a variable invokes a function)
C) I think its Math.random not just random
D) Is rect() and fill() a legitimate command? What class is it from?
A) I don't think you should post this here
B) Did you invoke the function? (I don't know if setting a variable invokes a function)
C) I think its Math.random not just random
D) Is rect() and fill() a legitimate command? What class is it from?
- drmcw
- Scratcher
1000+ posts
Static Simulation Code Help*
fill doesn't look right, as it's not being used anywhere. Isn't there a fillrect function instead?
- JAVAProgramming
- Scratcher
100+ posts
Static Simulation Code Help*
A) it is code I need help with Well,
A) I don't think you should post this here
B) Did you invoke the function? (I don't know if setting a variable invokes a function)
C) I think its Math.random not just random
D) Is rect() and fill() a legitimate command? What class is it from?
B) the “Draw” function is like a forever loop in Scratch
C)No, it is random();
D)Yes…
My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.
“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
- JAVAProgramming
- Scratcher
100+ posts
Static Simulation Code Help*
No, there is not a fillrect function. fill doesn't look right, as it's not being used anywhere. Isn't there a fillrect function instead?
My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.
“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
- AonymousGuy
- Scratcher
1000+ posts
Static Simulation Code Help*
IT IS Math.random()!!!
Sorry for caps.
Also I haven't done too much javascript, so I didn't know that setting a variable to a function will eternally call it.
Sorry for caps.
Also I haven't done too much javascript, so I didn't know that setting a variable to a function will eternally call it.
- JAVAProgramming
- Scratcher
100+ posts
Static Simulation Code Help*
IT IS Math.random()!!!OK, I kind of lied.. It isn't totally JavaScript… It's more like a hybrid of JavaScript.. So it IS RANDOM().
Sorry for caps.
Also I haven't done too much javascript, so I didn't know that setting a variable to a function will eternally call it.
My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.
“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
- AonymousGuy
- Scratcher
1000+ posts
Static Simulation Code Help*
A hybrid of javascript and what?IT IS Math.random()!!!OK, I kind of lied.. It isn't totally JavaScript… It's more like a hybrid of JavaScript.. So it IS RANDOM().
Sorry for caps.
Also I haven't done too much javascript, so I didn't know that setting a variable to a function will eternally call it.
If it's jQuery, I can't help.
- JAVAProgramming
- Scratcher
100+ posts
Static Simulation Code Help*
I don't even know what jQuery is… JavaScript and some things the creator of it made…?A hybrid of javascript and what?IT IS Math.random()!!!OK, I kind of lied.. It isn't totally JavaScript… It's more like a hybrid of JavaScript.. So it IS RANDOM().
Sorry for caps.
Also I haven't done too much javascript, so I didn't know that setting a variable to a function will eternally call it.
If it's jQuery, I can't help.
My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.
“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
- JAVAProgramming
- Scratcher
100+ posts
Static Simulation Code Help*
I have no errors in my code… still think its the fill not being used.
My Newest Project, Come Check It Out
Dots, On Scratch
Want to change the way we count? The Dozenal System.
“The story so far:
In the beginning the Universe was created.
This has made a lot of people very angry and been widely regarded as a bad move.”
― Douglas Adams, The Restaurant at the End of the Universe
- Discussion Forums
- » Help with Scripts
- » Static Simulation Code Help*