简体   繁体   English

使用HTML和CSS创建树

[英]Create tree using html and css

I have Christmas Tree image background like attached, but without fruits. 我有附着的圣诞树图像背景,但是没有水果。 I want create the fruits (maybe a icon image) by random quantity and position, but the position must be within the range of the foliage (red mark). 我想通过随机的数量和位置创建水果(可能是图标图像),但是位置必须在叶子(红色标记)的范围内。 Any css or js can do this? 任何CSS或JS都能做到这一点?

在此处输入图片说明

Thank you! 谢谢!

If it were me - given this picture - I would probably pick a random location in a rectangle containing the tree and test for the pixel there having substantially more green than other components - if not found, try again (probably put a limit of 100 tries or so, in case the tree gets filled up). 如果是我-给定这张图片-我可能会在包含树的矩形中随机选择一个位置,并测试该像素中的绿色比其他组件要多得多的像素-如果找不到,请重试(限制为100次尝试或大约在树被填满的情况下)。 That would also keep you from placing a new one directly on another ornament (though not prevent overlap, of course). 这也可以使您避免将新饰品直接放在另一饰品上(当然,这不能防止重叠)。 This seems a lot simpler than trying to define the outline of the tree. 这似乎比尝试定义树的轮廓要简单得多。 This also lets you change the background picture to a different tree or even a forest of trees. 这也使您可以将背景图片更改为另一棵树,甚至是树林。

我必须创建一个包含水果坐标的数组(非常多),然后从该数组中获取随机值。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM