Drawing a spiral on an HTML canvas using JavaScript

The Archimedean spiral is expressed as r=a+b(angle). Convert that into x, y coordinate, it will be expressed as x=(a+b*angle)*cos(angle), y=(a+b*angle)*sin(angle). Then you can put angle in a for loop and do something like this: for (i=0; i< 720; i++) { angle = 0.1 * i; x=(1+angle)*Math.cos(angle); y=(1+angle)*Math.sin(angle); context.lineTo(x, y); } Note the above assumes a … Read more

Value Remapping

From your description, it ought to be doing this, right? low2 + (value – low1) * (high2 – low2) / (high1 – low1) Find how far you are into the first range, scale that distance by the ratio of sizes of the ranges, and that’s how far you should be into the second range.

Arithmetic Overflow vs. Arithmetic Carry

Overflow flags get set when the register cannot properly represent the result as a signed value (you overflowed into the sign bit). Carry flags are set when the register cannot properly represent the result as an unsigned value (no sign bit required).

Why is the range of signed byte is from -128 to 127 (2’s complement) and not from -127 to 127?

Why is the range of unsigned byte is from -128 to 127? It’s not. An unsigned byte (assuming 8-bit) is from 0 to 255. The range of a signed byte using 2’s complement is from -128 to 127, directly from the definition of 2’s complement: 01111111 = +127 01111110 = +126 01111101 = +125 … … Read more

How to perform bilinear interpolation in Python

Here’s a reusable function you can use. It includes doctests and data validation: def bilinear_interpolation(x, y, points): ”’Interpolate (x,y) from values associated with four points. The four points are a list of four triplets: (x, y, value). The four points can be in any order. They should form a rectangle. >>> bilinear_interpolation(12, 5.5, … [(10, … Read more

javascript / jquery – select the larger of two numbers

You’re looking for the Max function I think…. var c = Math.max(a, b); This function will take more than two parameters as well: console.log(Math.max(4,76,92,3,4,12,9)); //outputs 92 If you have a array of arbitrary length to run through max, you can use apply… var arrayOfNumbers = [4,76,92,3,4,12,9]; console.log(Math.max.apply(null, arrayOfNumbers)); //outputs 92 OR if you’re using ES2015+ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)