方程驱动的平滑阴影同心形状 [英] Equation-driven smoothly shaded concentric shapes

查看:136
本文介绍了方程驱动的平滑阴影同心形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景



希望创建有趣的视频转换(灰度)。



问题



鉴于

  • 使用GNUPlot

  • 使用R

  • 绘图使用Wolfram Alpha,使用ImageMagick创建较小的同心版本


  • 解决方案

    在R中试试这个:

      #create palette 
    greyScale< - colorRampPalette(c(black,white))

    #绘制形状的函数
    plotHeart< - function(r,col){
    t< - seq(0,2 * pi,length.out = 100)
    x< ; - r * sin(t)^ 3
    y< - (13 * r / 16)* cos(t) - (5 * r / 16)* cos(2 * t) - (2 * r / 16)* cos(3 * t) - (r / 16)* cos(4 * t)
    polygon(x,y,col = col,border = NA)
    }



    #创建新情节画布
    plot.new()
    #限制是近似值
    plot.window(xlim = c(-16,16),ylim = c(-16, 13))

    #使用mapply循环
    mapply(plotHeart,seq(16,0,length.out = 100),greyScale(100))

    导致:





    这是通过重复绘制填充的多边形,其尺寸逐渐减小,颜色不同于一个另一个。回答你的问题:



    (1)这是由我的机器(一台适度的Core 2 duo笔记本电脑)在0.09秒内完成的。它们可能是更快的其他语言/实现,但这似乎对我来说足够快。



    (2)由不与其他线交叉的线组成的平面形状是通常称为简单多边形。


    Background

    Looking to create interesting video transitions (in grayscale).

    Problem

    Given equations that represent a closed, symmetrical shape, plot the outline and concentrically shade the shape towards its centre.

    Example

    Consider the following equations:

    x = 16 * sin(t)^3
    y = 13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
    t = [0:2 * pi]
    

    When plotted:

    When shaded, it would resemble (not shown completely shaded, but sufficient to show the idea):

    Notice that shading is darkest on the outside (e.g., #000000 RGB hex), then lightens as it fills to the centre. The centre would be a white (e.g., #FFFFFF) dot.

    Questions

    1. What would be the most expedient way to produce high-resolution, concentrically shaded grayscale images, such as the shaded heart above?
    2. What are such closed, symmetrical shapes formally called?

    Thank you!

    Ideas

    解决方案

    Try this in R:

    # create palette
    greyScale <- colorRampPalette(c("black","white"))
    
    # function to draw shape
    plotHeart <- function(r, col){
      t <- seq(0,2*pi,length.out=100)
      x <- r*sin(t)^3
      y <- (13*r/16)*cos(t) - (5*r/16)*cos(2*t) - (2*r/16)*cos(3*t) - (r/16)*cos(4*t)
      polygon(x,y,col=col,border=NA)
    }
    
    
    
    # create new plot canvas
    plot.new()
    # limits are approximate here
    plot.window(xlim=c(-16,16),ylim=c(-16,13))
    
    # use mapply to loop
    mapply(plotHeart,seq(16,0,length.out=100),greyScale(100))
    

    Which results in:

    This works by repeated drawing filled polygons of decreasing size and different colour atop of one another. To answer your questions:

    (1) This was produced by my machine (a modest Core 2 duo laptop) in 0.09 seconds. They may be other languages/implementations that are faster, but this seems quick enough to me.

    (2) A planar shape made up of lines which do not cross other is usually called a simple polygon.

    这篇关于方程驱动的平滑阴影同心形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆