从零开始仿写一个抖音App——音视频开篇

// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// include 了cmake 生成配置文件
#include “TutorialConfig.h”

int main (int argc, char *argv[]) {
if (argc < 2)
{
fprintf(stdout,“%s Version %d.%d\n”,
argv[0],
// 使用了 cmake 生成的配置参数
Tutorial_VERSION_MAJOR,
Tutorial_VERSION_MINOR);
fprintf(stdout,“Usage: %s number\n”,argv[0]);
return 1;
}
double inputValue = atof(argv[1]);
double outputValue = sqrt(inputValue);
fprintf(stdout,“The square root of %g is %g\n”,
inputValue, outputValue);
return 0;
}

// 这个是配置文件,cmake 会根据他在 cmake 的 build 目录生成一个 TutorialConfig.h 文件
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR

(2).添加库的依赖
  • 1.我们进入项目的 two/a/mylib 中会看见三个文件 CMakeLists.txt、mysqrt.cpp、MathFunctions.h 代码如下:
  • 1.声明了一个 library
  • 2.定义了一个计算平方根的函数,然后使用头文件暴露在外面

cmake_minimum_required (VERSION 2.6)

声明了一个 library 名为 MathFunctions,他包含一个可执行文件 mysqrt.cpp

add_library(MathFunctions mysqrt.cpp)

#include “MathFunctions.h”
#include <stdio.h>

// a hack square root calculation using simple operations
double mysqrt(double x) {
if (x <= 0) {
return 0;
}

double result;
double delta;
result = x;

// do ten iterations
int i;
for (i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
delta = x - (result * result);
result = result + 0.5 * delta / result;
fprintf(stdout, “Computing sqrt of %g to be %g\n”, x, result);
}
return result;
}

//
// Created by 何时夕 on 2018/11/11.
//

#ifndef PROJECT_MATHFUNCTIONS_H
#define PROJECT_MATHFUNCTIONS_H
double mysqrt(double x);
#endif //PROJECT_MATHFUNCTIONS_H

  • 2.然后我们再看看 two/a 这个目录下面的文件,这些文件大部分是从 one/b 中拷贝来的,我就只贴有修改的部分 CMakeLists.txt、Configure.h.in、MathFunctions.h、tutorial​
    .cpp:
  • 1.这里主要做的工作是现在 cmake 文件中定义了一个 USE_MYMATH 的开关,当这个开关为 ON 的时候就将我们定义的 library 集成到 project 中,否则就不集成,只使用系统自带的库。这个东西在跨平台的时候非常有用,比如 ios 和 android 中的 log 库不同,那么我就可以定义一个开关来区别这两个平台。
  • 2.可以注意到的是这里也定义了一个 Configure.h.in 文件作为配置文件,cmake 会根据这个文件来创建一个 Configure.h 文件,然后我们就可以在 Cpp 文件中使用我们定义的开关了。
  • 3.我们可以在 two/a/build 中运行 cmake…、make、./Tutorial_Mylib 3 这几个命令,会发现最终调用的是我们自己的函数,如果将 USE_MYMATH 改成 OFF 然后删除 build 中的文件再重新 build 一遍,会发现最后调用的是系统的函数。

cmake_minimum_required (VERSION 2.6)
project (Tutorial_Mylib)

set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)

configure_file (
P R O J E C T S O U R C E D I R / T u t o r i a l C o n f i g . h . i n " " {PROJECT_SOURCE_DIR}/TutorialConfig.h.in" " PROJECTSOURCEDIR/TutorialConfig.h.in""{PROJECT_BINARY_DIR}/TutorialConfig.h”
)

添加一个是否使用我们自己的库的开关 USE_MYMATH,这个开关可以在 cmake 中直接使用

option (USE_MYMATH
“Use tutorial provided math implementation” ON)

定义一个文件来储存 USE_MYMATH,以便在 cpp 文件中使用

configure_file(“ P R O

由于文字描述有限,这里给出一个简单的HTML和CSS代码示例,它创建了一个基础的登录界面,你可以根据这个例子去调整和添加更多风格的元素: ```html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="styles.css"> <title>风格登录页</title> </head> <body> <div class="login-container"> <img src="tiktok-logo.png" alt="Logo" class="logo"> <form id="login-form"> <input type="text" placeholder="请输入用户名" id="username" required> <input type="password" placeholder="请输入密码" id="password" required> <button type="submit">登录</button> <a href="#" class="social-login">已有账号?立即登录</a> </form> <div class="animation"> <!-- 可以添加动态加载效果的代码,如旋转的波浪线 --> <span class="wave"></span> </div> </div> </body> </html> ``` ```css /* styles.css */ .login-container { width: 300px; margin: auto; padding: 20px; background-color: #f0f0f0; border-radius: 5px; } .logo { display: block; margin-bottom: 15px; max-width: 100%; } input[type=text], input[type=password] { width: 100%; padding: 10px; margin-bottom: 15px; font-size: 16px; border: none; border-bottom: 1px solid #ccc; } button { background-color: #ff6e51; color: white; border: none; padding: 10px 20px; cursor: pointer; transition: background-color 0.3s ease; } .social-login { text-decoration: underline; color: #4c99d4; } .animation .wave { animation: wave 1s linear infinite; } @keyframes wave { 0%, 100% {transform: rotate(0deg);} 50% {transform: rotate(-20deg);} } ``` 这只是一个基本框架,为了完全复制风格,还需要进一步调整颜色、字体、图标和动画效果,甚至添加响应式设计。实际项目中可能还需要结合JavaScript来处理表单验证和提交事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值