Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. It's not working because you haven't defined stopDrawing() in the right place. It's inside an anonymous function, so it's only accessible inside that anonymous function. Declare the stopDrawing() function outside of all the other functions. Make sure it's not between any pair of braces { }.
  2. Like I mentioned, it's important that the variable interval is global, meaning that the statement var interval has to be outside of all the functions and the var keyword can't be used for the variable inside the function, making it simply interval = setInterval( without the var next to it.
  3. Remove this part of the code: if(timesRun === 300){clearInterval(interval); } You want the spirograph to stop when the button is clicked. The button is calling the stopDrawing() function, which you haven't created yet. Important: Make the variable interval global. Then you can stop the function using clearInterval in the stopDrawing function: function stopDrawing() { clearInterval(interval);}
  4. You'll have to configure the server to send .vpd files with a Content-Disposition of "attachment" Some servers can be configured with a .htaccess file in the directory, but others need to be changed from the server configuration files. <IfModule mod_headers.c><FilesMatch ".vpd$"> Header set Content-Disposition "attachment"</FilesMatch></IfModule> This is for apache servers.
  5. This looks like a problem with the browser itself. I don't think there's any way to solve it.
  6. Giving random values to "r" and "O" probably won't work, they need to be within a range that will have a noticeable effect. It looks like "r" probably would work best with a value between 10 or 50. The units of measurement are pixels, so 0.9 is a value smaller than one pixel. You need to go back to the place where you found this script and find out what the code authors meant to do with those variables. I'm not sure, but I think "O" is meant the center of the inner circle. The variable "t" is increasing a lot in each step, try increasing t by a smaller amount, such as t += 0.01 and you'll begin to see something happen. The spirograph is centered on the top left corner of the canvas. You will have to move the center by adding a horizontal and vertical offset to the final result of the calculations just before passing them to the lineTo() function.
  7. The space character is the same in all encodings. If you just want to remove spaces that will work. If you want to include line breaks and tabs as whitespace then you can select the appropriate characters. Functions like trim() consider the following characters whitespace, and since they're all single-byte characters they should work for pretty much any encoding: s or x20 or " " Space t Tab n New line r Carriage return 0 Null byte x0B Vertical tab The following regular expression will normalize all those: preg_replace('/[x20tnr0x0B]+/',' ',$str); For these characters the character set doesn't matter because almost all character sets share the same characters from 0 to 127.
  8. Simply setting the src attribute of an <img> element will make it display. // Create the imagevar img = document.createElement("img");// Set the file nameimg.src = "a.jpg"// Add it to an elementdocument.body.appendChild(img);
  9. You can put margin on the element that's immediately wrapped around the text or you can use padding instead.
  10. Every element has a contentEditable property which you can manipulate with Javascript. I haven't worked with it a lot, myself, but here's a page discussing it: http://stackoverflow.com/questions/20830353/how-to-make-html-content-editable-with-javascript-jquery
  11. If instead of clear: both you use clear: left then it won't go below the right column.
  12. Javascript is the language you have to use to make browser games, but in order to fully understand Javascript you first need to know HTML and CSS, because Javascript interfaces with these. So the usual learning order is HTML, then CSS and then Javascript.
  13. It probably could if the element above it is also floated. You can wrap the text in an element and use the clear property to make it go below: <div class="content"> test!</div>.content { clear: both;}
  14. The reason is that .standard is floated to the left. Content that follows it will go to the right side of it.
  15. In programming there's always more than one way to do a job. What they made there looks like a slightly different way to make a spirograph. It probably would work if you gave it the right values, but your code (as presented int he first post) is missing variables "r" and "O" which is why it's not working. Wherever you got the equations from, it would be important that they explained the meaning of R, r and O. Also remember that Javascript uses Math.cos() and Math.sin() rather than cos() and sin() My version of a spirograph is based on something simple to understand. I probably should have included a diagram explaining it. Their script has something mine doesn't: It's animated. This can be achieved by substituting the for() loop for a function that is called using setInterval() and stopped with another function that calls clearInterval.
  16. You probably got an error message that didn't show up because you have error reporting disabled. You can't print any content before sending a header. No echo statements or HTML. headers have to be the first thing sent to the client. When you redirect to another page, there's no point at all in displaying any content because the user is leaving the current page. Put the alert message on the destination page instead.
  17. Ingolme

    SQL Question

    I'm not exactly sure how you would get SQL to show two results of the same field twice in each row. Are you sure you understood the question properly? By using the ORDER BY property, frogs of the same habitat will be grouped together. If you use ths query SELECT * FROM Frogs ORDER BY FrogHabitat the results will be like this: FrogName FrogHabitat Wood frog Denmark Hill frog France Sky frog Germany Wood frog Iceland Sky frog Iceland Hill frog Sweden Wood frog Sweden
  18. Ingolme

    json question

    It would be x[date][attribute] Objects can be accessed in the same way arrays are: object.property = 5; or object["property"] = 5; or x = "property"; object[x] = 5;
  19. I'm not sure if you got your script from somewhere else, but what's important is understanding how it works. In a spirograph There are two radii, one for the main circle and one for the outside circle. Then there is a ratio of angular velocity between each one (for each degree/radian/cycle on the inner radius how many degrees/radians/cycles does the outer radius do?) Then you have to decide the resolution at which you want to draw the circle, how many segments you're dividing the circle into. The more resolution you give it, the less it will look like a bunch of straight lines put together. Attached is a working example. Here's the explanation: Let's create some input variables:innerRadius = 200 (You could have a user input this value) outerRadius = 100 (You could have a user input this value) ratio = 10 (You could have a user input this value) resolution = 10000 (You probably want this to be very high) This is the amount we move around the circle in each loop iteration: minAngle = 2*PI / resolution Now we need a temporary variable for the current angle: On each iteration innerAngle = i * minAngle; The outer angle is determined by the inner angle and the ratio: outerAngle = innerAngle * ratio We know that in a circle, the X position is given by the cosine of the angle and the Y position is given by the sine of the angle. X = cos(angle) * radius Y = sin(angle) * radius Where to draw The answer to where the "pencil" is in each iteration is given by the X and Y of the inner circle, plus the offsets given by the outer circle innerX = cos(innerAngle) * innerRadius innerY = sin(innerAngle) * innerRadius outerX = cos(outerAngle) * outerRadius outerY = sin(outerAngle) * outerRadius globalX = innerX + outerX globalY = innerY + outerY Offsets Now there's one last thing to do: Our circle is centered on the top left corner of the screen. To fix this will add half the canvas width and half the canvas height to the results: realX = globalX + (0.5* canvas.width) realY = globalY + (0.5* canvas.width) Now draw a line to (canvas lineTo() method) realX and to realY Extra detail: If you use lineTo inside the loop without setting the position first you'll start off with a line from the top left corner of the page to the first point in the spirograph. To prevent this, outside the loop calculate the X and Y for the first point in the spirgraph (inner angle 0, outer angle 0) and use moveTo() to start the cursor there. example.html
  20. Ingolme

    SQL Question

    You can ORDER BY habitat. Frogs of the same habitat will be grouped together. When looping through the results in PHP you can check when the habitat name changes in order to put separations between them.
  21. CSS is the one language you use for layouts, so that forum is good for layout discussion.
  22. The word is case sensitive. "About.html" is not the same as "about.html" Also make sure that the file is in the right folder.
  23. You could even put $_SESSION['name'] right in the function.
  24. The XML language doesn't have variables. If you want the contents of a PHP variable in your XML document, just pass the variable to the function: $value = 'Some text';$textNode= $xml->createTextNode($value); When using variables in PHP you don't wrap them in quotation marks, especially not single quotes. In PHP single quotes print out literally what is between them. Double quotes print text, special characters and variables. If all you want is the value of the variable itself, then don't use any quotation marks at all. The variable has the value in it already.
  25. Iframes are basic HTML: http://www.w3schools.com/html/html_iframe.asp It will show whatever is in the RSS feed when it loads.
×
×
  • Create New...