mooc上学习acllib后写的包含背景音乐的小涂鸦板(初入江湖,大佬勿喷)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mooc上学习acllib后写的包含背景音乐的小涂鸦板(初入江湖,大佬勿喷)相关的知识,希望对你有一定的参考价值。

#include "acllib.h"
ACL_Sound sound1;//背景音乐
ACL_Image img;//开始图
ACL_Image img1;//涂鸦图
ACL_Color c=RED;//默认画笔颜色
int cx=0;
int cy=0;
int j=0;//开始界面和绘图界面分离
int m=0;//重置当前绘图点and监控鼠标左或右键是否一直按着
void BEGIN(void)
{
 loadImage("begin_one.jpg",&img);
 loadSound("pop.mp3",&sound1);
 playSound(sound1,1);
 beginPaint();
 putImage(&img,0,0);
 setTextColor(RED);
 setTextBkColor(GREEN);
 setTextSize(50);
 setTextFont("Goudy Stout");
 paintText(125,200,"BEGIN");
 paintText(175,275,"MUSIC");
 paintText(225,350,"EXIT");
 endPaint();
}

void face_paint()
{
   loadImage("tu.jpg",&img1);
  
   //事先插图为了能够在上面涂鸦
   beginPaint();
   putImage(&img1,200,200);
    endPaint();
}

void rel_paint()
{
    static int ox = 0;
    static int oy = 0;
 
       if(m==1)//避免线画图成为点画图和把绘图起点确定
      {
            ox=cx;
           oy=cy;
           m++;
      }
     if(!(cx>=10&&cx<=72&&cy>=10&&cy<=30))
    { 
       
        beginPaint();
        setPenWidth(3);
        setPenColor(c);
        line(ox,oy,cx,cy);
        endPaint();
        ox=cx;
        oy=cy;
    
    }
}

void mouseEvent(int x,int y,int key,int event)
{
         static int k = 0; //完成歌曲开关键的重复使用(用全局或静态变量保证生存周期)
         //记录绘图坐标
         cx=x;
         cy=y;
 
      //开始界面的begin功能实现
    if(j==0&&x>=125&&x<=260&&y>=200&&y<=250&&key==LEFT_BUTTON&&event==BUTTON_DOWN)
      {
                beginPaint();
                clearDevice();
                endPaint();
                face_paint();
                j=1;
      }
 
          //MUSIC开关控制
     if(j==0&&x>=175&&x<=309&&y>=275&&y<=322&&key==LEFT_BUTTON&&event==BUTTON_DOWN)
    {
       switch(k)
      {
          case 0: 
         //菜单颜色
          beginPaint();
          putImage(&img,0,0);
           setTextColor(RED);
           setTextBkColor(GREEN);
           setTextSize(50);
           setTextFont("Goudy Stout");
           paintText(125,200,"BEGIN");
           paintText(225,350,"EXIT");
           endPaint();
          //改变选项颜色
           beginPaint();
          setTextColor(GREEN);
          setTextBkColor(RED);
          setTextSize(50);
         setTextFont("Goudy Stout");
         paintText(175,275,"MUSIC");
         endPaint(); 
         stopSound(sound1);//关闭音乐
         k=1;
         break;
  
          case 1:
          playSound(sound1,1);
            beginPaint();
            putImage(&img,0,0);
             setTextColor(RED);
             setTextBkColor(GREEN);
             setTextSize(50);
             setTextFont("Goudy Stout");
              paintText(125,200,"BEGIN");
              paintText(175,275,"MUSIC");
              paintText(225,350,"EXIT");
              endPaint();
             k=0;
             break;
         }
    }
 
 
    if(j==0&&x>=222&&x<=319&&y>=349&&y<=398&&key==LEFT_BUTTON&&event==BUTTON_DOWN)
 {
  exit(0);//退出功能
 }
 
 //画板面
 
       if(j==1)
     {   
       //选色板
         beginPaint();
        setBrushColor(BLUE);
        rectangle(10,10,30,30);
        endPaint();
 
        beginPaint();
       setBrushColor(GREEN);
       rectangle(31,10,51,30);
       endPaint();
 
       beginPaint();
       setBrushColor(BLACK);
       rectangle(52,10,72,30);
       endPaint();
   
       //调用划线函数
      //按住左键即可画图
             if(m!=0)
             {   
                rel_paint();
            }


           //笔色
            if(key==LEFT_BUTTON&&event==BUTTON_DOWN)
           {
                 m=1;
                          if(x>=10&&x<=30&&y>=10&&y<=30)
                        {
                              c=BLUE;
                         }
                        if(x>=31&&x<=51&&y>=10&&y<=30)
                         {
                                c=GREEN;
                          }
                       if(x>=52&&x<=72&&y>=10&&y<=30)
                        {
                                c=BLACK;
                       }
           }


          if(event==BUTTON_UP)
         {
              m=0;//既停止了一次画线,又重置了绘图点
          }
   
    }
 
}


int Setup()
{
 
 initWindow("",DEFAULT,DEFAULT,800,600);
 initConsole();
  BEGIN();
 registerMouseEvent(mouseEvent);
    return 0;
 
}

//选用开始图片(img)

 技术分享

//选用音乐和涂鸦图随意
























































































































































































以上是关于mooc上学习acllib后写的包含背景音乐的小涂鸦板(初入江湖,大佬勿喷)的主要内容,如果未能解决你的问题,请参考以下文章

mooc机器学习第六天-K近邻,决策树,朴素贝叶斯分类器简单尝试

Tinywebserver:一个简易的web服务器

一个简易的web服务器:Tinywebserver

Python学习第四天学习写的小案例(主要是针对 分支/循环的学习)

计算几何——凸包问题

计算几何——凸包问题