Fast Question:translate() not working with Processing.js?
in
Processing with Other Languages
•
1 year ago
I am very new in processing js, the following question is stupid but I don't know why when it happend...
It is a simplify code to show my problem, the translate function are not working when I run this code as html file using processing js. (Start from the comment line //****). I have tested it in processing and it is works fine, those rectangles should go to next row if they are out of the screen. But I just see the first row of rects when I running as html file.
Can anyone tell me what's wrong? Thank you very much!!!!!!
-
<script src="processing-1.3.6.min.js"></script>
<script type="text/processing" data-processing-target="mycanvas">
- int CubeSize = 40 * 4;
- int CubeCenter = 20 * 4;
- int MaxBoundary = 30 * 4;
- int MinBoundary = 10 * 4;
- int alphaValue = 200;
- int CubeNum = 100;
- int x = 0;
- int countRan = 0;
- boolean checked = false;
- void setup() {
- background(100);
- size(800, 800);
- smooth();
- noStroke();
- int CubeRow = (800 / (CubeSize += 5))-1;
- for (int i = 0; i < CubeNum; i++) {
- if (i == 0) {
- translate(5, 0);
- }
- else {
- //*************************
- if (x == CubeRow) {
- int Zero = ((CubeSize ) * (CubeRow-1));
- translate(-Zero, 0);
- translate(0, CubeSize);
- x = 0;
- }
- else {
- translate(CubeSize, 0);
- }
- }
- text(i, CubeCenter, CubeCenter);
- rect(0, 0, 50, 50);
- x++;
- }
- }
-
</script>
<canvas id="mycanvas"></canvas>
1