143 lines
4.5 KiB
HTML
143 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Processed Content</title>
|
|
<link rel="stylesheet" href="../style/Style.css" />
|
|
<style>
|
|
/* Styling for the <think> block */
|
|
.think {
|
|
background-color: grey;
|
|
color: white;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
}
|
|
/* Styling for normal text (outside code blocks) */
|
|
.normal-text {
|
|
background-color: lightgrey;
|
|
color: black;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
}
|
|
/* Styling for code blocks */
|
|
.code-block {
|
|
background-color: black;
|
|
color: white;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
white-space: pre-wrap;
|
|
font-family: monospace;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="main_scrollable " style="background-color: rgba(4, 0, 255, 0);">
|
|
|
|
<main id="main"></main>
|
|
|
|
<!-- <p id="output" style="background-color: rgb(4, 40, 201);">No message yet.</p> -->
|
|
<script>
|
|
// The input string containing a <think> block, text, and a triple backtick code block.
|
|
const inputString = `
|
|
<think>
|
|
Okay, I need to help the user write a concise PyBullet code to simulate the default humanoid. Let me think about what they're asking for.
|
|
|
|
First, I remember that PyBullet is a physics simulation library. The user wants to simulate the built-in humanoid model. So, I should start by importing PyBullet and maybe some necessary modules like math.
|
|
|
|
I'll need to connect to PyBullet's server. Usually, you use bullet.start(). Then, create a physics client using p = bc.connect().
|
|
|
|
Next, set up the simulation parameters: gravity with bc.setGravity(), and enable real-time stepping for smoother visualization with bc.realTimeSimulation(1).
|
|
|
|
Loading the humanoid is next. The default model can be loaded with loadURDF. I'll place it at (0, 0, 1) to stand on the ground.
|
|
|
|
Then, I need a way to reset the simulation each time. Wrapping everything in a while loop that resets and steps the physics makes sense.
|
|
|
|
Adding a camera for visualization is important too. Set up a camera position and orientation, then enable it with bc.startStateLogging().
|
|
|
|
Finally, run the simulation until the user presses 'Q' to exit.
|
|
|
|
I should make sure the code is short and concise, avoiding unnecessary details. Including comments will help explain each part briefly.
|
|
</think>
|
|
|
|
Here's a concise PyBullet code to simulate the default humanoid:
|
|
|
|
\`\`\`python
|
|
import pybullet as p
|
|
import time
|
|
|
|
# Initialize PyBullet
|
|
p.connect(p.GUI)
|
|
|
|
# Set gravity
|
|
p.setGravity(0, 0, -10)
|
|
|
|
# Load the default humanoid (built-in model)
|
|
humanoid = p.loadURDF("humanoid.urdf", [0, 0, 1])
|
|
|
|
# Enable real-time simulation
|
|
p.realTimeSimulation(1)
|
|
|
|
# Simulation loop
|
|
while True:
|
|
# Step physics
|
|
p.stepSimulation()
|
|
time.sleep(1/240) # Adjust the timestep as needed
|
|
|
|
# Check for 'Q' key to exit
|
|
if ord(p.readKey()) == ord('Q'):
|
|
break
|
|
|
|
# Cleanup and disconnect
|
|
p.disconnect()
|
|
\`\`\`
|
|
|
|
This code will load and simulate the default humanoid model that comes with PyBullet, allowing you to interact with it in the PyBullet GUI. The humanoid will stand upright by default, but you can modify its behavior by adding
|
|
additional control code.`;
|
|
|
|
function processContent(str) {
|
|
let processedHTML = '';
|
|
|
|
// Extract and process the <think> block first.
|
|
const thinkRegex = /<think>([\s\S]*?)<\/think>/;
|
|
const thinkMatch = str.match(thinkRegex);
|
|
if (thinkMatch) {
|
|
const thinkContent = thinkMatch[1];
|
|
processedHTML += '<div class="think">' + thinkContent + '</div>';
|
|
// Remove the <think> block from the string.
|
|
str = str.replace(thinkRegex, '');
|
|
}
|
|
|
|
// Process the rest of the string by splitting at triple backticks.
|
|
// This will alternate between normal text and code blocks.
|
|
const parts = str.split(/```/);
|
|
parts.forEach((part, index) => {
|
|
if (index % 2 === 0) {
|
|
// Normal text outside code blocks.
|
|
if (part.trim()) {
|
|
processedHTML += '<div class="normal-text">' + part + '</div>';
|
|
}
|
|
} else {
|
|
// Code block content.
|
|
processedHTML += '<pre class="code-block">' + part + '</pre>';
|
|
}
|
|
});
|
|
return processedHTML;
|
|
}
|
|
|
|
// Process the input string and update the <main> tag.
|
|
document.getElementById('main').innerHTML = processContent(inputString);
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|