コード例 #1
0
ファイル: CircleBrush.cpp プロジェクト: lxuad/impressionist
void CircleBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "CircleBrush::BrushMove  document is NULL\n" );
		return;
	}

	glBegin( GL_POLYGON );
		SetColor( source );

		int radius = pDoc->getSize();
		for (int i=0;i<1000;i++) glVertex2d( target.x+radius*cos(2*M_PI*i/1000), target.y+radius*sin(2*M_PI*i/1000) );

	glEnd();
}
コード例 #2
0
void CircleBrush::BrushMove (const Point source, const Point target) {
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "Circlerush::BrushMove document is NULL\n" );
		return;
	}
	int size = pDoc->getSize();
	int radius = size / 2;
	glBegin( GL_TRIANGLE_FAN );
		SetColor( source );

		for (double i = 0; i < 2*M_PI; i+=0.1){
			glVertex2d(target.x + radius*cos(i), target.y + radius*sin(i));
		}

	glEnd();
}
コード例 #3
0
void ScatteredLineBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("LineBrush::BrushMove  document is NULL\n");
		return;
	}

	const int size = pDoc->getSize();
	const float half_size = size / 2.0f;
	const int width = pDoc->getWidth();
	const int angle = pDoc->getAngle();
	const float half_line_width = width / 2.0f;
	float alpha = pDoc->getAlpha();
	float x, y;

	//glBegin(GL_POINTS);
	for (int i = 0; i < 3; i++)
	{

		x = target.x - size / 2 + irand(size);
		y = target.y - size / 2 + irand(size);

		Point random = Point(x, y);
		glPushMatrix();
		glTranslatef(random.x, random.y, 0.0f);
		glRotatef(angle, 0, 0, 1.0f);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glBegin(GL_LINES);
		SetColor(random, alpha);
		glVertex2f(-half_size, 0);
		glVertex2f(half_size, 0);
		glEnd();

		glPopMatrix();
		
	}
}
コード例 #4
0
void ScatteredCirclesBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	int scatterRadius = pDoc->getScatterRadius();
	float randAngle;

	if ( pDoc == NULL ) {
		printf( "ScatteredCirclesBrush::BrushMove  document is NULL\n" );
		return;
	}
	int radius = pDoc->getSize();
	for(int i = 0; i < 20; i++) {
		randAngle = frand() * 2 * M_PI;
		MakeCircle(Point(source.x + (frand() - 0.5) * scatterRadius * cos(randAngle),
			source.y + (frand() - 0.5) * scatterRadius * sin(randAngle)), radius);
	}
}
コード例 #5
0
ファイル: lineBrush.cpp プロジェクト: sfpotter/imp
void
LineBrush::BrushMove(const ImpBrush::Point source, const ImpBrush::Point target)
{
  ImpressionistDoc* pDoc = GetDocument();
  ImpressionistUI* dlg = pDoc->m_pUI;

  if (pDoc == NULL)
  {
    printf("LineBrush::BrushMove document is NULL\n");
    return;
  }

  glBegin(GL_LINES);
  {
    float size = (float)pDoc->getSize();
    SetColor(source);
    glVertex2d((float)target.x - size / 2.0f, target.y);
    glVertex2d((float)target.x + size / 2.0f, target.y);
  }
  glEnd();
}
コード例 #6
0
ファイル: filterbrush.cpp プロジェクト: ohwang/Impressionist
void FilterBrush::BrushMove( const Point source, const Point target , int bsize)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "FilterBrush::BrushMove document is NULL\n" );
		return;
	}

	dlg->get_filter_parameters(m_matrix, m_divisor, m_offset);
	int size = pDoc->getSize();

	// maybe useful
	if (bsize > 0) {
		size = bsize;
	}

	filter_image(pDoc->m_ucPainting, pDoc->m_nWidth, pDoc->m_nHeight, target.x - size / 2, target.y - size / 2, size, size, m_matrix, m_divisor, m_offset, pDoc);
	dlg->m_paintView->RestoreContent();
}
コード例 #7
0
void CircleBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "CircleBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glBegin( GL_POLYGON );
		SetColor( source, alpha );
		for (int i = 0;i<360;i++)
			glVertex2d( target.x +0.5*size*cos(6.28*i/360) , target.y+0.5*size*sin(6.28*i/360));

	glEnd();
}
コード例 #8
0
ファイル: PointBrush.cpp プロジェクト: gary9555/impressionist
void PointBrush::Auto(int startx, int endx, int starty,int endy, int w)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;
	int size = pDoc->getSize();
	int spacing = pDoc->getSpacing();
	double alpha = pDoc->getOpac();
	glPointSize((float)size);
	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glBegin(GL_POINTS);
	for (int i = startx; i < endx + 1; i+=spacing){
		for (int j = starty; j < endy + 1; j+=spacing){
			SetColorOpac(Point(startx+i,endy-j),alpha);
			glVertex2d(i,w-j);
		}
	}
	glEnd();
	 
}
コード例 #9
0
ファイル: spBrush.cpp プロジェクト: ckiwun/Computer-Graphics
void ScatteredPointBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "PointBrush::BrushMove  document is NULL\n" );
		return;
	}

	int size = pDoc->getSize();
	float alpha = pDoc->getAlpha();
	int angle = pDoc->getAngle();
	if(dlg->getDirMode()==1)
		angle = pDoc->getDirAngle();

	float cos_angle,sin_angle;
	float rad_angle = (angle*PI)/180;
	
	cos_angle = cos(-rad_angle);
	sin_angle = sin(-rad_angle);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	float orig_x,orig_y,x,y;
	SetColor( source, alpha );
	glBegin( GL_POINTS );
		for(int i = 0;i<0.05*size*size;i++)
		while(true){
			orig_x=-(size/2)+size*frand();
			orig_y=-(size/2)+size*frand();
			x = orig_x*cos_angle-orig_y*sin_angle;
			y = orig_x*sin_angle+orig_y*cos_angle;
			glVertex2d( target.x+x, target.y+y );
			break;
		}
	glEnd();
}
コード例 #10
0
void CircleBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("PointBrush::BrushMove  document is NULL\n");
		return;
	}

	float radius = (float)pDoc->getSize();
	float alpha = pDoc->getAlpha();

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glBegin(GL_POLYGON);
	SetColor(source, alpha);
	for (double i = 0; i < 2 * PI; i += PI / INTERVAL) {
		glVertex2d(target.x + cos(i)*radius, target.y + sin(i)*radius);
	}
	glEnd();
	glFlush();
}
コード例 #11
0
void CsprayBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "CsprayBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int density = pDoc->getDensity();
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	SetColor( source , alpha);
	for (int i = 0;i<density;i++){
			float r = rand() %10 ;
			r = r*size/10;
			oneCircle(target.x+r*cos(6.28*i/density) , target.y+r*sin(6.28*i/density), rand()%3);
		}

}
コード例 #12
0
void SpraycanBrush::BrushBegin( const Point source, const Point target )
{
  ImpressionistDoc* pDoc = GetDocument();
  ImpressionistUI* dlg=pDoc->m_pUI;
  int pointNo;
  int X, Y;
  float density = 0.8;
  int size = pDoc->getSize ();
  int thickness = pDoc->getThickness ();
  
  int topLeftX = target.x - (thickness / 2);
  int topLeftY = target.y + (size / 2);
  int bottomRightX = target.x + (thickness / 2);
  int bottomRightY = target.y - (size / 2);

  int totalPoints = thickness * size;

  int fillPoints = (int) (density * totalPoints);

  glPointSize (1.0);
  for (int i = 0; i < fillPoints; i++)
    {
      pointNo = rand () % totalPoints;
      Y = topLeftY - (pointNo / thickness);
      X = topLeftX + (pointNo % thickness);

      glBegin( GL_POINTS );
      SetColor( source );
      
      glVertex2d(X, Y);
      
      glEnd();

    }
  

}
コード例 #13
0
ファイル: lineBrush.cpp プロジェクト: rapidsnow/imp
void LineBrush::BrushMove( const Point source, const Point target )
{
    ImpressionistDoc* pDoc = GetDocument();
    ImpressionistUI* dlg=pDoc->m_pUI;

    if ( pDoc == NULL ) {
        printf( "LineBrush::BrushMove  document is NULL\n" );
        return;
    }
    int length;
    int angleSelection;
    float angle;
    Point lastPoint;

    //Define the length and figure out how we are determining the brush angle
    length = pDoc->getSize();
    angleSelection = pDoc->getAngleRadio();

    //If the brush angle selection is based off of cursor direction, do this
    if (angleSelection == 2)
    {
        lastPoint = pDoc->getLastPoint();
        angle = atan(float(lastPoint.y - source.y)/(lastPoint.x - source.x)) + M_PI/2.;
    }
    else
        angle = pDoc->getBrushAngle() * (M_PI/180.);

    //Create the lines

    glBegin( GL_LINES );
    SetColor( source );
    glVertex2d( source.x, source.y );
    glVertex2d( source.x + cos(angle) * length, source.y + sin(angle) * length);
    glEnd();

    pDoc->setLastPoint(source);
}
コード例 #14
0
void ScatteredPointBrush::BrushMove( const Point source, const Point target )
{
    ImpressionistDoc* pDoc = GetDocument();
    //ImpressionistUI* dlg=pDoc->m_pUI;

    if ( pDoc == NULL ) {
        printf( "ScatteredPointBrush::BrushMove document is NULL\n" );
        return;
    }

    int size = pDoc->getSize();
    int halfSize = size / 2;
    int minX = source.x - halfSize;
    int maxX = minX + size;
    int minY = source.y - halfSize;
    int maxY = minY + size;
    int offsetX = target.x - source.x;
    int offsetY = target.y - source.y;

    glBegin(GL_POINTS);
        for (int x = minX; x <= maxX; x++)
        {
            for (int y = minY; y <= maxY; y++)
            {
                int paintPoint = rand() % 100;

                if (paintPoint >= 75)
                {
                    Point individualSource(x, y);
                    Point individualTarget(x + offsetX, y + offsetY);
                    PointBrush::DrawPoint(pDoc, individualSource, individualTarget);
                }
            }
        }
    glEnd();
}
コード例 #15
0
void ScatteredPointBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("PointBrush::BrushMove  document is NULL\n");
		return;
	}

	int size = pDoc->getSize();
	//set random target coordinates
	//srand(time(NULL));
	int numOfPoints = rand() % (size/2)*(size/2) + 1;
	for (int i = 0; i < numOfPoints; i++){
		int xDisplacement = rand() % size;
		int yDisplacement = rand() % size;
		Point newSource(source.x + xDisplacement, source.y + yDisplacement);
		Point newTarget(target.x + xDisplacement, target.y + yDisplacement);

		PointBrush::BrushMove(newSource, newTarget);
	}

}
コード例 #16
0
void SprayBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "SprayBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int density = pDoc->getDensity();
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for (int i = 0; i<density; i++)
		{
			glPointSize( rand()%5+1 );
			glBegin( GL_POINTS );
			SetColor( source , alpha );
			glVertex2d( target.x - size/2 + rand()%size, target.y -size/2 + rand()%size);
			glEnd();
		}
}
コード例 #17
0
void LineBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "LineBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int ax,ay,bx,by;
	int alpha = pDoc->getAlpha(); 
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	double angle = pDoc->getStrokeAngle();
	glBegin( GL_LINES );
		SetColor( source, alpha );
		
		glVertex2d( target.x, target.y );
		glVertex2d( target.x + cos(angle)*size, target.y + sin(angle)*size );
		
	glEnd();
}
コード例 #18
0
ファイル: CurvedBrush.cpp プロジェクト: logchan/COMP4411
void CurvedBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("PointBrush::BrushMove  document is NULL\n");
		return;
	}

	int width = pDoc->m_nWidth;
	int height = pDoc->m_nHeight;

	radius = pDoc->getSize();
	minStrokeLength = pDoc->m_pUI->getMinStrokeLength();
	maxStrokeLength = pDoc->m_pUI->getMaxStrokeLength();
	curvatureFilter = pDoc->m_pUI->getCurvatureFilter();

	unsigned char* imageSource = (pDoc->m_ucBitmapBlurred == NULL) ? pDoc->m_ucBitmap : pDoc->m_ucBitmapBlurred;

	if (target.x < 0 || target.x >= width || target.y < 0 || target.y >= height)
	{
		return;
	}
	vector<pair< pair<int, int>, tuple<unsigned char, unsigned char, unsigned char> > > centers = CurvedBrushHelper::getCurvedBrushPoints(imageSource, pDoc->m_iGradient, pDoc->m_ucPreservedPainting, width, height, target.x, target.y, radius, minStrokeLength, maxStrokeLength, curvatureFilter);
	
	GLubyte color[4];
	color[3] = pDoc->getAlpha() * 255;
	auto color3 = centers[0].second;
	color[0] = get<0>(color3) * pDoc->m_pUI->m_colorSelector->r();
	color[1] = get<1>(color3) * pDoc->m_pUI->m_colorSelector->g();
	color[2] = get<2>(color3) * pDoc->m_pUI->m_colorSelector->b();
	glColor4ubv(color);
	
	if (centers.size() >= 3)
	{
		//calculate curves tangent
		double* tangentX = new double[centers.size()];
		double* tangentY = new double[centers.size()];
		tangentX[0] = centers[1].first.first - centers[0].first.first;
		tangentY[0] = centers[1].first.second - centers[0].first.second;
		tangentX[centers.size() - 1] = centers[centers.size() - 1].first.first - centers[centers.size() - 2].first.first;
		tangentY[centers.size() - 1] = centers[centers.size() - 1].first.second - centers[centers.size() - 2].first.second;
		for (int i = 1; i < centers.size() - 1; ++i)
		{
			tangentX[i] = centers[i].first.first - centers[i - 1].first.first;
			tangentY[i] = centers[i].first.second - centers[i - 1].first.second;
		}
		//calculate normal directions
		double* normalX = new double[centers.size()];
		double* normalY = new double[centers.size()];
		for (int i = 0; i < centers.size(); ++i)
		{
			double unit = sqrt(pow(tangentX[i], 2) + pow(tangentY[i], 2));
			normalX[i] = tangentY[i] / unit;
			normalY[i] = -tangentX[i] / unit;
		}
		//calculate boundary points and draw

		for (int i = 1; i < centers.size(); ++i)
		{
			glBegin(GL_POLYGON);
			glVertex2d(centers[i - 1].first.first + radius*normalX[i], centers[i - 1].first.second + radius*normalY[i]);
			glVertex2d(centers[i].first.first + radius*normalX[i], centers[i].first.second + radius*normalY[i]);
			glVertex2d(centers[i].first.first - radius*normalX[i], centers[i].first.second - radius*normalY[i]);
			glVertex2d(centers[i - 1].first.first - radius*normalX[i], centers[i - 1].first.second - radius*normalY[i]);
			glEnd();
		}

		delete tangentX;
		delete tangentY;
		delete normalX;
		delete normalY;
	}
	for (auto c : centers)
	{
		auto point = c.first;
		auto color3 = c.second;
		color[0] = get<0>(color3) * pDoc->m_pUI->m_colorSelector->r();
		color[1] = get<1>(color3) * pDoc->m_pUI->m_colorSelector->g();
		color[2] = get<2>(color3) * pDoc->m_pUI->m_colorSelector->b();
		glColor4ubv(color);

		glBegin(GL_POLYGON);
		for (int i = 0; i < 36; ++i)
		{
			double theta = i * 10 * 3.14159 / 180;
			glVertex2d(point.first - radius * cos(theta), point.second - radius * sin(theta));
		}
		glEnd();
	}
	
}
コード例 #19
0
void ScatteredCirclesBrush::BrushMove( const ImpBrush::Point source, const ImpBrush::Point target )
{
    ImpressionistDoc* pDoc = GetDocument();
    ImpressionistUI* dlg=pDoc->m_pUI;

    if ( pDoc == NULL ) {
        printf( "ScatteredCirclesBrush::BrushMove document is NULL\n" );
        return;
    }

    GLint size = pDoc->getSize();
    GLint circleCount = 4; // Draw up to 4 randomly placed circles.
    GLint segments = 40; // Increase segment size to increase accuracy
    GLint Ax,Ay,Bx,By,Ox,Oy;

    ImpBrush::Point temp_point;

    //
    // Compute origin x,y values
    //
    Ox = target.x - (.5*size);
    Oy = target.y - (.5*size);

    //
    // Randomization for each click (cap at INT_MAX should we ever hit it)
    //
    m_clickCount >= INT_MAX ? m_clickCount = 0 : m_clickCount++;
    

    //
    // Seed random number using the time plus click count
    //
    srand ( time(NULL) + m_clickCount );

    //
    // Generate random number of circles
    //
    GLint randomCircleCount = rand() % circleCount + 1;


    //
    // Generate pointCount number of points in the size region
    //
    for(GLint i = 0; i <= randomCircleCount; i++)
    {
        //
        // Compute new circle origin
        //
        Ay = rand() % size + Oy;
        Ax = rand() % size + Ox;

        //
        // Color sampling is different for each location
        //
        temp_point.x = source.x + (Ax - target.x);
        temp_point.y = source.y + (Ay - target.y);

        SetColor( temp_point ); 

        glBegin( GL_POLYGON );

        //
        // Draw the circle
        //
        //
        for(int j = 0; j < 360; j += (360 / segments))
        {
            

            //
            // Convert Degrees to radians and calculate x,y
            //
            GLfloat radian = j * (PI / 180);
            Bx = Ax + cos(radian) * (.5*size);
            By = Ay + sin(radian) * (.5*size);

            glVertex2d(Bx, By);
        }

        glEnd();
    }

    
}
コード例 #20
0
void ScatteredLineBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("LineBrush::BrushMove  document is NULL\n");
		return;
	}

	int size = pDoc->getSize();
	int angle = pDoc->getAngle();
	double opacity = pDoc->getOpac();
	int strokeDirChoice = dlg->m_StrokeDirChoice->value();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	srand(time(0));
	glMatrixMode(GL_MODELVIEW);
	
	switch (strokeDirChoice){
	// Slider/Right mouse 
	case 0:
		// don't have to change size and angle value
		for (int i = 0; i < 4; i++){
			float length = fRand(1, size / 2)*2.5;
			float dist = fRand(-size*0.3, size*0.3)*2.5;
			float displacement = fRand(-size*0.75, size*0.75);
			float x1 = target.x + displacement;
			float y1 = target.y + dist;

			glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
					SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
					glVertex2d(x1 - length*0.75, y1);
					glVertex2d(x1 + length*0.75, y1);
				glEnd();
			glPopMatrix();
		}
		break;

	// Gradient
	case 1:
		// change angle value according to 
		// the gradient at this point
		for (int i = 0; i < 4; i++){
			float length = fRand(1, size / 2)*2.5;
			float dist = fRand(-size*0.3, size*0.3)*2.5;
			float displacement = fRand(-size*0.75, size*0.75);
			float x1 = target.x + displacement;
			float y1 = target.y + dist;
			double Gx;
			double Gy;
			GLubyte color[3][3][3];
			double intensity[3][3];
			for (int i = -1; i < 2; i++){
				for (int j = -1; j < 2; j++){
					memcpy(color[i + 1][j + 1], pDoc->GetOriginalPixel(Point(source.x + displacement + i, source.y + dist + j)), 3);
					intensity[i + 1][j + 1] = 0.299*color[i + 1][j + 1][0] + 0.587*color[i + 1][j + 1][1] + 0.144*color[i + 1][j + 1][2];
				}
			}
			Gx = intensity[0][0] * (-1) + intensity[0][1] * (-2) + intensity[0][2] * (-1)\
				+ intensity[2][0] * (1) + intensity[2][1] * (2) + intensity[2][2] * (1);
			Gy = intensity[0][0] * (-1) + intensity[1][0] * (-2) + intensity[2][0] * (-1)\
				+ intensity[0][2] * (1) + intensity[1][2] * (2) + intensity[2][2] * (1);
			angle = -(int)(atan2(Gy, Gx)*57.32) % 360;

			glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
					SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
					glVertex2d(x1 - length*0.75, y1);
					glVertex2d(x1 + length*0.75, y1);
				glEnd();
			glPopMatrix();
		}
		break;

	// Brush direction
	case 2:
		current.x = target.x;
		current.y = target.y;
		if (prev.x!=-1&&current.x!=-1&&(current.x != prev.x || current.y != prev.y)){
			int dx = current.x - prev.x;
			int dy = current.y - prev.y;
			angle = (int)(atan2(dy, dx)*57.32) % 360;

			
			
			for (int i = 0; i < 4; i++){
				float length = size;
				float dist = fRand(-size*0.3, size*0.3)*2.5;
				float displacement = fRand(-size*0.75, size*0.75);
				float x1 = target.x + displacement;
				float y1 = target.y + dist;

				glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
				SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
				glVertex2d(x1 - length*0.75, y1);
				glVertex2d(x1 + length*0.75, y1);
				glEnd();
				glPopMatrix();
			}
		}
		prev.x = current.x;
		prev.y = current.y;
		break;

	default:
		break;

	}
	
}
コード例 #21
0
void LineBrush::BrushMove( const Point source, const Point target )
{
  int newX, newY, sourceNewX, sourceNewY;
  ImpressionistDoc* pDoc = GetDocument();
  ImpressionistUI* dlg=pDoc->m_pUI;

  if ( pDoc == NULL ) {
    printf( "LineBrush::BrushMove:document is NULL\n" );
    return;
  }
#if DEBUG
  printf ("In LineBrush::BrushMove with Source (%d, %d) and Target (%d, %d)\n",
	  source.x, source.y, target.x, target.y);

#endif
  if (dlg->directionOfStroke == CLICK_STROKE_DIRECTION)
    {
      int size = pDoc->getSize ();
      int angle = pDoc->getAngle ();
      int disp;
      int thickness = pDoc->getThickness ();

      if (size < 5)
	disp = size * 2;
      else
	disp = size;

      if (!angle || (angle == 180))
	{
	  newY = target.y;
	  newX = target.x + disp;
	  // 	    sourceNewY = source.y;
	  // 	    sourceNewX = source.x + disp;
	    
	}
      else if (angle == 90)
	{
	  newY = target.y + disp;
	  newX = target.x;
	  // 	    sourceNewY = source.y + disp;
	  // 	    sourceNewX = source.x;

	}
      else
	{
	  int tanAngle = (int) tan (angle);
	  int c = target.y - (tanAngle * target.x);
	    
	  newY = target.y + disp;
	  newX = (newY - c) / tanAngle;
	  // 	    sourceNewY = source.y + disp;
	  // 	    sourceNewX = (sourceNewY - c) / tanAngle;

	}
      glLineWidth( (float)thickness );
	
#if DEBUG
      printf ("LineBrush::BrushMove: Drawing a line from (%d,%d) to (%d,%d) of angle %d\n", 
	      target.x, target.y, newX, newY, angle);
#endif	

      glBegin( GL_LINES );
      SetColor( source );
       
      glVertex2d( target.x, target.y);
      glVertex2d( newX, newY);
      glEnd();
    }
  else if (dlg->directionOfStroke == DRAG_STROKE_DIRECTION)
    {

      int size = pDoc->getSize ();
      int angle = pDoc->getAngle ();
      int thickness = pDoc->getThickness ();
      glLineWidth( (float)thickness );
	

      if (lastPointX != -1)
	{
#if DEBUG
	  printf ("LineBrush::BrushMove: Drawing a line from (%d,%d) to (%d,%d) of angle %d\n", 
		  target.x, target.y, newX, newY, angle);
#endif	

	  glBegin( GL_LINES );
	  SetColor( source );
	  glVertex2d (lastPointX, lastPointY);
	  glVertex2d( target.x, target.y);
	  glEnd();
	  lastPointX = target.x;
	  lastPointY = target.y;
	}
      else
	{
	  lastPointX = target.x;
	  lastPointY = target.y;
	}
    }
}
コード例 #22
0
void ScatteredLinesBrush::BrushMove(const ImpBrush::Point source, const ImpBrush::Point target)
{
	// Get the basic pointers to document and UI.  
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	// Draw Random Lines
	m_ccount >= INT_MAX ? m_ccount = 0 : m_ccount++; 
	srand(time(NULL) + m_ccount);
	ImpBrush::Point temp_point;
	GLint total_lines = 4; 
	GLint A1x, A2x, AxMid, A1y, A2y, Ox, Oy; 
	
	if ( pDoc == NULL ) {
		printf( "SingleLineBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	// Get the size, width, angle, and direction of the stroke
	int dSize = pDoc->getSize();
	int dWidth = pDoc->getLineSize(); 
	int dAngle = pDoc->getLineAngle();  
	int dDirection = pDoc->getStrokeDirection(); 

	// Overwrite stroke if GRADIENT chosen
	if (dDirection == STROKE_DIRECTION_GRADIENT)
	{
		dAngle = SobelGradient(source); 
	}

	// Compute Line Points
	Ox = target.x - (.5 * dSize); 
	Oy = target.y - (.5 * dSize);

	GLint rand_lines = rand() % total_lines + 1; 
	for (int i = 0; i < rand_lines; i++)
	{
		// Get Y first
		A1y = rand() % dSize + Oy; 
		A2y = A1y; 

		// Get X1 and X2 ( start and end lines ) 
		A1x = rand() % dSize + Ox;
		A2x = A1x + dSize;
		AxMid = .5*(A1x + A2x);

		temp_point.x = source.x + (AxMid - target.x);
		temp_point.y = source.y + (A1y - target.y);
		SetColor(temp_point);

		// Translate, Rotate, Translate
		glPushMatrix();
		glTranslatef(target.x, target.y, 0);
		glRotatef(dAngle, 0.0, 0.0, 1.0);
		glTranslatef(-target.x, -target.y, 0);

		glBegin(GL_LINES);

		glVertex2i(A1x, A1y);
		glVertex2i(A2x, A2y);

		glEnd();
		glPopMatrix();

	}
}
コード例 #23
0
void ScatteredPointsBrush::BrushMove( const ImpBrush::Point source, const ImpBrush::Point target )
{
    ImpressionistDoc* pDoc = GetDocument();
    ImpressionistUI* dlg=pDoc->m_pUI;

    if ( pDoc == NULL ) {
        printf( "ScatteredPointsBrush::BrushMove document is NULL\n" );
        return;
    }

    GLint size = pDoc->getSize();
    GLint pointCount = .1 * (size * size); // Fill up 10% of the available pixels 
    pointCount = (pointCount < 1 ? 1 : pointCount); // Insure pointCount >= 1

    GLint Ax,Ay,Ox,Oy;

    ImpBrush::Point temp_point;

    //
    // Compute origin x,y values
    //
    Ox = target.x - (.5*size);
    Oy = target.y - (.5*size);

    //
    // Randomization for each click (cap at INT_MAX should we ever hit it)
    //
    m_clickCount >= INT_MAX ? m_clickCount = 0 : m_clickCount++;
    

    //
    // Seed random number using the time plus click count
    //
    srand ( time(NULL) + m_clickCount );


    //
    // Generate pointCount number of points in the size region
    //
    for(GLint i = 0; i <= pointCount; i++)
    {
        //
        // Compute X,Y Coordinates
        //
        Ax = rand() % size + Ox;
        Ay = rand() % size + Oy;

        //
        // Color sampling is different for each location
        //
        temp_point.x = source.x + (Ax - target.x);
        temp_point.y = source.y + (Ay - target.y);

        SetColor( temp_point ); 

        glBegin( GL_POINTS );

        glVertex2d( Ax, Ay );

        glEnd();
    }
}
コード例 #24
0
ファイル: LiquifyBrush.cpp プロジェクト: logchan/COMP4411
void LiquifyBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("PointBrush::BrushMove  document is NULL\n");
		return;
	}

	int size = pDoc->getSize() * 2;
	double c = pDoc->m_pUI->getLineWidth() / 7.0;

	int height = pDoc->m_nHeight;
	int width = pDoc->m_nWidth;
	unsigned char* originPainting = pDoc->m_ucPreservedPainting;

	GLubyte color[4];
	glPointSize(1);
	glBegin(GL_POINTS);
	for (int y = - size; y <= + size; ++y)
	{
		for (int x = - size; x <= + size; ++x)
		{
			// Check if the pixel inside circle
			if (x*x + y*y <= size*size)
			{

				// Get pixel array position
				if (target.x + x < 0 || target.x + x >= width || target.y + y < 0 || target.y + y >= height)
				{
					continue;
				}

				// Transform the pixel Cartesian coordinates (x, y) to polar coordinates (r, alpha)
				double r = sqrt(x*x + y*y);
				double alpha = atan2(y, x);
				double degrees = (alpha*180.0) / 3.14159;

				double interpolationFactor = r / size;
				r = interpolationFactor * r + (1.0 - interpolationFactor) * c * sqrt(r);
				// Transform back from polar coordinates to Cartesian 
				alpha = (degrees * 3.14159) / 180.0;
				int newY = r * sin(alpha);
				int newX = r * cos(alpha);

				// Get the new pixel location
				if (target.x + newX < 0 || target.x + newX >= width || target.y + newY < 0 || target.y + newY >= height)
				{
					continue;
				}
				int sourcePosition = (newY + target.y) * width + newX + target.x;
				sourcePosition *= 4;
				
				memcpy(color, originPainting + sourcePosition, 4);
				glColor4ubv(color);
				glVertex2d(target.x + x, target.y + y);
			}
		}
	}
	glEnd();
}