Difference between revisions of "ARM: Sierpinski triangle"
From ScienceZero
(Created page with "Draws the sierpinski triangle on a 320x256 screen with 8 bits per pixel. MOV R9,#320 ; Screen width MOV R2,#5 ; R...") |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | Draws the sierpinski triangle on a 320x256 screen with 8 bits per pixel. | + | Draws the sierpinski triangle on a 320x256 screen with 8 bits per pixel using the chaos game method. A vertex of a triangle is selected at random and averaged with the current position to find the new position to plot a pixel. |
MOV R9,#320 ; Screen width | MOV R9,#320 ; Screen width | ||
| Line 9: | Line 9: | ||
MOV R12,#128 | MOV R12,#128 | ||
| − | .LOOP RSB R2,R2,R2,ROR #21 ; Generate random number in the range 0 to 2 | + | .LOOP RSB R2,R2,R2,ROR #21 ; Generate pseudo random number in the range 0 to 2 |
MOVS R3,R2,LSR #31 ; LSB in carry, MSB in R3 | MOVS R3,R2,LSR #31 ; LSB in carry, MSB in R3 | ||
BHI LOOP ; Repeat if 3 | BHI LOOP ; Repeat if 3 | ||
| − | ADDCC R11,R11,R4,LSL R3 ; Calculate position | + | ADDCC R11,R11,R4,LSL R3 ; Calculate new position halfway |
ADDCC R12,R12,R3,LSL #8 ; between the old and the new vertex | ADDCC R12,R12,R3,LSL #8 ; between the old and the new vertex | ||
ADDCS R12,R12,#256 | ADDCS R12,R12,#256 | ||
| Line 25: | Line 25: | ||
BNE LOOP | BNE LOOP | ||
| + | [[File:Sierpinskicodercolour.png]] | ||
| − | [Category:Computing] | + | [[Category:Computing]] |
Latest revision as of 11:00, 7 August 2014
Draws the sierpinski triangle on a 320x256 screen with 8 bits per pixel using the chaos game method. A vertex of a triangle is selected at random and averaged with the current position to find the new position to plot a pixel.
MOV R9,#320 ; Screen width
MOV R2,#5 ; Random number generator seed
MOV R4,#160 ; X position of top vertex
MOV R8,#1048576 ; Loop counter
MOV R11,#160 ; Set start position to middle of the screen
MOV R12,#128
.LOOP RSB R2,R2,R2,ROR #21 ; Generate pseudo random number in the range 0 to 2
MOVS R3,R2,LSR #31 ; LSB in carry, MSB in R3
BHI LOOP ; Repeat if 3
ADDCC R11,R11,R4,LSL R3 ; Calculate new position halfway
ADDCC R12,R12,R3,LSL #8 ; between the old and the new vertex
ADDCS R12,R12,#256
MOV R11,R11,LSR #1
MOV R12,R12,LSR #1
MLA R7,R12,R9,R11 ; R7 = (R12 * 320) + R11
STRB R12,[R0,R7]
SUBS R8,R8,#1
BNE LOOP
