简体   繁体   English

有人可以帮忙吗? 我正在尝试制作一个程序,该程序循环通过数字-1至10并制作半径为平方的圆,但是它不起作用

[英]Can someone help? I'm trying to make a programs that loops through numbers -1to10 and makes circles with the radius squared but it doesn't work

I want the program to loop trough each number in the for loop and create a circle with the radius of that number squared but it doesn't seem to work. 我希望程序循环遍历for循环中的每个数字,并创建一个半径为该数字平方的圆,但是它似乎不起作用。 I only creates a circle with the radius of the last number in the for loop. 我只在for循环中以最后一个数字的半径创建一个圆。

I've tried creating a separate function and return the value and putting into my draw function, but that didn't seem to work. 我尝试创建一个单独的函数并返回值并将其放入我的draw函数中,但这似乎没有用。

function setup() {
  createCanvas(600, 600);
}

function draw() {
  for (i = -1; i <= 10; i++) {
    newI = i ** 2;
  };
  background(250);
  circle(300, 300, newI);
//ignore the lines those are just the axis//
  line(300, 0, 300, 600);
  line(0, 300, 600, 300);
}

I want each new radius of each new circle to be that of the number in the for loop squared. 我希望每个新圆的每个新半径都等于for循环中平方的数字。

As mentioned by @Tim Biegeleisen - the circle() and line() should be in the loop, but another approach is to have them separate. 正如@Tim Biegeleisen提到的那样,circle()和line()应该在循环中,但是另一种方法是将它们分开。

Rather than putting the logic into the loop - have the loop iteration call a separate named frunction and pass the new i value as the argument. 与其将逻辑放入循环中,还不如让循环迭代调用一个单独的名为frunction的函数,并将新的i值作为参数传递。

EDIT: loop changed to decrement in order to reverse the order of radius. 编辑:循环更改为递减,以反转半径的顺序。

function setup() {
  createCanvas(600, 600);
}

function draw() {
  for (i = 10; i >= -1; i--) {
    createCircle(i ** 2)
  };

}


function createCircle(newI){
  background(250);
  circle(300, 300, newI);
  line(300, 0, 300, 600);
  line(0, 300, 600, 300);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我试图使每个按钮增加他自己的div中输入的数字,但是不起作用 - I'm trying to make each button increase the numbers in the input in his own div but doesn't work 巨大的弹出窗口:为什么边框半径在图像上不起作用,如何使它起作用? - magnific popup: Why doesn't border radius work on the image and how can i make it work? 我正在尝试在 React 中实现搜索过滤器,但它不起作用,你能帮帮我吗? - I'm trying to implement a Search Filter in React, but it doesn't work, could you help me out? 我正在尝试为我的机器人在 discord.js 中创建一个自动角色 function 但它不起作用 - I'm trying to make an autorole function in discord.js for my bot but it doesn't work 我正在尝试使用“message.guild.ID”进行 if 语句,但它不起作用 - I'm trying to make an if statement with “message.guild.ID” and it doesn't work 我正在尝试通过 make id 获取模型,但我不能;无法工作 - I'm trying to fetch model through make id but i can;t working 我刚开始学习 javascript,我正在尝试制作一个计算器网站,但无法让它工作 - i just started learning javascript and i'm trying to make a calculator website but can't get it to work 我正在尝试制作一个程序来锁定一个网站,但我无法让它工作 - I'm trying to make a program to lock a website, but I can't get it to work 我不知道我做错了什么,它不起作用,我正在尝试列出任务清单 - i don't know what i did wrong, it doesn't work, i'm trying to make a task list React Search - 我正在尝试创建一个过滤器,但它不起作用 - React Search - I'm trying to create a filter and it doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM