Android中球体碰撞代码分享-kotlin,入门版

* 可以产生形变,回弹的小球
*
* 整个view的核心:
* Scroller函数
* 1.调用scroller.public void startScroll(int startX, int startY, int dx, int dy, int duration);
* 在指定时间范围内,startX,startY,会移动dx,dy距离
*
* 2.然后调用:invalidate(); 系统内部会调用onDraw();
*
* 3.在onDraw方法内部又会调用  computeScrollOffset()函数。
* 所以,实现scroll.computeScrollOffset(); //如果还没有完全移动完成,就执行XXXXX
*
* 4.如果返回true 继续调用 invalidate();
*
* 这样就会在位移的过程中,执行你:  if(scroll.computeScrollOffset()){
* //你自己的方法
* }
*

class BallViewTwo @JvmOverloads constructor(context: Context,attrs: AttributeSet? = null
) : androidx.appcompat.widget.AppCompatImageView(context, attrs) {private var mContext: Context = context//屏幕的宽高private var displayHeight: Int = 0private var displayWidth: Int = 0private var changelength = 30 //第一次形变的大小private var mCurrentDirection = -1 //碰撞后,此时的方向private var mDuration = 450 //变形需要持续的时间/*** flag=-1 正常移动* flag=0 压缩变形* flag=1 恢复压缩形变* flag=2 往相反的方向弹* flag=3 弹回原先的位置*/private var flag = -1private var mShotOver: ShotOver? = null //回调函数private var moveToLeft = 100 //正常状态下,小球移动到x轴的位置private var moveToTop = 100 //正常状态下,小球移动到y轴的位置private val centerX = 180 //小球圆心xprivate val centerY = 180 //小球圆心yprivate val radius = 180 //半径private val bubbleWidth = radius * 2 //小球的宽private val bubbleHeight = radius * 2 //小球的高private var paint: Paint // 画笔private var scroller: Scroller // 整个view的核心private var rectF: RectF? = null //绘制椭圆private var ovalLeft = 0private var ovalTop = 0private var ovalRight = 0private var ovalBottom = 0 //椭圆的左上右下private var currY = 0private var currX = 0private var offset = 0 //发生的移动量private val shotBackDuration = 100 //回弹执行的时间private val shotBackChange = 15 //回弹需要移动的距离private var newOvalLeft = 0private var newOvalTop = 0private var newOvalRight = 0private var newOvalBottom = 0private var isShotBack = true // 是否开启回弹效果init {paint = Paint()paint.color = Color.REDscroller = Scroller(context)rectF = RectF()}override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {displayHeight = mContext.resources.displayMetrics.heightPixelsdisplayWidth = mContext.resources.displayMetrics.widthPixelsLog.i("qq", "ballview-------displayHeight=-$displayHeight displayWidth=$displayWidth")super.onMeasure(widthMeasureSpec, heightMeasureSpec)}override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {super.onSizeChanged(w, h, oldw, oldh)}override fun onDraw(canvas: Canvas) {when (flag) {-1 -> {canvas.translate(moveToLeft.toFloat(), moveToTop.toFloat())canvas.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)Log.i("qq", "正常移动小球 小球left=$moveToLeft top=$moveToTop")}0 -> circleToOval(canvas)1 -> ovalToCircle(canvas)2 -> shotBackLeaveBounds(canvas)3 -> shotBackGotoBounds(canvas)}super.onDraw(canvas)}/*** 小球变形完再回弹,靠近边界*/private fun shotBackGotoBounds(canvas: Canvas) {if (scroller.computeScrollOffset()) {ovalLeft = scroller.currXovalTop = scroller.currYcanvas.translate(ovalLeft.toFloat(), ovalTop.toFloat())canvas.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)invalidate()Log.i("shotBack", "远离边界。。moveToLeft=$ovalLeft moveToTop=$ovalTop")} else {Log.i("shotBack", "所有效果都结束")canvas.translate(ovalLeft.toFloat(), ovalTop.toFloat())canvas.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint)isShotBack = falsestartChange(shotBackChange)}}/*** 小球变形完再回弹,也就是远离边界*/private fun shotBackLeaveBounds(canvas: Canvas) {if (scroller.computeScrollOffset()) {ovalLeft = scroller.currXovalTop = scroller.currYcanvas.translate(ovalLeft.toFloat(), ovalTop.toFloat())canvas.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint!!)invalidate()Log.i("shotBack", "远离边界。。moveToLeft=$ovalLeft moveToTop=$ovalTop")} else {canvas.translate(ovalLeft.toFloat(), ovalTop.toFloat())canvas.drawCircle(centerX.toFloat(), centerY.toFloat(), radius.toFloat(), paint!!)flag = 3finishShotBack()}}/*** 将椭圆恢复成圆形*/private fun ovalToCircle(canvas: Canvas) {if (scroller!!.computeScrollOffset()) {when (mCurrentDirection) {0 -> {currY = scroller!!.currYoffset = newOvalTop - currYovalLeft = newOvalLeft + offsetovalTop = currY + offsetovalRight = newOvalRight - offsetovalBottom = newOvalBottom + offset + offsetrectF!![ovalLeft.toFloat(), ovalTop.toFloat(), ovalRight.toFloat()] =ovalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)Log.i("qq","将椭圆----恢复成圆形,方向向北 currY=$currY offset=$offset")Log.i("qq","将椭圆----恢复成圆形,方向向北 ovalLeft=$ovalLeft ovalTop=$ovalTop ovalRight=$ovalRight ovalBottom=$ovalBottom")}1 -> {currX = scroller!!.currXoffset = newOvalLeft - currXovalLeft = currX - offsetovalTop = newOvalTop + offsetovalRight = newOvalRight + offset - offsetovalBottom = newOvalBottom - offsetrectF!![ovalLeft.toFloat(), ovalTop.toFloat(), ovalRight.toFloat()] =ovalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)}2 -> {currY = scroller!!.currYoffset = newOvalTop - currYovalLeft = newOvalLeft + offsetovalTop = currY - offsetovalRight = newOvalRight - offsetovalBottom = newOvalBottomrectF!![ovalLeft.toFloat(), ovalTop.toFloat(), ovalRight.toFloat()] =ovalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)Log.i("qq","将椭圆----恢复成圆形,方向向南 currY=$currY offset=$offset")Log.i("qq","将椭圆----恢复成圆形,方向向南 ovalLeft=$ovalLeft ovalTop=$ovalTop ovalRight=$ovalRight ovalBottom=$ovalBottom")}3 -> {currX = scroller!!.currXoffset = newOvalLeft - currXovalLeft = currX + offsetovalTop = newOvalTop + offsetovalRight = newOvalRight + offset + offsetovalBottom = newOvalBottom - offsetrectF!![ovalLeft.toFloat(), ovalTop.toFloat(), ovalRight.toFloat()] =ovalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)}}invalidate()} else {canvas.drawOval(rectF!!, paint!!)//如果需要回弹的话if (isShotBack) {flag = 2startShotBack()} else {flag = -1if (mShotOver != null) {mShotOver!!.bubbleShotEnd()}}}}/*** 圆挤压成椭圆*/private fun circleToOval(canvas: Canvas) {if (scroller!!.computeScrollOffset()) {when (mCurrentDirection) {0 -> {currY = scroller!!.currYoffset = currY - ovalTopnewOvalLeft = ovalLeft - offsetnewOvalTop = currY - offsetnewOvalRight = ovalRight + offsetnewOvalBottom = ovalBottom - offset - offsetrectF!![newOvalLeft.toFloat(), newOvalTop.toFloat(), newOvalRight.toFloat()] =newOvalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)}1 -> {currX = scroller!!.currXoffset = currX - ovalLeftnewOvalLeft = currX + offsetnewOvalTop = ovalTop - offsetnewOvalRight = ovalRight - offset + offsetnewOvalBottom = ovalBottom + offsetrectF!![newOvalLeft.toFloat(), newOvalTop.toFloat(), newOvalRight.toFloat()] =newOvalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)}2 -> {currY = scroller!!.currYoffset = currY - ovalTopnewOvalLeft = ovalLeft - offsetnewOvalTop = currY + offsetnewOvalRight = ovalRight + offsetnewOvalBottom = ovalBottomrectF!![newOvalLeft.toFloat(), newOvalTop.toFloat(), newOvalRight.toFloat()] =newOvalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)Log.i("qq", "圆挤压成椭圆,方向向南 currY=$currY offset=$offset")Log.i("qq","圆挤压成椭圆,方向向南 newOvalLeft=$newOvalLeft newOvalTop=$newOvalTop newOvalRight=$newOvalRight newOvalBottom=$newOvalBottom")}3 -> {currX = scroller!!.currXoffset = currX - ovalLeftnewOvalLeft = currX - offsetnewOvalTop = ovalTop - offsetnewOvalRight = ovalRight - offset - offsetnewOvalBottom = ovalBottom + offsetrectF!![newOvalLeft.toFloat(), newOvalTop.toFloat(), newOvalRight.toFloat()] =newOvalBottom.toFloat()canvas.drawOval(rectF!!, paint!!)}}invalidate()} else {canvas.drawOval(rectF!!, paint!!)reverse()}}/*** 碰撞变形结束后,开启弹一弹效果*/fun startShotBack() {when (mCurrentDirection) {0 -> scroller!!.startScroll(ovalLeft, ovalTop, 0, shotBackChange, shotBackDuration)1 -> scroller!!.startScroll(ovalLeft, ovalTop, -shotBackChange, 0, shotBackDuration)2 -> scroller!!.startScroll(ovalLeft, ovalTop, 0, -shotBackChange, shotBackDuration)3 -> scroller!!.startScroll(ovalLeft, ovalTop, shotBackChange, 0, shotBackDuration)}invalidate()}/*** 结束 “弹的一段距离”*/fun finishShotBack() {when (mCurrentDirection) {0 -> scroller!!.startScroll(ovalLeft, ovalTop, 0, -shotBackChange, shotBackDuration)1 -> scroller!!.startScroll(ovalLeft, ovalTop, shotBackChange, 0, shotBackDuration)2 -> scroller!!.startScroll(ovalLeft, ovalTop, 0, shotBackChange, shotBackDuration)3 -> scroller!!.startScroll(ovalLeft, ovalTop, -shotBackChange, 0, shotBackDuration)}invalidate()}/*** 移动小球*/fun moveTo(l: Int, t: Int, direction: Int, duration: Int, shotBack: Boolean) {isShotBack = shotBackmDuration = durationmCurrentDirection = directionmoveToLeft = lmoveToTop = tif (t == 0) {mCurrentDirection = 0startChange(30)} else if (l == displayWidth - bubbleWidth) {mCurrentDirection = 1startChange(30)} else if (t == displayHeight - bubbleHeight) {mCurrentDirection = 2startChange(30)} else if (l == 0) {mCurrentDirection = 3startChange(30)} else {invalidate()}}/*** 开始变形*/private fun startChange(change: Int) {changelength = changeif (mShotOver != null) {mShotOver!!.bubbleShotStart(mCurrentDirection)}flag = 0
//发生变形时,先初始化椭圆刚发生变形时的位置ovalLeft = moveToLeftovalTop = moveToTopovalRight = moveToLeft + bubbleWidthovalBottom = ovalTop + bubbleHeightwhen (mCurrentDirection) {0 -> scroller!!.startScroll(moveToLeft, moveToTop, 0, changelength, mDuration)1 -> scroller!!.startScroll(moveToLeft, moveToTop, changelength, 0, mDuration)2 -> scroller!!.startScroll(moveToLeft, moveToTop, 0, changelength, mDuration)3 -> scroller!!.startScroll(moveToLeft, moveToTop, changelength, 0, mDuration)}Log.i("qq","小球开始变形,方向=$mCurrentDirection 当前小球的坐标ovalLeft=$ovalLeft ovalTop=$ovalTop ovalRight=$ovalRight ovalBottom=$ovalBottom")invalidate()}/*** 回复变形前的状态*/private fun reverse() {flag = 1when (mCurrentDirection) {0 -> scroller!!.startScroll(newOvalLeft, newOvalTop, 0, -changelength, mDuration)1 -> scroller!!.startScroll(newOvalLeft, newOvalTop, -changelength, 0, mDuration)2 -> scroller!!.startScroll(newOvalLeft, newOvalTop, 0, -changelength, mDuration)3 -> scroller!!.startScroll(newOvalLeft, newOvalTop, -changelength, 0, mDuration)}invalidate()}fun setShotOver(shotOver: ShotOver?) {mShotOver = shotOver}/*** 碰撞变形效果完成*/interface ShotOver {fun bubbleShotStart(direction: Int)fun bubbleShotEnd()}/*** (辅助函数)//没有实现效果* 圆挤压成椭圆时,变形加速减少*//*public void circleToOvalAndAcceleratedReduce(Canvas canvas){if(gradient == 0){newOvalLeft = ovalLeft;newOvalTop = ovalTop;newOvalRight = ovalRight;newOvalBottom = ovalBottom;}if((offset - oldOffset) >= 10 && gradient == 0){Log.i("qq", "移动距离大于10时绘制一次");newOvalLeft = ovalLeft - offset;newOvalTop = currY - offset;newOvalRight = ovalRight + offset;newOvalBottom = ovalBottom - offset - offset;rectF.set(newOvalLeft, newOvalTop, newOvalRight, newOvalBottom);canvas.drawOval(rectF, paint);oldOffset = offset;gradient = 1;}else if((offset - oldOffset) >= 7 && gradient == 1){Log.i("qq", "移动距离大于7时绘制一次");newOvalLeft = ovalLeft - offset;newOvalTop = currY - offset;newOvalRight = ovalRight + offset;newOvalBottom = ovalBottom - offset - offset;rectF.set(newOvalLeft, newOvalTop, newOvalRight, newOvalBottom);canvas.drawOval(rectF, paint);gradient = 2;oldOffset = offset;}else if((offset - oldOffset) >= 4 && gradient == 2){Log.i("qq","移动距离大于4时绘制一次");newOvalLeft = ovalLeft - offset;newOvalTop = currY - offset;newOvalRight = ovalRight + offset;newOvalBottom = ovalBottom - offset - offset;rectF.set(newOvalLeft, newOvalTop, newOvalRight, newOvalBottom);canvas.drawOval(rectF, paint);gradient = 3;oldOffset = offset;}else if((offset - oldOffset) >= 2 && gradient == 3){Log.i("qq","移动距离大于2时绘制一次");newOvalLeft = ovalLeft - offset;newOvalTop = currY - offset;newOvalRight = ovalRight + offset;newOvalBottom = ovalBottom - offset - offset;rectF.set(newOvalLeft, newOvalTop, newOvalRight, newOvalBottom);canvas.drawOval(rectF, paint);gradient = -1;oldOffset = offset;}else{Log.i("qq", "移动绘制一次");rectF.set(newOvalLeft, newOvalTop, newOvalRight, newOvalBottom);canvas.drawOval(rectF, paint);}Log.i("qq", "圆挤压成椭圆,方向向北 currY=" + currY + " offset=" + offset);Log.i("qq", "圆挤压成椭圆,方向向北 newOvalLeft=" + newOvalLeft + " newOvalTop=" + newOvalTop + " newOvalRight=" + newOvalRight + " newOvalBottom=" + newOvalBottom);}*/
}

/*** 1.根据重力感应移动小球* 2.一般重力感应使用的重力加速,这样的话每次移动距离不是固定的* 3.此应用,将速度固定。* 4.小球碰撞到边缘时,会发生形变。(小球压缩形变)* 5.可以点击按钮添加,发生形变后回弹效果*/
class AnimationActivity : Activity(), View.OnClickListener {private var sensorManager: SensorManager? = nullprivate var sensor: Sensor? = nullprivate var init = false// 因为布局是填充父窗体的,且设置了出掉状态栏,所有求出的宽高就是屏幕的宽高。private var containerWidth = 0private var containerHeight = 0// 小球的宽高private val ballWidth = 360private val ballHeight = 360// 自定义球private lateinit var ball: BallViewTwo// 小球的起始位置private var ballX = 100fprivate var ballY = 100fprivate var currentState = -1 // 初始方向private var shotDirection = -1 // 小球发生碰撞时的那刻的方向// 初始化 东 西 南 北 四个方向private val NORTH = 0private val EAST = 1private val SOUTH = 2private val WEST = 3private var constantsSpeed = 100 // 每次斜边移动的距离private val SPEED = 10 // 比例private var canMove = true // 小球是否可以移动private val durationPiece = 150 // 执行动画的时间块private var duration = 450 // 初始速度下的执行时间private var isShotBack = false/*** -1: 小球正常移动* 0: 小球正在碰撞* 1: 小球碰撞刚结束*/private var shot = -1/** Called when the activity is first created. */override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN)setContentView(R.layout.activity_animation)// 初始化重力感应sensorManager = getSystemService(SENSOR_SERVICE) as SensorManagersensor = sensorManager!!.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)}private fun init() {val container = findViewById<View>(R.id.ball_container)findViewById<View>(R.id.accelerate).setOnClickListener(this) // 加速移动findViewById<View>(R.id.reduce).setOnClickListener(this) // 减少移动findViewById<View>(R.id.normal).setOnClickListener(this) // 正常速度移动findViewById<View>(R.id.isShowBack).setOnClickListener(this) // 是否弹一弹containerWidth = container.widthcontainerHeight = container.heightball = findViewById(R.id.ball)/*** 碰撞监听*/ball.setShotOver(object : BallViewTwo.ShotOver {override fun bubbleShotStart(direction: Int) {shotDirection = directionshot = 0 // 正在压缩变形canMove = false// Log.i("shotDirection", "小球发生碰撞时的方向==" + shotDirection);}override fun bubbleShotEnd() {shot = 1 // 刚压缩变形结束}})}/*** 移动小球* @param x* @param y*/private fun moveTo(x: Float, y: Float) {ballX += xballY += yif (ballX < 0) {ballX = 0f}if (ballY < 0) {ballY = 0f}if (ballX > containerWidth - ballWidth) {ballX = (containerWidth - ballWidth).toFloat()}if (ballY > containerHeight - ballHeight) {ballY = (containerHeight - ballHeight).toFloat()}ball.moveTo(ballX.toInt(), ballY.toInt(), currentState, duration, isShotBack)}private val listener = object : SensorEventListener {override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) {// TODO Auto-generated method stub}override fun onSensorChanged(event: SensorEvent) {if (!init) returncurrentState = calc(event)// 如果当前方向不等于碰撞方向 并且圆刚碰撞结束if (shotDirection != currentState && shot == 1) {canMove = true}Log.i("direction", "当前方向==$currentState canMove=$canMove")// 可以移动的话才计算移动速度,调用移动方法if (canMove) {// 如果刚碰撞结束,根据位置,将其挪动一段距离if (shot == 1) {when (shotDirection) {0 -> moveTo(0f, 20f)1 -> moveTo(-20f, 0f)2 -> moveTo(0f, -20f)3 -> moveTo(20f, 0f)}shot = -1// 直接移动小球} else {constantSpeed(event)}} else {Log.i("qq", "正在执行“弹”,所以先不移动小球")}}}/*** 计算x,y轴应该移动的值(为了使每次移动距离保持不变)* @param event*/private fun constantSpeed(event: SensorEvent) {val x = event.values[SensorManager.DATA_X] * SPEEDval y = event.values[SensorManager.DATA_Y] * SPEEDval tan = x / yval movey: Doubleval movex: Doubleif (x == 0f && y != 0f) {movex = 0.0movey = constantsSpeed.toDouble()} else if (x != 0f && y == 0f) {movex = constantsSpeed.toDouble()movey = 0.0} else if (x == 0f && y == 0f) {movex = 0.0movey = 0.0} else {val temp = constantsSpeed / (tan * tan + 1)movey = Math.sqrt(temp.toDouble()) // 开根号movex = movey * tan}moveTo((if (x < 0) -Math.abs(movex) else Math.abs(movex)).toFloat(),(if (y < 0) -Math.abs(movey) else Math.abs(movey)).toFloat())}// 注册重力感应监听private fun register() {sensorManager?.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_GAME)}// 解除重力感应监听private fun unregister() {sensorManager?.unregisterListener(listener)Log.i("vv", "结束监听")}override fun onWindowFocusChanged(hasFocus: Boolean) {super.onWindowFocusChanged(hasFocus)if (hasFocus && !init) {init()init = true}}/*** 计算当前球的方向*/private fun calc(event: SensorEvent): Int {val x = event.values[0]val y = event.values[1]val tempVertical: Intval tempHorizontal: InttempHorizontal = when {x > 0 -> WESTx < 0 -> EASTelse -> -1}tempVertical = when {y > 0 -> SOUTHy < 0 -> NORTHelse -> -1}currentState = when {tempHorizontal == EAST && tempVertical == NORTH ->if (Math.abs(x) > Math.abs(y)) EAST else NORTHtempHorizontal == EAST && tempVertical == SOUTH ->if (Math.abs(x) > Math.abs(y)) EAST else SOUTHtempHorizontal == WEST && tempVertical == NORTH ->if (Math.abs(x) > Math.abs(y)) WEST else NORTHtempHorizontal == WEST && tempVertical == SOUTH ->if (Math.abs(x) > Math.abs(y)) WEST else SOUTHelse -> currentState}return currentState}override fun onDestroy() {super.onDestroy()unregister()}override fun onPause() {super.onPause()unregister()}override fun onRestart() {super.onRestart()register()}override fun onResume() {super.onResume()register()}override fun onClick(v: View) {when (v.id) {R.id.accelerate -> adjustSpeedAndDuration(5)R.id.reduce -> adjustSpeedAndDuration(-5)R.id.normal -> {constantsSpeed = 10duration = 450}R.id.isShowBack -> isShotBack = !isShotBack}}/*** 改变小球的移动速度和变形时间* 因为移动速度越快,碰撞时间越短*/private fun adjustSpeedAndDuration(change: Int) {constantsSpeed += changeduration = if (change < 0) {duration + durationPiece} else {duration - durationPiece}when {constantsSpeed <= 5 -> {constantsSpeed = 5duration = 750}constantsSpeed >= 25 -> {constantsSpeed = 25duration = 150}}}
}

 xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:tools="http://schemas.android.com/tools"tools:context=".ui.activity.AnimationActivity"><FrameLayoutandroid:id="@+id/ball_container"android:layout_width="match_parent"android:layout_height="match_parent"><com.hjq.demo.animationdemo.BallViewTwoandroid:id="@+id/ball"android:layout_width="360dp"android:layout_height="360dp" /></FrameLayout><Buttonandroid:id="@+id/accelerate"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="加速" /><Buttonandroid:id="@+id/reduce"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/accelerate"android:text="减速" /><Buttonandroid:id="@+id/normal"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/reduce"android:text="正常速度" /><Buttonandroid:id="@+id/isShowBack"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/normal"android:text="是否弹一弹" />
</RelativeLayout>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/26902.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

RedHat9 | Mariadb数据库的配置与管理

一、实验环境 1、Mariadb数据库介绍 MariaDB数据库管理系统是一个开源的关系型数据库管理系统&#xff0c;与MySQL高度兼容&#xff0c;并提供了更多的功能和性能优化。 起源和背景 MariaDB是MySQL的一个分支&#xff0c;主要由开源社区维护。由MySQL的创始人Michael Widen…

体验亚马逊AIGC——Amazon Bedrock

前言 随着人工智能技术的不断发展&#xff0c;我们已经进入了一个全新的时代&#xff0c;即AI驱动的时代。在这个时代&#xff0c;人工智能已经逐渐成为我们生活中不可或缺的一部分&#xff0c;它可以帮助我们更好地处理各种复杂的问题&#xff0c;提高我们的工作效率&#xff…

UDP的组播发送与接收C语言测试和nc接收组播测试

组播这个东西&#xff0c;很多年前用过一次。本身的原理不复杂&#xff0c;未知的是使用的环境&#xff0c;受使用环境的影响有多大&#xff0c;还是那句废话&#xff0c;具体问题具体分析。 发送端代码multicast.c #include <stdio.h> #include <stdlib.h> #…

鸿蒙开发:【设置任务快照的图标和名称】

设置任务快照的图标和名称 设置任务快照的图标和名称是为了提高用户界面的可视化性和用户体验&#xff0c;以便更好地管理和跟踪应用程序中的任务和功能。通过为每个任务快照设置不同的图标和名称&#xff0c;可以更轻松地区分和识别每个任务的功能。 默认情况下任务快照的图…

python-pandas获取excel表中每个sheet的名称

安装 pandas 首先确保安装了 pandas 和 openpyxl&#xff08;用于处理 Excel 文件&#xff09; pip install pandas openpyxlimport pandas as pd 加载 Excel 文件 excel_file pd.ExcelFile(your_excel_file.xlsx)获取所有工作表的名称 sheet_names excel_file.sheet_na…

C++基础知识(八:STL标准库 Map和multimap )

Map C 标准模板库&#xff08;STL&#xff09;中的 map 容器是一种非常有用的关联容器&#xff0c;用于存储键值对&#xff08;key-value pairs&#xff09;。在 map 中&#xff0c;每个元素都由一个键和一个值组成&#xff0c;其中键是唯一的&#xff0c;而值则可以重复。 基…

vue3+el-plus对eleplus对el-table表格进行拖拽(使用sortablejs进行列拖拽和行拖拽):

先看看是不是你需要的&#xff1a; 表格行和列拖拽 如有对表格拖拽进行限制某列或某行不进行拖拽的需求&#xff0c;请点击&#xff1a; vue3ele-plussortableJs对el-table使用sortableJs插件对表格拖拽时限定某列或某行不允许拖拽-CSDN博客 如果你已实现拖拽需求&#xff0c…

mybatis中resultMap和resultType的区别

总结 基本映射 &#xff1a;&#xff08;resultType&#xff09;使用resultType进行输出映射&#xff0c;只有查询出来的列名和pojo中的属性名一致&#xff0c;该列才可以映射成功。&#xff08;数据库&#xff0c;实体&#xff0c;查询字段,这些全部都得一一对应&#xff09;…

编程入门:Visual Studio探秘之旅

编程入门&#xff1a;Visual Studio探秘之旅 步入编程的世界&#xff0c;选择一个合适的开发工具至关重要。Visual Studio&#xff0c;这款由微软推出的强大集成开发环境&#xff08;IDE&#xff09;&#xff0c;无疑是初学者的理想之选。它不仅提供了丰富的功能&#xff0c;还…

运算符分为哪几类?哪些运算符常用作判断?简述运算符的优先级

运算符包含6大类&#xff1a;算术运算符、赋值运算符、比较运算符、逻辑运算符、位运算符、三元&#xff08;目&#xff09;运算符。 逻辑运算符常用作布尔判断 typeof 运算符: typeof 运算符用于确定变量或表达式的数据类型&#xff0c;并返回一个表示类型的字符串。 typeof …

一文让你清晰了解医疗行业采购堡垒机的必要性

医疗行业&#xff0c;一个与大家息息相关的行业。随着医疗行业的快速发展和信息化建设的深入推进&#xff0c;传统网络安全防护手段已经难以满足现代医疗信息系统的安全需求&#xff0c;特别是在处理敏感的患者信息和保障医院内部数据安全方面。因此采购堡垒机是非常必要的。 堡…

ssm160基于Java技术的会员制度管理的商品营销系统的设计与实现+vue

商品营销系统计与实现 摘 要 现代经济快节奏发展以及不断完善升级的信息化技术&#xff0c;让传统数据信息的管理升级为软件存储&#xff0c;归纳&#xff0c;集中处理数据信息的管理方式。本商品营销系统就是在这样的大环境下诞生&#xff0c;其可以帮助管理者在短时间内处理…

【面试经典150题】【双指针】392. 判断子序列

题目链接 https://leetcode.cn/problems/is-subsequence/?envTypestudy-plan-v2&envIdtop-interview-150 题解思路 首先如果s的长度大于t的长度&#xff0c;那么s肯定不是t的子序列如果s的长度等于t的长度&#xff0c;那么st的情况下s才是t的子序列如果s的长度小于t的长…

单片机课设-基于单片机的电子时钟设计(仿真+代码+报告)

基于单片机的电子时钟设计 前言一、课设任务是什么?二、系统总体方案硬件设计2.1 系统硬件总体设计2.2 键盘电路设计2.3 DS1302实时时钟芯片电路设计2.4 复位电路2.5 LCD电路设计 三、软件设计3.1 主程序流程图3.2 主要程序设计代码3.3 修改时间函数3.4 扫描键盘函数 四、仿真…

Pytest 记录日志输出到控制台和写入文件

目录 自定义日志记录器和内置的日志记录器 项目代码 项目目录树 自定义日志记录器 函数源代码 pytest中定义和覆盖日志记录信息 使用cli定义Logging 使用pytest.ini定义Logging 修改单个测试级别的日志 日志输出的重要性不言而喻&#xff0c;不仅可以观测执行过程&…

纵深发力 持续推进,富格林平台发展势头喜人

自2024年2月1日正式上线以来,富格林互联网投融资平台已迅速崛起,吸引了业内专家学者的高度认可以及广大投资者的青睐。平台规模持续扩大,目前累计注册用户已超过10万人,总投资额突破50亿美元。这一卓越表现不仅体现了平台的稳健运营和出色的投资项目,也展示了其在互联网投融资领…

bash和sh区别

bash 和 sh 是两种常用的 Unix Shell&#xff0c;它们有一些区别&#xff0c;特别是在功能和兼容性方面。以下是一些主要的区别&#xff1a; 1. **历史与实现**&#xff1a; - sh&#xff08;Bourne Shell&#xff09;是第一个 Unix Shell&#xff0c;最初由 Stephen Bourn…

大型语言模型(LLMs)是如何工作的?

大型语言模型&#xff08;LLMs&#xff09;如ChatGPT、Bing的“Sydney”模式和Google的Bard正在占据新闻头条。与其讨论它们将使哪些工作变得过时&#xff0c;本文将探讨这些模型的工作原理&#xff0c;包括它们从哪里获取数据以及使它们能够生成令人信服的真实文本的基本数学方…

UG编程中圆柱体的精确编程之道

UG编程中圆柱体的精确编程之道 在UG编程的世界中&#xff0c;圆柱体作为一种基础且重要的几何形态&#xff0c;其编程过程既需要精确的技巧&#xff0c;又蕴含着深厚的理论知识。本文将从四个方面、五个方面、六个方面和七个方面&#xff0c;深入探讨如何在UG编程中精确创建圆…

【Docker】Docker 配置镜像加速

Docker配置镜像加速或配置源加速&#xff0c;主要是为了加快Docker镜像的拉取速度&#xff0c;特别是在网络环境较差或需要频繁拉取镜像的情况下。以下是一个详细的配置步骤。 1. 确定要使用的镜像源 首先&#xff0c;你需要选择一个或多个镜像源。以下是一些常见的Docker镜像…