English 中文(简体)
PHP + CSS + Lettering.js Creating curved text
原标题:PHP + CSS + Lettering.js Creating curved text

I m 使用字母。 js to Packcode><span> elements around each letter in a string. I m 正在使用PHP进行铺设。 在下面的例子中,$bellcurve尚未界定,例如,我想象的办法可能会使我获得解决办法,但事实上,我不敢肯定这是否正确(但问题在于此)。

因此:

$string = "Hey!! Don t be an apple!"

我想计算一下该插图中的特性,然后,就每个特性而言,形成如下的等级声明,每个数值都是“顶”的,造成整体的伤亡。

我的购买力平价知识使我知道:

    $string = "Hey!! Don t be an apple!";
    $string = str_split($string);
    $i = 1;
    foreach($string as $char){
        echo  .char  . $i .  {top:   . $bellcurve * $i .  px} ;
        $i++;
    }

例如,在这项工作中进行的快速尝试是人工地看着:

span.char1 {top: 20px}
span.char2 {top: 18px}
span.char3 {top: 16px}
span.char4 {top: 15px}
span.char5 {top: 14px}
span.char6 {top: 13px}
span.char7 {top: 12px}
span.char8 {top: 11px}
span.char9 {top: 10px}
span.char10 {top: 10px}
span.char11 {top: 10px}
span.char12 {top: 9px}
span.char13 {top: 9px}
span.char14 {top: 10px}
span.char15 {top: 10px}
span.char16 {top: 10px}
span.char17 {top: 11px}
span.char18 {top: 12px}
span.char19 {top: 13px}
span.char20 {top: 14px}
span.char21 {top: 15px}
span.char22 {top: 16px}
span.char23 {top: 18px}
span.char24 {top: 20px}

What I need to know how to do is create a coefficient ( $bellcurve ) which, when multiplied by $i (the character index), will create a bell curve when iterated over the total number of characters.

或者如果有一个更好的办法,请让我知道!

感谢!


这里的答案是从javascript改为PHP的:

<?php
        $string = get( character_slogan );
        $string = str_split($string);
        $count = count($string);
        $pi = pi();
        $c = 1.0;
        $b = $count / 2;
        $piece = sqrt(2*$pi);
        $a = 1 / ($c*$piece);
?>

    <style type="text/css">

<?php 
    $x = 1;
    foreach($string as $char){
        $E = M_E;
        $bellcurve = ($a*$E)-(pow($x-$b, 2)/pow(2*$c, 2));
        echo  .char  . $x .  {top:   . -$bellcurve .  px}
         ;
        $x++;
    }
?>
    </style>
最佳回答

您可使用Gaussian功能,以形成一种“bell曲”的曲线。

“entergraph

• setting

a = 1/(1.0*(Math.sqrt(2*Math.PI))) // height of the curve s peak ( 1/(σ√(2π)) )
b = letterCount / 2                // position of the center, b = μ (expected value)
c = 1.0                            // width of the "bell", c = σ (variance)

然后在<代码>span各项内容上公布,并照搬top <>/code>“bellPosition”等。

bellPosition = (a*Math.E)-(Math.pow(x-b, 2)/Math.pow(2*c, 2))

you can play with this (especially c to change the variance in the curve)

<>,这一实例是jsfiddle <>>>>>在<代码>span>/code>要素上使用javascript,应当易于翻译到PHP。

问题回答

I will have a look at this in detail when I get home from work. For now, the following should get you started:

在您的风格上添加以下特性:

<span style="display:inline-block; position:absolute; top:$Y; left:$x;">$z</span>

increase $X to display your characters on a horizontal line and increase / decrease $Y to change the vertical position. TO create the desired bell shape, increase / decrease $Y by a incrementally lesser / bigger number everytime, depending if you are before or after the middle of the word.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...