美文网首页
processing 方圆世界

processing 方圆世界

作者: homeless_honey | 来源:发表于2019-08-01 11:18 被阅读0次

1. 膨胀

  • # 变大的圆
  • r = r + 0.5
  • # 触边判断
  • def edges() :
  • return (x + r > width || x - r < 0 || y + r > height || y -r < 0)

2. 生成圈圈

  • # total即是每帧生成圈圈的数量
  • while (count < total):
  • newC = newCircle()
  •   if (newC != null):
  •    circles.add(newC)
  •    count++
  • # 圈圈的内部不生成新的圆
  • for (Circle c : circles):
  • d = dist(x, y, c.x, c.y)
  •   if (d < c.r):
  •    valid = false
  •    break
  • # 对每个圆来说,一旦与其他任何一个圆距离够近,则不再膨胀
  • for (Circle other : circles):
  • if (c != other):
  •   d = dist(c.x, c.y, other.x, other.y)
  •   if (d - 2 < c.r + other.r):
  •    c.growing = false
  •    break

3. 上图

  • # 根据待生成圈圈的位置 获取图片上相应颜色
  • int index = int(x) + int(y) * img.width
  • new Circle(x, y, img.pixels[index])
  • # 生成矩形
  • randomSeed(seed)
  • if (random(1)>0.8):
  •  rect(x, y, r*random(1, 2), r*random(1, 2))

4. 美化

  • # 正片叠底,透明度渐增
  • tint(255, alpha)
  • image(img, 0, 0)
  • if (alpha < 256):
  • alpha += (frameCount<150) ?.5 :5
  • # 删除不合适的点点
  • def mousePressed():
  • for (Circle c : circles):
  •   d = dist(mouseX, mouseY, c.x, c.y)
  •    if (d < c.r):
  •     c.showing = false
  •     c.growing = false
  •     c.r = 0

相关文章

网友评论

      本文标题:processing 方圆世界

      本文链接:https://www.haomeiwen.com/subject/hnvfdctx.html