Discuss Scratch

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:

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?
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?

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
JAVAProgramming
Scratcher
100+ posts

Static Simulation Code Help*

AonymousGuy wrote:

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) it is code I need help with
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*

drmcw wrote:

fill doesn't look right, as it's not being used anywhere. Isn't there a fillrect function instead?
No, there is not a fillrect function.

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.
JAVAProgramming
Scratcher
100+ posts

Static Simulation Code Help*

AonymousGuy wrote:

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.
OK, I kind of lied.. It isn't totally JavaScript… It's more like a hybrid of JavaScript.. So it IS RANDOM().

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*

JAVAProgramming wrote:

AonymousGuy wrote:

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.
OK, I kind of lied.. It isn't totally JavaScript… It's more like a hybrid of JavaScript.. So it IS RANDOM().
A hybrid of javascript and what?

If it's jQuery, I can't help.
JAVAProgramming
Scratcher
100+ posts

Static Simulation Code Help*

AonymousGuy wrote:

JAVAProgramming wrote:

AonymousGuy wrote:

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.
OK, I kind of lied.. It isn't totally JavaScript… It's more like a hybrid of JavaScript.. So it IS RANDOM().
A hybrid of javascript and what?

If it's jQuery, I can't help.
I don't even know what jQuery is… JavaScript and some things the creator of it made…?

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
drmcw
Scratcher
1000+ posts

Static Simulation Code Help*

still think its the fill not being used.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
JAVAProgramming
Scratcher
100+ posts

Static Simulation Code Help*

drmcw wrote:

still think its the fill not being used.
I have no errors in my code…

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

Powered by DjangoBB