Gemini 2.0 Flash Thinking Experimental 01-21 好强

测试的是:python: 小球在旋转的六边形内部滚动,逼真的模拟小球的弹性,重力以及为六边形内部边框的摩擦力,think in english,show me the code.

python_vXazBg9Zc7

效果好,速度快!30秒以内

import pygame
import math

# Initialize Pygame
pygame.init()

# Screen dimensions
WIDTH = 800
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Rotating Hexagon Ball Simulation")

# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)

# Physics constants
GRAVITY = 0.5  # Gravity strength
FRICTION = 0.01 # Friction coefficient (adjust for desired friction)
ELASTICITY = 0.8 # Elasticity of the ball (0.0 to 1.0, 1.0 is perfectly elastic)
ROTATION_SPEED = 0.02 # Speed of hexagon rotation

class Ball:
    def __init__(self, x, y, radius, color):
        self.x = x
        self.y = y
        self.radius = radius
        self.color = color
        self.vx = 0  # Velocity in x direction
        self.vy = 0  # Velocity in y direction

    def draw(self, screen):
        pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), self.radius)

    def move(self):
        self.vy += GRAVITY  # Apply gravity

        # Apply friction (simple linear friction opposing velocity)
        friction_x = -FRICTION * self.vx
        friction_y = -FRICTION * self.vy
        self.vx += friction_x
        self.vy += friction_y

        self.x += self.vx
        self.y += self.vy


class Hexagon:
    def __init__(self, center_x, center_y, radius, color):
        self.center_x = center_x
        self.center_y = center_y
        self.radius = radius
        self.color = color
        self.rotation_angle = 0  # Rotation angle in radians

    def get_vertices(self):
        vertices = []
        for i in range(6):
            angle_deg = 60 * i - 90 # Start from top vertex
            angle_rad = math.radians(angle_deg)
            x = self.center_x + self.radius * math.cos(angle_rad)
            y = self.center_y + self.radius * math.sin(angle_rad)
            vertices.append((x, y))
        return vertices

    def get_rotated_vertices(self):
        vertices = self.get_vertices()
        rotated_vertices = []
        for x, y in vertices:
            angle = self.rotation_angle
            rotated_x = math.cos(angle) * (x - self.center_x) - math.sin(angle) * (y - self.center_y) + self.center_x
            rotated_y = math.sin(angle) * (x - self.center_x) + math.cos(angle) * (y - self.center_y) + self.center_y
            rotated_vertices.append((rotated_x, rotated_y))
        return rotated_vertices

    def draw(self, screen):
        rotated_vertices = self.get_rotated_vertices()
        pygame.draw.polygon(screen, self.color, rotated_vertices, 2) # Draw hexagon outline


def check_collision(ball, hexagon):
    rotated_vertices = hexagon.get_rotated_vertices()
    num_vertices = len(rotated_vertices)

    for i in range(num_vertices):
        p1 = rotated_vertices[i]
        p2 = rotated_vertices[(i + 1) % num_vertices] # Next vertex, wrap around to the first

        # Calculate the vector representing the edge
        edge_vector_x = p2[0] - p1[0]
        edge_vector_y = p2[1] - p1[1]

        # Calculate the vector from point p1 to the ball's center
        ball_vector_x = ball.x - p1[0]
        ball_vector_y = ball.y - p1[1]

        # Project ball_vector onto the normal of the edge vector.
        # Normal vector can be found by swapping and negating components of edge_vector
        normal_vector_x = -edge_vector_y
        normal_vector_y = edge_vector_x

        # Normalize the normal vector
        normal_magnitude = math.sqrt(normal_vector_x**2 + normal_vector_y**2)
        if normal_magnitude == 0: # Avoid division by zero if edge has zero length (shouldn't happen in regular hexagon)
            continue
        normal_vector_x /= normal_magnitude
        normal_vector_y /= normal_magnitude

        # Project ball_vector onto the normal vector (dot product)
        projection_length = ball_vector_x * normal_vector_x + ball_vector_y * normal_vector_y

        # If the projection length is less than or equal to the ball's radius, there's a potential collision
        if projection_length <= ball.radius:
            # Further check if the closest point on the edge is actually within the segment p1-p2

            # Project ball_vector onto the edge vector
            edge_magnitude_sq = edge_vector_x**2 + edge_vector_y**2
            if edge_magnitude_sq == 0: # Avoid division by zero if edge has zero length
                continue
            projection_on_edge = (ball_vector_x * edge_vector_x + ball_vector_y * edge_vector_y) / edge_magnitude_sq

            # Check if the projection falls within the segment (0 <= projection_on_edge <= 1)
            if 0 <= projection_on_edge <= 1:
                # Collision detected! Reflect the ball's velocity along the normal

                # Dot product of velocity and normal vector
                dot_product = ball.vx * normal_vector_x + ball.vy * normal_vector_y

                # Reflect velocity components
                ball.vx -= 2 * dot_product * normal_vector_x * ELASTICITY
                ball.vy -= 2 * dot_product * normal_vector_y * ELASTICITY

                # Slightly move ball out of collision to prevent sticking
                ball.x += normal_vector_x * (ball.radius - projection_length) * 1.1 # 1.1 to push slightly out
                ball.y += normal_vector_y * (ball.radius - projection_length) * 1.1
                return True # Collision handled, no need to check other edges for this frame

    return False # No collision


# Create ball and hexagon objects
ball = Ball(WIDTH // 2, HEIGHT // 4, 20, RED)
hexagon = Hexagon(WIDTH // 2, HEIGHT // 2, 150, WHITE)

# Game loop
running = True
clock = pygame.time.Clock()

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Update game state
    hexagon.rotation_angle += ROTATION_SPEED # Rotate the hexagon
    ball.move() # Move the ball based on physics

    # Collision detection
    check_collision(ball, hexagon)

    # Keep ball within screen bounds (optional, but prevents ball from going too far out)
    if ball.x - ball.radius < 0:
        ball.x = ball.radius
        ball.vx = -ball.vx * ELASTICITY # Bounce off left wall
    if ball.x + ball.radius > WIDTH:
        ball.x = WIDTH - ball.radius
        ball.vx = -ball.vx * ELASTICITY # Bounce off right wall
    if ball.y - ball.radius < 0:
        ball.y = ball.radius
        ball.vy = -ball.vy * ELASTICITY # Bounce off top wall
    if ball.y + ball.radius > HEIGHT:
        ball.y = HEIGHT - ball.radius
        ball.vy = -ball.vy * ELASTICITY # Bounce off bottom wall


    # Drawing
    screen.fill(BLACK) # Clear screen
    hexagon.draw(screen) # Draw hexagon
    ball.draw(screen)   # Draw ball

    pygame.display.flip() # Update the display

    clock.tick(60) # Limit frame rate to 60 FPS

pygame.quit()
31 个赞

deepseek官网开启推理模式也还行,但是摩擦力是不是有亿点点大~思考了426秒

python_JTU2LqTt75

import pygame
import math
from pygame.locals import *
import sys

# 初始化Pygame
pygame.init()
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Bouncing Ball in Rotating Hexagon")
clock = pygame.time.Clock()

# 颜色定义
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)

# 六边形参数
center = (width//2, height//2)
hex_radius = 150  # 六边形半径(中心到顶点的距离)
angular_speed = math.radians(45)  # 旋转速度(弧度/秒)
rotation_angle = 0

# 小球参数
ball_radius = 10
ball_pos = [width//2, height//2 - 100]  # 初始位置
ball_vel = [0.0, 0.0]
restitution = 0.8  # 恢复系数
friction = 0.3     # 摩擦系数
gravity = 980       # 重力加速度(像素/秒²)
dt = 0.01          # 时间步长(秒)

def compute_hexagon_vertices(center, radius, rotation):
    """计算旋转后的六边形顶点坐标"""
    vertices = []
    for i in range(6):
        theta = rotation + math.radians(60 * i)
        x = center[0] + radius * math.cos(theta)
        y = center[1] + radius * math.sin(theta)
        vertices.append((x, y))
    return vertices

def closest_point_on_segment(A, B, P):
    """计算点P到线段AB的最近点"""
    ax, ay = A
    bx, by = B
    px, py = P
    
    ab_vec = (bx - ax, by - ay)
    ap_vec = (px - ax, py - ay)
    
    t = (ap_vec[0]*ab_vec[0] + ap_vec[1]*ab_vec[1]) / (ab_vec[0]**2 + ab_vec[1]**2 + 1e-8)
    t = max(0, min(1, t))
    
    return (ax + t*ab_vec[0], ay + t*ab_vec[1])

running = True
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    # 更新六边形旋转角度
    rotation_angle += angular_speed * dt
    vertices = compute_hexagon_vertices(center, hex_radius, rotation_angle)

    # 碰撞检测与响应
    collision_occurred = False
    for i in range(6):
        A = vertices[i]
        B = vertices[(i+1)%6]
        
        # 计算最近点
        Q = closest_point_on_segment(A, B, ball_pos)
        
        # 计算距离和法线向量
        dx = ball_pos[0] - Q[0]
        dy = ball_pos[1] - Q[1]
        distance = math.hypot(dx, dy)
        
        if distance < ball_radius:
            # 计算边向量和法线
            edge_vec = (B[0]-A[0], B[1]-A[1])
            nx = -edge_vec[1]
            ny = edge_vec[0]
            norm = math.hypot(nx, ny)
            if norm == 0:
                continue
            nx /= norm
            ny /= norm

            # 计算边上的点的线速度
            qx_rel = Q[0] - center[0]
            qy_rel = Q[1] - center[1]
            vq_x = -angular_speed * qy_rel
            vq_y = angular_speed * qx_rel

            # 计算相对速度
            rel_vx = ball_vel[0] - vq_x
            rel_vy = ball_vel[1] - vq_y

            # 分解速度分量
            vn = (rel_vx * nx + rel_vy * ny) * nx
            vt_x = rel_vx - vn
            vt_y = rel_vy - (rel_vx * nx + rel_vy * ny) * ny

            # 应用碰撞响应
            new_vn = (-restitution * vn, -restitution * (rel_vx * nx + rel_vy * ny) * ny)
            new_vt = (vt_x * (1 - friction), vt_y * (1 - friction))

            # 更新速度
            ball_vel[0] = new_vn[0] + new_vt[0] + vq_x
            ball_vel[1] = new_vn[1] + new_vt[1] + vq_y

            # 位置修正
            penetration = ball_radius - distance
            ball_pos[0] += nx * penetration
            ball_pos[1] += ny * penetration

            collision_occurred = True
            break  # 每次只处理一个碰撞

    # 应用重力
    ball_vel[1] += gravity * dt

    # 更新位置
    ball_pos[0] += ball_vel[0] * dt
    ball_pos[1] += ball_vel[1] * dt

    # 绘制
    screen.fill(BLACK)
    pygame.draw.polygon(screen, WHITE, vertices, 2)
    pygame.draw.circle(screen, RED, (int(ball_pos[0]), int(ball_pos[1])), ball_radius)
    pygame.display.flip()
    
    clock.tick(100)

pygame.quit()
sys.exit()
10 个赞

有什么UI可以在线运行吗?

7 个赞

谷歌貌似是伪思考,不过确实家大业大算力很高,响应快

8 个赞

差距这么明显

3 个赞

我这两天在体验“google/gemini-2.0-flash-lite-preview-02-05:free”(openrouter的)感觉也不错,回答都是比较准确的。

6 个赞

gemini 2.0 flash 以及thinking还有2.0 pro的api目前都免费吗

3 个赞

同问,看你们都玩,我也想玩了

2 个赞

是的,暂时免费


1 个赞

0121的思考快得让我感觉是假的 :tieba_033:

2 个赞

cursor中配置谷歌这个api能免费调这个模型吗?

1 个赞

这个模型有啥特点呢

1 个赞

:rofl: 确实,飞快

1 个赞

伪思考是怎么一回事?求科普

1 个赞

粘贴代码到visual code运行

具体不清楚,但好像跟速度快有关系?就谷歌拿原本模型作为基底改的思考流,但不完全是思考,道听途说的

2 个赞

其实gemini 2.0系列我一直觉得很强

建议问点贴合生产力的编程问题,很多这种炫技的美化代码有点像是面向媒体优化的,体现不出真实力

4 个赞

这两个哪个写作能力强呀佬友

免费啊,我现在日常用得最多的就是gemini了