- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是 Planet 类:
public class Planet extends CelestialBody {
private static Random r = new Random();
private static Star star;
public Planet(Star star, int orbitRadius, int x, int y){
name = "PLACEHOLDER";
radius = Tools.intBetween(Settings.MAX_PLANET_SIZE, Settings.MIN_PLANET_SIZE);
color = Tools.rObjFromArray(Settings.PLANET_COLORS);
this.star = star;
this.orbitRadius = orbitRadius;
this.x = x; this.y = y;
}
public static Planet createNewPlanet(Star star, int orbitRadius){
int px = (int) (star.x + orbitRadius * Math.cos(Math.toRadians(r.nextInt(360))));
int py = (int) (star.y + orbitRadius * Math.sin(Math.toRadians(r.nextInt(360))));
return new Planet(star, orbitRadius, px, py);
}
public void render(Graphics g){
//Draw orbit
g.setColor(Color.white);
g.drawOval(star.x - orbitRadius, star.y - orbitRadius, orbitRadius * 2, orbitRadius * 2);
//Draw planet
g.setColor(color);
g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
}
}
<小时/>
orbitRadius = distance from planet to star (random);
radius = planet's radius (random)
如果您需要更多代码,请在评论中询问,我知道这是一个菜鸟问题,但我就是不明白为什么轨道与行星不对齐。谢谢。
最佳答案
问题出在以下两行:
int px = (int) (star.x + orbitRadius * Math.cos(Math.toRadians(r.nextInt(360))));
int py = (int) (star.y + orbitRadius * Math.sin(Math.toRadians(r.nextInt(360))));
因为您单独调用 r.nextInt(360)
两次,所以每次都会获得不同的随机数。
结果是 x 和 y 坐标针对不同的角度,我认为很清楚为什么这会是一个问题。
解决方案非常简单:调用一次r.nextInt
并保存结果:
double randomAngle = Math.toRadians(r.nextInt(360));
int px = (int) (star.x + orbitRadius * Math.cos(randomAngle));
int py = (int) (star.y + orbitRadius * Math.sin(randomAngle));
我认为这应该可以解决问题。
关于java - 尝试创建随机的 "solar system",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40334350/
我已经安装了 Solarized color-theme在最新版本的 Emacs (24.3) 中使用 package.el,但颜色似乎不对(对比度似乎太低) 我的 Solarized 安装: 网页截
所以我正面临着我的ls通过这种方式显示颜色的方式之间的差异: https://github.com/seebi/dircolors-solarized 在这之间,以及zsh选项卡如何自动完成显示颜色。
我已经开始使用 emacs(大约几天)。我还阅读了这个主题:Color themes are strange/incorrect in terminal emulator但我仍然有问题。 我做了什么:
这是 Planet 类: public class Planet extends CelestialBody { private static Random r = new Random();
我使用 solarized 作为我的配色方案,并在我的 vimrc 文件中进行了一些自定义。但奇怪的是,当 gVim 启动时,它们不会被应用。我需要获取配置一次,以便日晒设置被接管。所述选项是: le
我正在为 (g)vim 使用 Solarized 主题,并且网站上的屏幕截图与我实际拥有的屏幕截图之间存在细微差异。 主题站点上 python 的屏幕截图在这里: (来源:ethanschoonove
我有两个 solr 实例,一个用于开发和索引准备,第二个是为用户的请求提供服务(部署系统)。开发solr采用本地模式,部署采用云模式。 在开发中完成索引后,我必须将其索引模式化以进行部署。当两个系统上
我正在努力在 vim 上安装 solarized 插件,以下是我遵循的步骤 使用 gmarik/Vundle.vim 安装 solarized 插件(使用下面的 .vimrc 脚本) 运行 vim +
我尝试安装 this theme in emacs . 我下载了文件夹 emacs-color-theme-solarized 并将其放入 .emacs.d/ 目录中。我在同一目录中创建了一个文件 i
设置一台新机器并尝试在 Vim 中运行 Solarized。运行 vim 时出现以下错误: E185:找不到曝光的配色方案 尝试遵循 Solarized README on the official
我正在使用 Solr 来索引 DOC、DOCX 和 PDF 文件。我已经为文本启用了存储并检查了它。以下是示例 DOC 文件的结果: , a mobile user interface (UI) so
我试图过滤一些 .txt 文件,这些文件以 YYYYMMDD 格式的日期命名,并且包含一些关于太阳事件区域的数据。我编写了一个代码,给定一个 YYYYMMDD 格式的日期,它可以列出一个时间范围内的文
作为我的太阳系计划的一部分,一切都很好地实现了,我试图扩展我的计划以包括用户可以绕着 orrey 飞行,或者换句话说,通过使用方向键。这就是我基本上所做的: void keyboard(unsi
我通过病原体安装了 Solarized,它在我的 Mac 上的终端和 MacVim 中都运行良好。今天,我尝试在 Linode 上设置一个 Ubuntu 盒子。我刚刚克隆了 my dotfiles并链
我已经在 iTerm 上使用了日光化的黑暗主题一段时间了,它看起来从来都不像原来的那样。我决定尝试解决它,并在这里和其他网站找到了各种答案: Using the same theme对于 iTerm
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我正在尝试将 light Solarized 主题与 vim 和 xfce4-terminal 一起使用。 我安装了 xfce4-terminal 的主题: cd mkdir solarized ;
您知道 Solar Hijri (Jalali) 日期的 JavaScript 小部件吗?用户可能会输入日期作为 Solar Hijri,我需要转换。 最佳答案 您可以在此处找到用于来回转换日期的 L
我使用 Pathogen 为 Vim 安装了 solarized colorcheme。我的 .vimrc 仅包含以下内容: execute pathogen#infect() syntax enab
我在 Xubuntu 上用 solarized scheme color 安装了 vim。在我安装 Pathogen 之前,它工作正常。现在,我在终端中盯着 Vim 时不断收到以下错误消息: 处理/u
我是一名优秀的程序员,十分优秀!