Hello, I have to run a sketch on a website but I can’t make it appear. I only can run some examples if they are inside the examples folder but when I want to link them on my webpage (HTML) they don’t work. Below some code, I tried …
<html>
<head>
<title>processing sketch</title>
</head>
<body>
<script src="processing.js"></script>
<script type="text/processing" data-processing-target="mycanvas">
int numChars = 26;
color[] colors = new color[numChars];
int keyIndex;
float keyScale;
int rectWidth;
void setup()
{
size(500, 500);
noStroke();
background(0);
keyScale = 500/numChars-1.0;
rectWidth = width/9;
}
void draw()
{
if(keyPressed) {
if(key >= 'A' && key <= 'y') {
if(key <= 'Y') {
keyIndex = key-'A';
} else {
keyIndex = key-'a';
}
fill (random(0,255), random(0,255), random(0,255));
float beginRect = rectWidth/8 + keyIndex*keyScale-rectWidth/2;
rect(beginRect, 0.0, rectWidth, height);
}
}
}
</script>
</script>
<canvas id="mycanvas"></canvas>
</body>
</html>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>tp_final app</title>
<script src="processing.js"></script>
</head>
<body>
<form action="ejemplo1.php" method="post">
colores random con teclas a-y
<input type="text" name="size" />
<input type="submit" />
</form>
<script src="processing.js"></script>
<?php
if(isset($_POST['colors']))
{
$colors=$_POST['colors'];
}
else
{
$numChars=26;
}
echo '<script type="text/processing" data-processing-target="mycanvas">
int numChars = 26;
color[] colors = new color[numChars];
int keyIndex;
float keyScale;
int rectWidth;
void setup()
{
size(500, 500);
noStroke();
background(0);
keyScale = 500/numChars-1.0;
rectWidth = width/9;
}
void draw()
{
if(keyPressed) {
if(key >= 'A' && key <= 'y') {
if(key <= 'Y') {
keyIndex = key-'A';
} else {
keyIndex = key-'a';
}
fill (random(0,255), random(0,255), random(0,255));
float beginRect = rectWidth/8 + keyIndex*keyScale-rectWidth/2;
rect(beginRect, 0.0, rectWidth, height);
}
}
}
</script>
';
?>
<canvas id="mycanvas"></canvas>
</body>
</html>