r3wp [groups: 83 posts: 189283]

# World: r3wp

## [gfx math] Graphics or geometry related math discussion

 newer last Maxim13-Feb-2007[1x3] ```LADISLAV POSTED THIS in rebgui group: this DISTANCE? version looks twice as fast as the one currently distributed: distance?: make function! [ "Returns the distance between two points." p1 [pair!] "First point" p2 [pair!] "Second point" ][ p1: p1 - p2 p1: p1 * p1 square-root p1/x + p1/y ] ``` ```does anyone have a fast function which will give me (any) point along the line which goes from one coord to another? X---------(o)---X the func spec would be: between [start [pair] end [pair] at [decimal!] ] where 'at is a decimal ranging from 0 to 1 ``` ```actually the AT argument could be negative or larger than 1 (which indicates points beyond coords) and should also support an integer! , which would change the measure of 'AT to be pixels, instead of a scaling. ``` Ladislav13-Feb-2007[4] ```how about this? between: func [ {compute the specified point on the line} start [pair!] end [pair!] at [decimal! integer!] /local vector points ] [ ; solve "degenerate case" first if equal? start end [return start] vector: end - start if integer? at [ ; convert AT to decimal points: max abs vector/x abs vector/y at: at / points ] start + to pair! reduce [round vector/x * at round vector/y * at] ] ``` Maxim13-Feb-2007[5] ```thanks I'll test it out shortly ! :-D ``` Maxim14-Feb-2007[6x3] ```this is my final function, I removed the rounding as it created a lot of noise in position, (not the fault of the round function but the act or rounding itself, would snap the position back and forth while dragging) I also use the vector's length using an hypothenuse formula (similar to distance), cause your previous example did not properly scale to the vector's maximum size. I also added support for supplying a negative value for 'AT argument so that it actually offsets from the end, which is very usefull. vlength: func [v] [v: v * v square-root v/x + v/y] between: func [ {compute the specified point on the line} start [pair!] end [pair!] at [decimal! integer!] /local vector points ] [ ; solve "degenerate case" first if equal? start end [return start] vector: end - start if integer? at [ ; convert AT to decimal at: at / (to-integer vlength vector) ] if negative? at [ at: 1 + at ] start + to-pair reduce [to-integer vector/x * at to-integer vector/y * at] ] ``` ```here is segment... a cousin to between which returns two coordinates at one... usefull to draw segments of a bigger line in other colors (handles for example) ;-------------------- ;- segment() ;-------------------- segment: func [ {compute the specified segment from the line} start [pair!] end [pair!] from [decimal! integer! none!] to [decimal! integer! none!] /local vector points length ][ ; solve "degenerate case" first if equal? start end [return reduce [start start]] vector: end - start length: vlength vector ;---------- ; FROM if integer? from [ ; convert from to decimal from: from / length ] if none? from [ from: 0 ] if negative? from [ ; this case lets us define a segment using the end as the reference from: 1 + from ; from is negative, so this actually substracts from length ] ;---------- ; TO if integer? to [ ; convert to, to decimal to: to / length ] if none? to [ to: 1 ] if negative? to [ ; this case lets us define a segment using the end as the reference to: 1 + to ; to is negative, so this actually substracts from length ] reduce [start + to-pair reduce [to-integer vector/x * from to-integer vector/y * from] start + to-pair reduce [to-integer vector/x * to to-integer vector/y * to] ] ] ``` ```btw, 'SEGMENT also supports none! which effectively returns that argument's postion, usefull to make segments which reach one of both ends of a line. ``` Steeve16-Feb-2007[9] ```someone tried to adapt FFT on Rebol ? ``` Maxim16-Feb-2007[10] ```btw steeve tried your little demos... nice ``` Steeve16-Feb-2007[11] ```demo-ay ? ``` Maxim16-Feb-2007[12] ```both scripts on rebol.org ``` Steeve16-Feb-2007[13] ```ok ``` Maxim16-Feb-2007[14] ```did you try out regraph demo? ``` Steeve16-Feb-2007[15x3] ```i'm not sure ``` ```don't remember ``` ```on rebol.org ? ``` Maxim16-Feb-2007[18x2] ```it was just a graphic editing engine proof of concept for my dataflow engine... of which I am now building the v2 of the graphic engine, which allows your graphic elements to render into parrallel layers. ``` ```do read http://www.pointillistic.com/open-REBOL/moa/steel/retools/download/regraph.r ``` Steeve16-Feb-2007[20] ```i try ``` Maxim16-Feb-2007[21] ```the layers will allow us to optimise what gets refreshed and allow us to stack some properties of all graphic elements on the same layer, even if the graphic elements themselves are rendered as a list (of overlapping things) ``` Steeve16-Feb-2007[22x3] ```hum ok, it's more advanced than my try ``` ```different concept ``` ```btw, i have a question on liquid ``` Maxim16-Feb-2007[25] ```yes? ``` Steeve16-Feb-2007[26] ```it's your work isn't it ? ``` Maxim16-Feb-2007[27] ```moving to liquid group... ``` Steeve16-Feb-2007[28x2] ```(that's not my question) ``` ```well, can you synchronise lists or only single values ``` Maxim16-Feb-2007[30] ```(did you see the !Liquid group on the left? ``` Steeve16-Feb-2007[31x2] ```by lists, i mean, block of values ``` ```sorry ``` Robert19-Aug-2007[33] ```Hi, I have a question concerning color palette conversions. I have a color palette of greens that I would like to convert to blue using the same "look and style" as the green ones. Is this possible? ``` Chris19-Aug-2007[34] ```What does your colour palette look like? e.g. [0.0.100 5.8.189] ? ``` Rebolek19-Aug-2007[35] ```Robert, convert your colors to HSV and change Hue. ``` Chris19-Aug-2007[36x2] ```I wrote this before HSV functions were added to /View, but it still works: http://www.ross-gill.com/r/hsv-lab.r ``` ```But now there are native hsv functions... ``` Robert20-Aug-2007[38x2] ```This is my colour palette: ; 7 primary colors bn-green: 0.102.76 green-field: 51.133.110 reed-green: 102.163.146 patina-green: 153.194.183 glass-green: 204.224.219 light-green: 232.241.239 ash-gray: 209.209.209 ; 7 secondary colors midnight: 0.29.43 foggy-morning: 31.93.154 hazy-day: 102.154.204 light-mint: 154.204.205 terra-cotta: 205.153.103 desert-sand: 229.201.115 sunflower: 254.191.0 ``` ```It's stated that this palette is specialy designed to harmonize. And I want to get a palette being based on blue with the same properties. ``` Rebolek20-Aug-2007[40] ```REBOL [] colors: [ ; 7 primary colors bn-green 0.102.76 green-field 51.133.110 reed-green 102.163.146 patina-green 153.194.183 glass-green 204.224.219 light-green 232.241.239 ash-gray 209.209.209 ; 7 secondary colors midnight 0.29.43 foggy-morning 31.93.154 hazy-day 102.154.204 light-mint 154.204.205 terra-cotta 205.153.103 desert-sand 229.201.115 sunflower 254.191.0 ] change-colors: func [val /local h hsv][ forskip colors 2 [ hsv: rgb-to-hsv colors/2 h: hsv/1 + val // 255 hsv/1: h colors/2: hsv-to-rgb hsv ] ~b1/color: colors/bn-green ~b2/color: colors/green-field ~b3/color: colors/reed-green ~b4/color: colors/patina-green ~b5/color: colors/glass-green ~b6/color: colors/light-green ~b7/color: colors/ash-gray ~b11/color: colors/midnight ~b12/color: colors/foggy-morning ~b13/color: colors/hazy-day ~b14/color: colors/light-mint ~b15/color: colors/terra-cotta ~b16/color: colors/desert-sand ~b17/color: colors/sunflower ] lay: layout [ across ~b1: box colors/bn-green ~b2: box colors/green-field ~b3: box colors/reed-green ~b4: box colors/patina-green ~b5: box colors/glass-green ~b6: box colors/light-green ~b7: box colors/ash-gray return ~b11: box colors/midnight ~b12: box colors/foggy-morning ~b13: box colors/hazy-day ~b14: box colors/light-mint ~b15: box colors/terra-cotta ~b16: box colors/desert-sand ~b17: box colors/sunflower return button "change color" [change-colors 64 show lay] ] view lay ``` Robert20-Aug-2007[41x2] ```Thx a lot!! :-) ``` ```I will play around with this. ``` Rebolek20-Aug-2007[43] ```you're welcome :) ``` Geomol9-May-2008[44x2] ```Has anyone got experience with this Texturing Tool? http://www.mapzoneeditor.com/index.php ``` ```Or know of a good place to look for texture producing algorithms? ``` Reichart11-Jul-2008[46] ```Look towards people in the video game business....they did lots of this in the 80-90s ``` Rebolek11-Jul-2008[47x3] ```http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=texture-lab.r ``` ```It's nothing special, but it works :) ``` ```press "Open" to see some presets ``` Anton7-Jan-2009[50] ```Hi, I'm looking for a range of colours from "hot white" to "cool blue" to represent molten metal cooling down. Currently I have this range of 6 colours: colors: [white yellow orange red purple navy] (I interpolate between the colours for more resolution.) Does anybody know how I can improve these colours ? Any websites that are good for this? ``` newer last