Exemplo n.º 1
0
// draw function point
void set_point ( float_t x_real, float_t y_real )
{
	if ((x_real> window_left) & (x_real < window_right) & (y_real > window_down) & (y_real <window_up))
	{
		Text_Foreground_Color( COLOR_WHITE );
		Draw_Line( scale_x( x_real ), scale_y( y_real ), scale_x( x_real ), scale_y( y_real ) );
		RAIO_StartDrawing( LINE );
	}
}
Exemplo n.º 2
0
void Plotter::draw_line(double x1, double y1, double x2, double y2) {
    //Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

    cr->move_to (scale_x(x1), scale_y(y1));
    cr->line_to (scale_x(x2), scale_y(y2));

    cr->stroke();
    cr->save();

}
Exemplo n.º 3
0
void Plotter::draw_point(double x, double y) {

    //Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
    cr->arc(scale_x(x), scale_y(y),
            POINT_RES, 0.0, 2.0 * M_PI);
    cr->stroke();
}
Exemplo n.º 4
0
int main()
{
    
    int Iteration;
    const int IterationMax=200;
    
		/* write header */
		printf("P6\n%d\n%d\n%d\n",
				size_x,size_y,max_color_component_value);

    /* compute and write image data bytes to the file*/
	for(int i_y=0; i_y < size_y ;i_y++)
	{
		for(int i_x=0; i_x < size_x ;i_x++){
			double x0 = scale_x( i_x );
			double y0 = scale_y( i_y );
			double x = 0.0;
			double y = 0.0;
		//	printf("%f,%f\n",x0,y0 );
			int iteration = 0;
			while (( (x*x + y*y) < 4 )&&( iteration < max_iteration )){
				/* printf( "\nx= */
				double xtemp = x*x - y*y + x0;
				y = 2*x*y + y0;
				x = xtemp;
				++iteration;
			}
			char r,g,b;
			color_for_iteration( &r, &g, &b, iteration );
			printf( "%c%c%c", r, g, b );
		}
    }
    return 0;
 }
Exemplo n.º 5
0
void example_DrawFunction( int16_t function )
{
	float_t x_real, y_real;
	int16_t count;

	RAIO_clear_screen();

	// draw x-axis
	draw_coords_line ( window_left, 0, window_right, 0 );
	for( count = (int16_t)window_left; count < (int16_t)window_right; count++ )
	{
		Draw_Line ( scale_x( count ), scale_y( window_up*0.01 ), scale_x( count ), scale_y( window_down*0.01 ) );
		Text_Foreground_Color ( COLOR_WHITE );
		RAIO_StartDrawing ( LINE );
	}

	// draw y-axis
	draw_coords_line ( 0, window_up, 0, window_down );
	for( count = (int16_t)window_down; count < (int16_t)window_up; count++ )
	{
		Draw_Line ( scale_x( window_left*0.01 ), scale_y( count ), scale_x( window_right*0.01 ), scale_y( count ) );
		Text_Foreground_Color ( COLOR_WHITE );
		RAIO_StartDrawing ( LINE );
	}


	// draw function
	for( x_real = window_left; x_real < window_right; x_real=x_real+0.02 )
	{
		switch (function) // -> see FUNCTIONS
		{
			case SIN:      y_real = sin( x_real );   break;
			case COS:      y_real = cos( x_real );   break;
			case TAN:      y_real = tan( x_real );   break;
			case PARABOLA: y_real = x_real * x_real; break;
			case EXPONENT: y_real = exp( x_real );   break;
			case LOGN    : y_real = log( x_real );   break;
			default: break;
		};
		set_point( x_real, y_real);
	}
}
Exemplo n.º 6
0
// draw coordinate system
void draw_coords_line (float_t x1, float_t y1, float_t x2, float_t y2)
{
	Text_Foreground_Color( COLOR_WHITE );
	Draw_Line( scale_x( x1 ), scale_y( y1 ), scale_x( x2 ), scale_y( y2 ) );
	RAIO_StartDrawing( LINE );
}
Exemplo n.º 7
0
/// Draw the shadow for a shape
static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, const glm::vec4 &light)
{
	unsigned int i, j, n;
	Vector3f *pVertices;
	iIMDPoly *pPolys;
	static std::vector<EDGE> edgelist;  // Static, to save allocations.
	static std::vector<EDGE> edgelistFlipped;  // Static, to save allocations.
	static std::vector<EDGE> edgelistFiltered;  // Static, to save allocations.
	EDGE *drawlist = NULL;

	unsigned edge_count;
	pVertices = shape->points;
	if (flag & pie_STATIC_SHADOW && shape->shadowEdgeList)
	{
		drawlist = shape->shadowEdgeList;
		edge_count = shape->nShadowEdges;
	}
	else
	{
		edgelist.clear();
		for (i = 0, pPolys = shape->polys; i < shape->npolys; ++i, ++pPolys)
		{
			glm::vec3 p[3];
			for (j = 0; j < 3; j++)
			{
				int current = pPolys->pindex[j];
				p[j] = glm::vec3(pVertices[current].x, scale_y(pVertices[current].y, flag, flag_data), pVertices[current].z);
			}
			if (glm::dot(glm::cross(p[2] - p[0], p[1] - p[0]), glm::vec3(light)) > 0.0f)
			{
				for (n = 1; n < 3; n++)
				{
					// link to the previous vertex
					addToEdgeList(pPolys->pindex[n - 1], pPolys->pindex[n], edgelist);
				}
				// back to the first (FIXME - should be 0, not 2?)
				addToEdgeList(pPolys->pindex[2], pPolys->pindex[0], edgelist);
			}
		}

		// Remove duplicate pairs from the edge list. For example, in the list ((1 2), (2 6), (6 2), (3, 4)), remove (2 6) and (6 2).
		edgelistFlipped = edgelist;
		std::for_each(edgelistFlipped.begin(), edgelistFlipped.end(), flipEdge);
		std::sort(edgelist.begin(), edgelist.end(), edgeLessThan);
		std::sort(edgelistFlipped.begin(), edgelistFlipped.end(), edgeLessThan);
		edgelistFiltered.resize(edgelist.size());
		edgelistFiltered.erase(std::set_difference(edgelist.begin(), edgelist.end(), edgelistFlipped.begin(), edgelistFlipped.end(), edgelistFiltered.begin(), edgeLessThan), edgelistFiltered.end());

		drawlist = &edgelistFiltered[0];
		edge_count = edgelistFiltered.size();
		//debug(LOG_WARNING, "we have %i edges", edge_count);

		if (flag & pie_STATIC_SHADOW)
		{
			// then store it in the imd
			shape->nShadowEdges = edge_count;
			shape->shadowEdgeList = (EDGE *)realloc(shape->shadowEdgeList, sizeof(EDGE) * shape->nShadowEdges);
			std::copy(drawlist, drawlist + edge_count, shape->shadowEdgeList);
		}
	}

	// draw the shadow volume
	glBegin(GL_QUADS);
	glNormal3f(0.0, 1.0, 0.0);
	for (i = 0; i < edge_count; i++)
	{
		int a = drawlist[i].from, b = drawlist[i].to;

		glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
		glVertex3f(pVertices[b].x + light[0], scale_y(pVertices[b].y, flag, flag_data) + light[1], pVertices[b].z + light[2]);
		glVertex3f(pVertices[a].x + light[0], scale_y(pVertices[a].y, flag, flag_data) + light[1], pVertices[a].z + light[2]);
		glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
	}
	glEnd();
}
Exemplo n.º 8
0
/// Draw the shadow for a shape
static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* light)
{
	unsigned int i, j, n;
	Vector3f *pVertices;
	iIMDPoly *pPolys;
	static std::vector<EDGE> edgelist;  // Static, to save allocations.
	static std::vector<EDGE> edgelistFlipped;  // Static, to save allocations.
	static std::vector<EDGE> edgelistFiltered;  // Static, to save allocations.
	EDGE *drawlist = NULL;

	unsigned edge_count;
	pVertices = shape->points;
	if( flag & pie_STATIC_SHADOW && shape->shadowEdgeList )
	{
		drawlist = shape->shadowEdgeList;
		edge_count = shape->nShadowEdges;
	}
	else
	{
		edgelist.clear();
		for (i = 0, pPolys = shape->polys; i < shape->npolys; ++i, ++pPolys)
		{
			Vector3f p[3];
			for(j = 0; j < 3; j++)
			{
				int current = pPolys->pindex[j];
				p[j] = Vector3f(pVertices[current].x, scale_y(pVertices[current].y, flag, flag_data), pVertices[current].z);
			}

			Vector3f normal = crossProduct(p[2] - p[0], p[1] - p[0]);
			if (normal * *light > 0)
			{
				for (n = 1; n < pPolys->npnts; n++)
				{
					// link to the previous vertex
					addToEdgeList(pPolys->pindex[n-1], pPolys->pindex[n], edgelist);
				}
				// back to the first
				addToEdgeList(pPolys->pindex[pPolys->npnts-1], pPolys->pindex[0], edgelist);
			}
		}

		// Remove duplicate pairs from the edge list. For example, in the list ((1 2), (2 6), (6 2), (3, 4)), remove (2 6) and (6 2).
		edgelistFlipped = edgelist;
		std::for_each(edgelistFlipped.begin(), edgelistFlipped.end(), flipEdge);
		std::sort(edgelist.begin(), edgelist.end(), edgeLessThan);
		std::sort(edgelistFlipped.begin(), edgelistFlipped.end(), edgeLessThan);
		edgelistFiltered.resize(edgelist.size());
		edgelistFiltered.erase(std::set_difference(edgelist.begin(), edgelist.end(), edgelistFlipped.begin(), edgelistFlipped.end(), edgelistFiltered.begin(), edgeLessThan), edgelistFiltered.end());

		drawlist = &edgelistFiltered[0];
		edge_count = edgelistFiltered.size();
		//debug(LOG_WARNING, "we have %i edges", edge_count);

		if(flag & pie_STATIC_SHADOW)
		{
			// then store it in the imd
			shape->nShadowEdges = edge_count;
			shape->shadowEdgeList = (EDGE *)realloc(shape->shadowEdgeList, sizeof(EDGE) * shape->nShadowEdges);
			std::copy(drawlist, drawlist + edge_count, shape->shadowEdgeList);
		}
	}

	// draw the shadow volume
	glBegin(GL_QUADS);
	glNormal3f(0.0, 1.0, 0.0);
	for(i=0;i<edge_count;i++)
	{
		int a = drawlist[i].from, b = drawlist[i].to;

		glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
		glVertex3f(pVertices[b].x+light->x, scale_y(pVertices[b].y, flag, flag_data)+light->y, pVertices[b].z+light->z);
		glVertex3f(pVertices[a].x+light->x, scale_y(pVertices[a].y, flag, flag_data)+light->y, pVertices[a].z+light->z);
		glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
	}
	glEnd();

#ifdef SHOW_SHADOW_EDGES
	glDisable(GL_DEPTH_TEST);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

	glColor4ub(0xFF, 0, 0, 0xFF);
	glBegin(GL_LINES);
	for(i = 0; i < edge_count; i++)
	{
		int a = drawlist[i].from, b = drawlist[i].to;
		if(a < 0)
		{
			continue;
		}

		glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
		glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
	}
	glEnd();
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glEnable(GL_DEPTH_TEST);
#endif
}
Exemplo n.º 9
0
/// Draw the shadow for a shape
static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* light)
{
	unsigned int i, j, n;
	Vector3f *pVertices;
	iIMDPoly *pPolys;
	unsigned int edge_count = 0;
	static EDGE *edgelist = NULL;
	static unsigned int edgelistsize = 256;
	EDGE *drawlist = NULL;

	if(!edgelist)
	{
		edgelist = (EDGE*)malloc(sizeof(EDGE)*edgelistsize);
	}
	pVertices = shape->points;
	if( flag & pie_STATIC_SHADOW && shape->shadowEdgeList )
	{
		drawlist = shape->shadowEdgeList;
		edge_count = shape->nShadowEdges;
	}
	else
	{

		for (i = 0, pPolys = shape->polys; i < shape->npolys; ++i, ++pPolys) {
			Vector3f p[3], v[2], normal = {0.0f, 0.0f, 0.0f};
			VERTEXID current, first;
			for(j = 0; j < 3; j++)
			{
				current = pPolys->pindex[j];
				p[j] = Vector3f_Init(pVertices[current].x, scale_y(pVertices[current].y, flag, flag_data), pVertices[current].z);
			}

			v[0] = Vector3f_Sub(p[2], p[0]);
			v[1] = Vector3f_Sub(p[1], p[0]);
			normal = Vector3f_CrossP(v[0], v[1]);
			if (Vector3f_ScalarP(normal, *light) > 0)
			{
				first = pPolys->pindex[0];
				for (n = 1; n < pPolys->npnts; n++) {
					// link to the previous vertex
					addToEdgeList(pPolys->pindex[n-1], pPolys->pindex[n], edgelist, &edge_count, pVertices);
					// check if the edgelist is still large enough
					if(edge_count >= edgelistsize-1)
					{
						// enlarge
						EDGE* newstack;
						edgelistsize *= 2;
						newstack = realloc(edgelist, sizeof(EDGE) * edgelistsize);
						if (newstack == NULL)
						{
							debug(LOG_FATAL, "pie_DrawShadow: Out of memory!");
							abort();
							return;
						}

						edgelist = newstack;

						debug(LOG_WARNING, "new edge list size: %u", edgelistsize);
					}
				}
				// back to the first
				addToEdgeList(pPolys->pindex[pPolys->npnts-1], first, edgelist, &edge_count, pVertices);
			}
		}
		//debug(LOG_WARNING, "we have %i edges", edge_count);
		drawlist = edgelist;

		if(flag & pie_STATIC_SHADOW)
		{
			// first compact the current edgelist
			for(i = 0, j = 0; i < edge_count; i++)
			{
				if(edgelist[i].from < 0)
				{
					continue;
				}
				edgelist[j] = edgelist[i];
				j++;
			}
			edge_count = j;
			// then store it in the imd
			shape->nShadowEdges = edge_count;
			shape->shadowEdgeList = realloc(shape->shadowEdgeList, sizeof(EDGE) * shape->nShadowEdges);
			memcpy(shape->shadowEdgeList, edgelist, sizeof(EDGE) * shape->nShadowEdges);
		}
	}

	// draw the shadow volume
	glBegin(GL_QUADS);
	for(i=0;i<edge_count;i++)
	{
		int a = drawlist[i].from, b = drawlist[i].to;
		if(a < 0)
		{
			continue;
		}

		glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
		glVertex3f(pVertices[b].x+light->x, scale_y(pVertices[b].y, flag, flag_data)+light->y, pVertices[b].z+light->z);
		glVertex3f(pVertices[a].x+light->x, scale_y(pVertices[a].y, flag, flag_data)+light->y, pVertices[a].z+light->z);
		glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
	}
	glEnd();

#ifdef SHOW_SHADOW_EDGES
	glDisable(GL_DEPTH_TEST);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

	glColor4ub(0xFF, 0, 0, 0xFF);
	glBegin(GL_LINES);
	for(i = 0; i < edge_count; i++)
	{
		int a = drawlist[i].from, b = drawlist[i].to;
		if(a < 0)
		{
			continue;
		}

		glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
		glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
	}
	glEnd();
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glEnable(GL_DEPTH_TEST);
#endif
}
Exemplo n.º 10
0
/// Draw the shadow for a shape
static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, const glm::vec4 &light, const glm::mat4 &modelViewMatrix)
{
    static std::vector<EDGE> edgelist;  // Static, to save allocations.
    static std::vector<EDGE> edgelistFlipped;  // Static, to save allocations.
    static std::vector<EDGE> edgelistFiltered;  // Static, to save allocations.
    EDGE *drawlist = NULL;

    unsigned edge_count;
    Vector3f *pVertices = shape->points;
    if (flag & pie_STATIC_SHADOW && shape->shadowEdgeList)
    {
        drawlist = shape->shadowEdgeList;
        edge_count = shape->nShadowEdges;
    }
    else
    {
        edgelist.clear();
        iIMDPoly *end = shape->polys + shape->npolys;
        for (iIMDPoly *pPolys = shape->polys; pPolys != end; ++pPolys)
        {
            glm::vec3 p[3];
            for (int j = 0; j < 3; ++j)
            {
                int current = pPolys->pindex[j];
                p[j] = glm::vec3(pVertices[current].x, scale_y(pVertices[current].y, flag, flag_data), pVertices[current].z);
            }
            if (glm::dot(glm::cross(p[2] - p[0], p[1] - p[0]), glm::vec3(light)) > 0.0f)
            {
                for (int n = 0; n < 3; ++n)
                {
                    // Add the edges
                    edgelist.push_back({pPolys->pindex[n], pPolys->pindex[(n + 1)%3]});
                }
            }
        }

        // Remove duplicate pairs from the edge list. For example, in the list ((1 2), (2 6), (6 2), (3, 4)), remove (2 6) and (6 2).
        edgelistFlipped = edgelist;
        std::for_each(edgelistFlipped.begin(), edgelistFlipped.end(), flipEdge);
        std::sort(edgelist.begin(), edgelist.end(), edgeLessThan);
        std::sort(edgelistFlipped.begin(), edgelistFlipped.end(), edgeLessThan);
        edgelistFiltered.resize(edgelist.size());
        edgelistFiltered.erase(std::set_difference(edgelist.begin(), edgelist.end(), edgelistFlipped.begin(), edgelistFlipped.end(), edgelistFiltered.begin(), edgeLessThan), edgelistFiltered.end());

        drawlist = &edgelistFiltered[0];
        edge_count = edgelistFiltered.size();
        //debug(LOG_WARNING, "we have %i edges", edge_count);

        if (flag & pie_STATIC_SHADOW)
        {
            // then store it in the imd
            shape->nShadowEdges = edge_count;
            shape->shadowEdgeList = (EDGE *)realloc(shape->shadowEdgeList, sizeof(EDGE) * shape->nShadowEdges);
            std::copy(drawlist, drawlist + edge_count, shape->shadowEdgeList);
        }
    }

    std::vector<Vector3f> vertexes;
    for (unsigned i = 0; i < edge_count; i++)
    {
        int a = drawlist[i].from, b = drawlist[i].to;

        glm::vec3 v1(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
        glm::vec3 v2(pVertices[b].x + light[0], scale_y(pVertices[b].y, flag, flag_data) + light[1], pVertices[b].z + light[2]);
        glm::vec3 v3(pVertices[a].x + light[0], scale_y(pVertices[a].y, flag, flag_data) + light[1], pVertices[a].z + light[2]);
        glm::vec3 v4(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);

        vertexes.push_back(v1);
        vertexes.push_back(v2);
        vertexes.push_back(v3);

        vertexes.push_back(v3);
        vertexes.push_back(v4);
        vertexes.push_back(v1);
    }

    // draw the shadow volume
    const auto &program = pie_ActivateShader(SHADER_GENERIC_COLOR, pie_PerspectiveGet() * modelViewMatrix, glm::vec4());
    static glBufferWrapper buffer;
    glBindBuffer(GL_ARRAY_BUFFER, buffer.id);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3f) * vertexes.size(), vertexes.data(), GL_STREAM_DRAW);
    glEnableVertexAttribArray(program.locVertex);
    glVertexAttribPointer(program.locVertex, 3, GL_FLOAT, GL_FALSE, 0, nullptr);

    glDrawArrays(GL_TRIANGLES, 0, edge_count * 2 * 3);
    glDisableVertexAttribArray(program.locVertex);
    pie_DeactivateShader();
}