我试图画一个画布2个盒子,但我看不到任何东西。有没有人有想法?
char *receiveData(int sock)
{
int counter = 0, i = 0, j = 0;
char buffer[256];
bzero(buffer, 256);
int tempKey = symmetricKeyInt, KeyDigitsNumber = 0;
while (tempKey > 0)
{
tempKey /= 10;
KeyDigitsNumber++;
}
tempKey = symmetricKeyInt;
int KeyArr[KeyDigitsNumber];
for (j = KeyDigitsNumber - 1; j >= 0; j--)
{
KeyArr[j] = tempKey % 10;
tempKey = tempKey / 10;
}
read(sock, buffer, 255);
int bufferSize = ntohl(*((int*)&buffer))
char *temp;
char *decrypted = malloc(bufferSize);
char numBuffer[20];
int testInt;
int encInt;
for (j = 0; j < bufferSize; j++)
{
bzero(numBuffer, 20);
read(sock, numBuffer, 19);
testInt = ntohl(*((int*)&numBuffer)) ^ KeyArr[j %KeyDigitsNumber];
sprintf(temp, "%d", testInt);
decrypted[j] = temp;
}
printf("THis from inside receiveData function: %s\n", (char *)decrypted);
return decrypted;
}
答案 0 :(得分:0)
id="canvas"
而非使用getElementById("canvas")
ctx
作为CanvasRendering的简写上下文(不是canvas
)ctx.fill()
var arena = {
o1: ['gate', 5, 5, 20, 20],
o2: ['block', 50, 40, 30, 40]
};
$(document).ready(function() {
var c = document.getElementById('canvas');
var ctx = c.getContext("2d");
ctx.lineWidth = "6";
ctx.strokeStyle = "red";
var xpercent = c.width / 100;
var ypercent = c.height / 100;
for (var key in arena) {
var arr = arena[key];
ctx.beginPath();
ctx.rect(arr[1] * xpercent, arr[2] * ypercent, arr[3] * xpercent, arr[4] * ypercent);
ctx.fill();
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="canvas"></canvas>
&#13;