小编mkb*_*mkb的帖子

t/= d是什么意思?Python并获得错误

// t: current time, b: begInnIng value, c: change In value, d: duration

def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
    //alert(jQuery.easing.default);
    return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
    return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
    return -c *(t/=d)*(t-2) + b;
},
Run Code Online (Sandbox Code Playgroud)

我试图将Robert Penner的Easing Functions转换为python并卡住!任何帮助或其他任何人之前做过这个?

https://github.com/danro/jquery-easing/blob/master/jquery.easing.js

javascript python

5
推荐指数
1
解决办法
1237
查看次数

如何加快c ++中二维三角矩阵的内存分配?

我需要为一个代表三角矩阵的非常大的数组分配内存.我写了以下代码:

const int max_number_of_particles=20000;
float **dis_vec;

dis_vec = new float **[max_number_of_particles];

for (i = 0; i<max_number_of_particles; i++)
  dis_vec[i] = new float *[i];

for (i = 0; i<max_number_of_particles; i++)
  for (j = 0; j<i; j++)
    dis_vec[i][j] = new float[2];
Run Code Online (Sandbox Code Playgroud)

问题是这样做所需的时间(分配内存)随着矩阵大小的增加而迅速增加.有谁知道这个问题更好的解决方案?

谢谢.

c++ matrix triangular dynamic-allocation

2
推荐指数
1
解决办法
1013
查看次数

如何测试嵌入在bash脚本中的perl命令是否返回true?

所以,我有一个bash脚本,其中我想要一个条件,这取决于perl脚本返回的内容.我的代码背后的想法如下:

for i in $(ls); do
    if $(perl -e "if (\$i =~ /^.*(bleh|blah|bluh)/) {print 'true';}"); then
       echo $i;
   fi;
done
Run Code Online (Sandbox Code Playgroud)

目前,这总是返回true,当我在if语句周围尝试[[]]时,我遇到了错误.任何人的想法?

Ps我知道我可以用grep做到这一点,但这只是一个例子.我想知道如何让Bash一般使用Perl输出

Pps我知道我可以用两行来做,将perl输出设置为变量,然后测试该变量值,但我宁愿避免使用那个额外的变量.似乎很浪费.

bash perl

1
推荐指数
1
解决办法
1751
查看次数

C++基础知识,向量,析构函数

我对如何做到这一点的最佳实践感到有些困惑.假设我有一个类,例如分配一些内存.我希望它像汽车一样自我毁灭,但也因为某种原因未知而将它放在矢量中.

 #include <iostream>
 #include <vector>
 class Test {
 public:
  Test();
  Test(int a);
  virtual ~Test();
  int counter;
  Test * otherTest;
 };

 volatile int count = 0;


 Test::Test(int a) {
  count++;
  counter = count;
  std::cout << counter <<  "Got constructed!\n";
  otherTest = new Test();
  otherTest->counter = 999;
 }

 Test::Test() {
  count++;
  counter = count;
  std::cout << counter <<  "Alloced got constructed!\n";
  otherTest = NULL;
 }


 Test::~Test() {
  if(otherTest != 0){
  std::cout << otherTest->counter << " 1Got destructed" << counter << "\n";
  otherTest->counter …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
372
查看次数

C图形库错误

我有以下代码:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
    int gd=DETECT,gm;
    int dx,dy,p,end;
    float x1,x2,y1,y2,x,y;
    initgraph(&gd,&gm,"");
    printf("\nEnter the value of x1: ");
    scanf("%f",&x1);
    printf("\nEnter the value of y1: ");
    scanf("%f",&y1);
    printf("\nEnter the value of x2: ");
    scanf("%f",&x2);
    printf("\nEnter the value of y2: ");
    scanf("%f",&y2);
    dx=abs(x1-x2);
    dy=abs(y2-y1);
    p=2*dy-dx;

    if(x1>x2)
    {
        x=x2;
        y=y2;
        end=x1;
    }
    else
    {
        x=x1;
        y=y1;
        end=x2;
    }
    putpixel(x,y,10);
    while(x<end)
    {
        x=x+1;
        if(p<0)
        {
            p=p+2*dy;
        }
        else
        {
            y=y+1;
            p=p+2*(dy-dx);
        }
        putpixel(x,y,10);
    }
    getch();
    closegraph();
}
Run Code Online (Sandbox Code Playgroud)

代码主要用于创建一条线.但是当我运行这个程序时,我在控制台中收到错误消息(我使用的是Ubuntu 10.04版本):

test.c:2: fatal …

c graphics

1
推荐指数
1
解决办法
5573
查看次数

标签 统计

c++ ×2

bash ×1

c ×1

dynamic-allocation ×1

graphics ×1

javascript ×1

matrix ×1

perl ×1

python ×1

triangular ×1