Author Topic: Hearts and peace  (Read 967 times)

m4unot

  • Guest
Hearts and peace
« on: August 10, 2014, 04:02:05 pm »
Drop some Hearts where you touch the screen:

Code: [Select]
#include "DragonFireSDK.h"
#include <iostream>
#include <string>
#include <vector>


#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif // M_PI

 int size = 220; // Size of the heart
 int r = size / 4; // Radius of the curves



int total_curve_vertex_count = 40; // Maximum number of vertices per curve
    int total_vertex_count = 80; // Total number of vertices: 30 + 10 + 10 + 30

    struct CurveInfo // Store information for each of the four square curves
    {
        int vertex_count;
        double t0; // Angle origin
        double s; // Angle sign: +1 or -1
        int cx, cy; // (Relative) coordinates of the center of the curve
    }
    curve_infos[4] =
    {
        // Upper-left
        { 3 * total_curve_vertex_count / 4,        0.0, -1.0, -r, -r},
        // Lower-left
        {     total_curve_vertex_count / 4, 1.5 * M_PI,  1.0, -r,  r},
        // Lower-right
        {     total_curve_vertex_count / 4,       M_PI,  1.0,  r,  r},
        // Upper-right
        { 3 * total_curve_vertex_count / 4, 0.5 * M_PI, -1.0,  r, -r},
    };

    int vertex_index = 0;

void heart(int draw, int x_0, int y_0){





bool position = false;

for(int i = 0; i < 4; i++)
    {
        CurveInfo& curve_info = curve_infos[i];
        int vertex_count = curve_info.vertex_count;
        double t0 = curve_info.t0;
        double s = curve_info.s;
        int cx = x_0 + curve_info.cx;
        int cy = y_0 + curve_info.cy;

        for(int j = 0; j < vertex_count; j++)
        {
            double dt = s * 2.0 * M_PI * j / (total_curve_vertex_count - 1);
            int x = cx + r * cos(t0 + dt);
            int y = cy + r * sin(t0 + dt);

if( position == false){

    DrawMoveTo(draw, x, y);

position = true;

}

        DrawLineTo(draw, x, y);
           
        }
    }

   }



 
   
int dropheart(int id, int event, int x, int y);
int draw_data;

void AppMain()
{

TouchAdd(0, 0, 320, 480, dropheart, 0);

draw_data = DrawAdd(0, 0, 320, 480);

DrawSetColor(draw_data, 0xFF0000);

DrawSetFillColor(draw_data, 0x00FF00FF);

DrawSetPenWidth(draw_data, 1);






}


int dropheart(int id, int event, int x, int y)     //event: 1=down, 2=move, 3=up

{

   if (event == 3)

   { 

   
heart(draw_data, x, y);

      printf("You dropped a heart\n");

     return 0;

   }

}

 

void OnTimer()
{

}

void AppExit()
{

}

have some fuuuuuun!